Skip to content

[libc] implement ioctl #85275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nickdesaulniers opened this issue Mar 14, 2024 · 7 comments · May be fixed by #90317 or #141393
Open

[libc] implement ioctl #85275

nickdesaulniers opened this issue Mar 14, 2024 · 7 comments · May be fixed by #90317 or #141393
Assignees
Labels
good first issue https://github.com/llvm/llvm-project/contribute libc

Comments

@nickdesaulniers
Copy link
Member

nickdesaulniers commented Mar 14, 2024

the ioctl syscall is pretty important, and is used by libc++ for LIBCXX_ENABLE_RANDOM_DEVICE support.

We currently define a few macros for ioctl in include/llvm-libc-macros/sys-ioctl-macros.h and generate ioctl.h via include/sys/ioctl.h.def.

I also see open coded calls to ioctl in:

  • src/unistd/linux/isatty.cpp
  • src/termios/linux/tcgetattr.cpp
  • src/termios/linux/tcsendbreak.cpp
  • src/termios/linux/tcgetsid.cpp
  • src/termios/linux/tcdrain.cpp
  • src/termios/linux/tcsetattr.cpp
  • src/termios/linux/tcflush.cpp
  • src/termios/linux/tcflow.cpp

I assume once ioctl is implemented, all of the above open coded calls should be replaced with the call to our internal wrapper.

@nickdesaulniers nickdesaulniers added good first issue https://github.com/llvm/llvm-project/contribute libc labels Mar 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. In the comments of the issue, request for it to be assigned to you.
  2. Fix the issue locally.
  3. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  4. Create a Git commit.
  5. Run git clang-format HEAD~1 to format your changes.
  6. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

@llvm/issue-subscribers-good-first-issue

Author: Nick Desaulniers (nickdesaulniers)

the ioctl syscall is pretty important, and is used by libc++ for LIBCXX_ENABLE_RANDOM_DEVICE support.

We currently define a few macros for ioctl in include/llvm-libc-macros/sys-ioctl-macros.h and generate ioctl.h via include/sys/ioctl.h.def.

I also see open coded calls to ioctl in:

  • src/unistd/linux/isatty.cpp
  • src/termios/linux/tcgetattr.cpp
  • src/termios/linux/tcsendbreak.cpp
  • src/termios/linux/tcgetsid.cpp
  • src/termios/linux/tcdrain.cpp
  • src/termios/linux/tcsetattr.cpp
  • src/termios/linux/tcflush.cpp
  • src/termios/linux/tcflow.cpp

I assume once ioctl is implemented, all of the above open coded calls should be replaced with the call to our internal wrapper.

@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

@llvm/issue-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

the ioctl syscall is pretty important, and is used by libc++ for LIBCXX_ENABLE_RANDOM_DEVICE support.

We currently define a few macros for ioctl in include/llvm-libc-macros/sys-ioctl-macros.h and generate ioctl.h via include/sys/ioctl.h.def.

I also see open coded calls to ioctl in:

  • src/unistd/linux/isatty.cpp
  • src/termios/linux/tcgetattr.cpp
  • src/termios/linux/tcsendbreak.cpp
  • src/termios/linux/tcgetsid.cpp
  • src/termios/linux/tcdrain.cpp
  • src/termios/linux/tcsetattr.cpp
  • src/termios/linux/tcflush.cpp
  • src/termios/linux/tcflow.cpp

I assume once ioctl is implemented, all of the above open coded calls should be replaced with the call to our internal wrapper.

@changkhothuychung
Copy link
Contributor

Hi I am interested in this issue, can this be assigned to me? Thanks.

@nickdesaulniers
Copy link
Member Author

Hi @changkhothuychung , thanks for your interest!

This one will be interesting, since the ioctl interface is variadic, but syscalls have an upper limit on how many args can be passed in registers. FWICT, it seems like va_start, va_arg, and va_end can be used to unpack a void* which is then passed as the third parameter for the syscall.

048041f is probably a good example of adding a new entry that's specific to linux. I'd use that as a reference for the boilerplate that needs to be added.

Terrifyingly, POSIX seems to have standardized this interface, under a different header and with a different signature than what is used in linux.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html

I'll probably have to do some more digging into the history there, but for now, please provide an implementation based on the signature and header as specified by man 3 ioctl.

@changkhothuychung
Copy link
Contributor

@nickdesaulniers Thank you very much for the instructions! I will start working on it and will make a PR as soon as I have some progress.

@changkhothuychung
Copy link
Contributor

@nickdesaulniers do you have any documentations about building and testing libc? Thanks.

lntue pushed a commit that referenced this issue Apr 10, 2024
This PR is to work on the issue #85275
@changkhothuychung changkhothuychung linked a pull request Jul 29, 2024 that will close this issue
@cowtoolz cowtoolz linked a pull request May 25, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue https://github.com/llvm/llvm-project/contribute libc
Projects
None yet
3 participants