mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 02:38:07 +08:00
committed by
GitHub
parent
65deac0872
commit
a50a7ea2e2
@@ -335,6 +335,7 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.unistd.getentropy
|
||||
libc.src.unistd.geteuid
|
||||
libc.src.unistd.gethostname
|
||||
libc.src.unistd.getpagesize
|
||||
libc.src.unistd.getpid
|
||||
libc.src.unistd.getppid
|
||||
libc.src.unistd.getsid
|
||||
|
||||
@@ -338,6 +338,7 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.unistd.getentropy
|
||||
libc.src.unistd.geteuid
|
||||
libc.src.unistd.gethostname
|
||||
libc.src.unistd.getpagesize
|
||||
libc.src.unistd.getpid
|
||||
libc.src.unistd.getppid
|
||||
libc.src.unistd.getsid
|
||||
|
||||
@@ -347,6 +347,7 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
libc.src.unistd.getentropy
|
||||
libc.src.unistd.geteuid
|
||||
libc.src.unistd.gethostname
|
||||
libc.src.unistd.getpagesize
|
||||
libc.src.unistd.getpid
|
||||
libc.src.unistd.getppid
|
||||
libc.src.unistd.getsid
|
||||
|
||||
@@ -174,6 +174,12 @@ functions:
|
||||
arguments:
|
||||
- type: char *
|
||||
- type: size_t
|
||||
- name: getpagesize
|
||||
standards:
|
||||
- BSDExtensions
|
||||
return_type: int
|
||||
arguments:
|
||||
- type: void
|
||||
- name: getopt
|
||||
standards:
|
||||
- POSIX
|
||||
|
||||
@@ -139,6 +139,13 @@ add_entrypoint_object(
|
||||
.${LIBC_TARGET_OS}.gethostname
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
getpagesize
|
||||
ALIAS
|
||||
DEPENDS
|
||||
.${LIBC_TARGET_OS}.getpagesize
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
getpid
|
||||
ALIAS
|
||||
|
||||
20
libc/src/unistd/getpagesize.h
Normal file
20
libc/src/unistd/getpagesize.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//===-- Implementation header for getpagesize -------------------*- 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_UNISTD_GETPAGESIZE_H
|
||||
#define LLVM_LIBC_SRC_UNISTD_GETPAGESIZE_H
|
||||
|
||||
#include "src/__support/common.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
int getpagesize();
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC_UNISTD_GETPAGESIZE_H
|
||||
@@ -249,6 +249,16 @@ add_entrypoint_object(
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
getpagesize
|
||||
SRCS
|
||||
getpagesize.cpp
|
||||
HDRS
|
||||
../getpagesize.h
|
||||
DEPENDS
|
||||
libc.src.__support.OSUtil.linux.auxv
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
geteuid
|
||||
SRCS
|
||||
|
||||
25
libc/src/unistd/linux/getpagesize.cpp
Normal file
25
libc/src/unistd/linux/getpagesize.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
//===-- Linux implementation of getpagesize -------------------------------===//
|
||||
//
|
||||
// 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/unistd/getpagesize.h"
|
||||
|
||||
#include "src/__support/OSUtil/linux/auxv.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, getpagesize, ()) {
|
||||
cpp::optional<unsigned long> page_size =
|
||||
(LIBC_NAMESPACE::auxv::get(AT_PAGESZ));
|
||||
if (page_size)
|
||||
return static_cast<int>(*page_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
@@ -477,6 +477,17 @@ add_libc_unittest(
|
||||
libc.test.UnitTest.ErrnoCheckingTest
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
getpagesize_test
|
||||
SUITE
|
||||
libc_unistd_unittests
|
||||
SRCS
|
||||
getpagesize_test.cpp
|
||||
DEPENDS
|
||||
libc.src.unistd.getpagesize
|
||||
libc.test.UnitTest.ErrnoCheckingTest
|
||||
)
|
||||
|
||||
add_libc_unittest(
|
||||
getgid_test
|
||||
SUITE
|
||||
|
||||
24
libc/test/src/unistd/getpagesize_test.cpp
Normal file
24
libc/test/src/unistd/getpagesize_test.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//===-- Unittests for getpagesize -----------------------------------------===//
|
||||
//
|
||||
// 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/unistd/getpagesize.h"
|
||||
|
||||
#include "test/UnitTest/ErrnoCheckingTest.h"
|
||||
#include "test/UnitTest/Test.h"
|
||||
|
||||
using LlvmLibcGetPageSizeTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
|
||||
|
||||
TEST(LlvmLibcGetPageSizeTest, GetPageSize) {
|
||||
// getpagesize doesn't modify errno
|
||||
int ret = LIBC_NAMESPACE::getpagesize();
|
||||
ASSERT_NE(ret, -1);
|
||||
ASSERT_NE(ret, 0);
|
||||
// Correct page size depends on the hardware mode, but will be a modulus of
|
||||
// 4096
|
||||
ASSERT_EQ(ret % 4096, 0);
|
||||
}
|
||||
@@ -577,6 +577,8 @@ functions:
|
||||
in-latest-posix: ""
|
||||
gethostname:
|
||||
in-latest-posix: ""
|
||||
getpagesize:
|
||||
in-latest-posix: ""
|
||||
getlogin:
|
||||
in-latest-posix: ""
|
||||
getlogin_r:
|
||||
|
||||
@@ -6092,6 +6092,15 @@ libc_function(
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "getpagesize",
|
||||
srcs = ["src/unistd/linux/getpagesize.cpp"],
|
||||
hdrs = ["src/unistd/getpagesize.h"],
|
||||
deps = [
|
||||
":__support_osutil_linux_auxv",
|
||||
],
|
||||
)
|
||||
|
||||
libc_function(
|
||||
name = "getppid",
|
||||
srcs = ["src/unistd/linux/getppid.cpp"],
|
||||
|
||||
@@ -74,6 +74,14 @@ libc_test(
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "getpagesize_test",
|
||||
srcs = ["getpagesize_test.cpp"],
|
||||
deps = [
|
||||
"//libc:getpagesize",
|
||||
],
|
||||
)
|
||||
|
||||
libc_test(
|
||||
name = "pread_pwrite_test",
|
||||
srcs = ["pread_pwrite_test.cpp"],
|
||||
|
||||
Reference in New Issue
Block a user