Skip to content

Commit 5a8891a

Browse files
committed
fixup! - Create remap_file_pages wrapper for the linux sys call. - Add UnitTest for remap_file_pages - Add function to libc/spec/linux.td - Add Function spec to mman.yaml
1 parent 50bf5e9 commit 5a8891a

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

libc/newhdrgen/yaml/sys/mman.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ functions:
100100
- type: int
101101
- name: remap_file_pages
102102
standards:
103-
- LINUX
103+
- Linux
104104
return_type: int
105105
arguments:
106106
- type: void *
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
1-
//===----- Linux implementation of the POSIX remap_file_pages function ----===//
1+
//===------- Linux implementation of the remap_file_pages function --------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <src/sys/mman/remap_file_pages.h>
9+
#include "src/sys/mman/remap_file_pages.h"
1010

1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
15-
#include <sys/syscall.h> // For syscall numbers.
15+
#include <sys/syscall.h> // For syscall numbers.
1616

1717
namespace LIBC_NAMESPACE_DECL {
1818

19-
// This function is currently linux only. It has to be refactored suitably if
20-
// remap_file_pages is to be supported on non-linux operating systems also.
2119
LLVM_LIBC_FUNCTION(int, remap_file_pages,
22-
(void *addr, size_t size, int prot, size_t pgoff, int flags))
23-
{
20+
(void *addr, size_t size, int prot, size_t pgoff,
21+
int flags)) {
2422
#ifdef SYS_remap_file_pages
25-
long syscall_number = SYS_remap_file_pages;
23+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_remap_file_pages,
24+
reinterpret_cast<long>(addr),
25+
size, prot, pgoff, flags);
2626
#else
2727
#error "remap_file_pages syscall is not available."
2828
#endif
2929

30-
31-
int ret = LIBC_NAMESPACE::syscall_impl<int>(
32-
syscall_number, reinterpret_cast<long>(addr), size, prot, pgoff, flags);
33-
3430
// A negative return value indicates an error with the magnitude of the
3531
// value being the error code.
3632
if (ret < 0) {
@@ -41,4 +37,4 @@ LLVM_LIBC_FUNCTION(int, remap_file_pages,
4137
return 0;
4238
}
4339

44-
} // namespace LIBC_NAMESPACE_DECL
40+
} // namespace LIBC_NAMESPACE_DECL

libc/src/sys/mman/remap_file_pages.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#define LLVM_LIBC_SRC_SYS_MMAN_REMAP_FILE_PAGES_H
1111

1212
#include "src/__support/macros/config.h"
13-
#include <sys/mman.h>
13+
#include <stddef.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

17-
int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff, int flags);
17+
int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff,
18+
int flags);
1819

1920
} // namespace LIBC_NAMESPACE_DECL
2021

21-
#endif //LLVM_LIBC_SRC_SYS_MMAN_REMAP_FILE_PAGES_H
22+
#endif // LLVM_LIBC_SRC_SYS_MMAN_REMAP_FILE_PAGES_H

libc/test/src/sys/mman/linux/remap_file_pages_test.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
#include "src/sys/mman/mmap.h"
1111
#include "src/sys/mman/munmap.h"
1212
#include "src/sys/mman/remap_file_pages.h"
13+
#include "src/unistd/sysconf.h"
1314
#include "test/UnitTest/ErrnoSetterMatcher.h"
1415
#include "test/UnitTest/Test.h"
15-
#include "src/unistd/sysconf.h"
1616

1717
#include <sys/mman.h>
1818

19-
2019
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
2120
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
2221

@@ -36,7 +35,8 @@ TEST(LlvmLibcRemapFilePagesTest, NoError) {
3635
LIBC_NAMESPACE::libc_errno = 0;
3736

3837
// Now try to remap the pages
39-
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(addr, page_size, PROT_READ, page_size, 0),
38+
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(addr, page_size, PROT_READ,
39+
page_size, 0),
4040
Succeeds());
4141

4242
// Reset error number for the new function
@@ -55,7 +55,8 @@ TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) {
5555
ASSERT_NE(addr, MAP_FAILED);
5656

5757
// Try to remap pages with an invalid flag MAP_PRIVATE
58-
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(addr, page_size, PROT_READ, 0, MAP_PRIVATE),
58+
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(addr, page_size, PROT_READ, 0,
59+
MAP_PRIVATE),
5960
Fails(EINVAL));
6061

6162
// Clean up
@@ -67,8 +68,9 @@ TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidAddress) {
6768
ASSERT_GT(page_size, size_t(0));
6869

6970
// Use an address that we haven't mapped
70-
void *invalid_addr = reinterpret_cast<void*>(0x12345000);
71+
void *invalid_addr = reinterpret_cast<void *>(0x12345000);
7172

72-
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(invalid_addr, page_size, PROT_READ, 0, 0),
73+
EXPECT_THAT(LIBC_NAMESPACE::remap_file_pages(invalid_addr, page_size,
74+
PROT_READ, 0, 0),
7375
Fails(EINVAL));
74-
}
76+
}

0 commit comments

Comments
 (0)