forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR is to work on the issue llvm#85275
- Loading branch information
1 parent
8dc006e
commit 289a2c3
Showing
12 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 | ||
) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//===-- Implementation header for mmap function -----------------*- 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, unsigned long request, ...); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_SYS_IOCTL_IOCTL_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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 | ||
) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===---------- Linux implementation of the POSIX ioctl function --------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/sys/ioctl/ioctl.h" | ||
|
||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
#include "src/__support/common.h" | ||
#include "src/errno/libc_errno.h" | ||
#include <stdarg.h> | ||
#include <sys/syscall.h> // For syscall numbers. | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
// This function is currently linux only. It has to be refactored suitably if | ||
// madvise is to be supported on non-linux operating systems also. | ||
LLVM_LIBC_FUNCTION(int, ioctl, (int fd, unsigned long request, ...)) { | ||
va_list ptr_to_memory; | ||
va_start(ptr_to_memory, 1); | ||
va_arg(ptr_to_memory, void *) int ret = | ||
LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, request, ptr_to_memory); | ||
va_end(ptr_to_memory); | ||
|
||
// A negative return value indicates an error with the magnitude of the | ||
// value being the error code. | ||
if (ret < 0) { | ||
libc_errno = -ret; | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
add_subdirectory(${LIBC_TARGET_OS}) | ||
endif() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_custom_target(libc_sys_ioctl_unittests) | ||
|
||
add_libc_unittest( | ||
ioctl_test | ||
SUITE | ||
libc_sys_ioctl_unittests | ||
SRCS | ||
ioctl_test.cpp | ||
DEPENDS | ||
libc.include.sys_ioctl | ||
libc.src.errno.errno | ||
libc.test.errno_setter_matcher | ||
) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===-- Unittests for ioctl -----------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
#include "src/errno/libc_errno.h" | ||
#include "src/sys/ioctl/ioctl.h" | ||
#include "test/UnitTest/ErrnoSetterMatcher.h" | ||
#include "test/UnitTest/LibcTest.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
|
||
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; | ||
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; | ||
|
||
TEST(LlvmLibcIoctlTest, InvalidFileDescriptor) { | ||
int fd = 10; | ||
unsigned long request = 10; | ||
int res = LIBC_NAMESPACE::ioctl(fd, 10, NULL); | ||
EXPECT_THAT(res, Fails(EBADF, -1)); | ||
} |