-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[libc] Add basic ioctl
function
#97509
Closed
Closed
+78
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There's probably a lot more to do here.
39 tasks
@llvm/pr-subscribers-libc Author: Izaak Schroeder (izaakschroeder) ChangesThere's probably a lot more to do here but it's a start. Full diff: https://github.com/llvm/llvm-project/pull/97509.diff 8 Files Affected:
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 940df63e3912b..1f068ff3505af 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -206,6 +206,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.vsnprintf
libc.src.stdio.vsprintf
+ # sys/ioctl.h entrypoints
+ libc.src.sys.ioctl.ioctl
+
# sys/mman.h entrypoints
libc.src.sys.mman.madvise
libc.src.sys.mman.mincore
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 09f04fb31dfd8..291f89b09029a 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -226,6 +226,9 @@ set(TARGET_LIBC_ENTRYPOINTS
# https://github.com/llvm/llvm-project/issues/80060
# libc.src.sys.epoll.epoll_pwait2
+ # sys/ioctl.h entrypoints
+ libc.src.sys.ioctl.ioctl
+
# sys/mman.h entrypoints
libc.src.sys.mman.madvise
libc.src.sys.mman.mincore
diff --git a/libc/spec/posix.td b/libc/spec/posix.td
index d14047548e104..bf1bab57952af 100644
--- a/libc/spec/posix.td
+++ b/libc/spec/posix.td
@@ -1442,7 +1442,13 @@ def POSIX : StandardSpec<"POSIX"> {
], // Macros
[], // Types
[], // Enumerations
- [] // Functions
+ [
+ FunctionSpec<
+ "ioctl",
+ RetValSpec<IntType>,
+ [ArgSpec<IntType>, ArgSpec<IntType>, ArgSpec<VarArgType>]
+ >
+ ] // Functions
>;
HeaderSpec Spawn = HeaderSpec<
diff --git a/libc/src/sys/CMakeLists.txt b/libc/src/sys/CMakeLists.txt
index adc666b94202f..ac54df35284a7 100644
--- a/libc/src/sys/CMakeLists.txt
+++ b/libc/src/sys/CMakeLists.txt
@@ -1,5 +1,6 @@
add_subdirectory(auxv)
add_subdirectory(epoll)
+add_subdirectory(ioctl)
add_subdirectory(mman)
add_subdirectory(random)
add_subdirectory(resource)
diff --git a/libc/src/sys/ioctl/CMakeLists.txt b/libc/src/sys/ioctl/CMakeLists.txt
new file mode 100644
index 0000000000000..099a1b96389fc
--- /dev/null
+++ b/libc/src/sys/ioctl/CMakeLists.txt
@@ -0,0 +1,10 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
+
+add_entrypoint_object(
+ ioctl
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.ioctl
+)
diff --git a/libc/src/sys/ioctl/ioctl.h b/libc/src/sys/ioctl/ioctl.h
new file mode 100644
index 0000000000000..012d7cd8ed78b
--- /dev/null
+++ b/libc/src/sys/ioctl/ioctl.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for ioctl -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H
+#define LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H
+
+namespace LIBC_NAMESPACE {
+
+int ioctl(int fd, int req, ...);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H
diff --git a/libc/src/sys/ioctl/linux/CMakeLists.txt b/libc/src/sys/ioctl/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..876f35aaee66c
--- /dev/null
+++ b/libc/src/sys/ioctl/linux/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_entrypoint_object(
+ ioctl
+ SRCS
+ ioctl.cpp
+ HDRS
+ ../ioctl.h
+ DEPENDS
+ libc.include.sys_ioctl
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
diff --git a/libc/src/sys/ioctl/linux/ioctl.cpp b/libc/src/sys/ioctl/linux/ioctl.cpp
new file mode 100644
index 0000000000000..9b455f62d47a1
--- /dev/null
+++ b/libc/src/sys/ioctl/linux/ioctl.cpp
@@ -0,0 +1,24 @@
+#include <stdarg.h>
+#include <sys/syscall.h> // For syscall numbers.
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+#include "src/sys/ioctl/ioctl.h"
+
+#include "src/errno/libc_errno.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, ioctl, (int fd, int req, ...)) {
+ void *arg;
+ va_list ap;
+ va_start(ap, req);
+ arg = va_arg(ap, void *);
+ va_end(ap);
+ int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, req, arg);
+ // FIXME(@izaakschroeder): There is probably more to do here.
+ // See: https://github.com/kraj/musl/blob/kraj/master/src/misc/ioctl.c
+ return ret;
+}
+
+} // namespace LIBC_NAMESPACE
|
There is another ioctl PR: #90317 |
@lntue sorry I will close mine 😅 thanks for pointing it out! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's probably a lot more to do here but it's a start. This is enough for
libcxx
to compile withLIBCXX_ENABLE_RANDOM_DEVICE=ON
as part of #97191See: