llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

[libc] implement ioctl #85275

Open nickdesaulniers opened 6 months ago

nickdesaulniers commented 6 months ago

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:

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

llvmbot commented 6 months ago

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 commented 6 months ago

@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 commented 6 months ago

@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 commented 6 months ago

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

nickdesaulniers commented 6 months ago

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.

048041f197197 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 commented 5 months ago

@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 commented 5 months ago

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