Skip to content

Commit 7ef6504

Browse files
cowtoolzjhuber6michaelrj-google
authored andcommitted
[libc] add ioctl (llvm#141393)
Closes llvm#85275 Closes llvm#90317 Updates llvm#97191 --------- Co-authored-by: Joseph Huber <[email protected]> Co-authored-by: Michael Jones <[email protected]>
1 parent 373be92 commit 7ef6504

File tree

16 files changed

+219
-0
lines changed

16 files changed

+219
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ set(TARGET_LIBC_ENTRYPOINTS
245245
# https://github.com/llvm/llvm-project/issues/80060
246246
# libc.src.sys.epoll.epoll_pwait2
247247

248+
# sys/ioctl.h entrypoints
249+
libc.src.sys.ioctl.ioctl
250+
248251
# sys/mman.h entrypoints
249252
libc.src.sys.mman.madvise
250253
libc.src.sys.mman.mincore

libc/config/linux/arm/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ set(TARGET_LIBC_ENTRYPOINTS
172172
libc.src.stdlib.free
173173
libc.src.stdlib.malloc
174174

175+
# sys/ioctl.h entrypoints
176+
libc.src.sys.ioctl.ioctl
177+
175178
# sys/mman.h entrypoints
176179
libc.src.sys.mman.mmap
177180
libc.src.sys.mman.munmap

libc/config/linux/riscv/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ set(TARGET_LIBC_ENTRYPOINTS
246246
# https://github.com/llvm/llvm-project/issues/80060
247247
# libc.src.sys.epoll.epoll_pwait2
248248

249+
# sys/ioctl.h entrypoints
250+
libc.src.sys.ioctl.ioctl
251+
249252
# sys/mman.h entrypoints
250253
libc.src.sys.mman.madvise
251254
libc.src.sys.mman.mincore

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ set(TARGET_LIBC_ENTRYPOINTS
246246
# https://github.com/llvm/llvm-project/issues/80060
247247
# libc.src.sys.epoll.epoll_pwait2
248248

249+
# sys/ioctl.h entrypoints
250+
libc.src.sys.ioctl.ioctl
251+
249252
# sys/mman.h entrypoints
250253
libc.src.sys.mman.madvise
251254
libc.src.sys.mman.mincore

libc/hdr/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ add_proxy_header_library(
126126
libc.include.llvm-libc-macros.sys_epoll_macros
127127
)
128128

129+
add_proxy_header_library(
130+
sys_ioctl_macros
131+
HDRS
132+
sys_ioctl_macros.h
133+
FULL_BUILD_DEPENDS
134+
libc.include.sys_ioctl
135+
libc.include.llvm-libc-macros.sys_ioctl_macros
136+
)
137+
129138
add_proxy_header_library(
130139
sys_stat_macros
131140
HDRS

libc/hdr/sys_ioctl_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from sys/ioctl.h -----------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_HDR_SYS_IOCTL_MACROS_H
10+
#define LLVM_LIBC_HDR_SYS_IOCTL_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/sys-ioctl-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <sys/ioctl.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_SYS_IOCTL_MACROS_H

libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
// around the definitions of macros like _IO, _IOR, _IOW, and _IOWR that I don't
1616
// think is worth digging into right now.
1717
#define TIOCGETD 0x5424
18+
#define FIONREAD 0x541B
1819

1920
#endif // LLVM_LIBC_MACROS_LINUX_SYS_IOCTL_MACROS_H

libc/src/sys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ add_subdirectory(utsname)
1313
add_subdirectory(wait)
1414
add_subdirectory(prctl)
1515
add_subdirectory(uio)
16+
add_subdirectory(ioctl)

libc/src/sys/ioctl/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
2+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
3+
endif()
4+
5+
add_entrypoint_object(
6+
ioctl
7+
ALIAS
8+
DEPENDS
9+
.${LIBC_TARGET_OS}.ioctl
10+
)

libc/src/sys/ioctl/ioctl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for ioctl ---------------------------*-C++-*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H
10+
#define LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int ioctl(int fd, unsigned long request, ...);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H

0 commit comments

Comments
 (0)