Skip to content

Commit 2e1e27c

Browse files
[libc] adjust linux's mman.h definitions (#79652)
Use definitions from `<linux/mman.h>` to dispatch arch-specific flag values. For example, `MCL_CURRENT/MCL_FUTURE/MCL_ONFAULT` are different on different architectures.
1 parent d9a9872 commit 2e1e27c

File tree

3 files changed

+34
-96
lines changed

3 files changed

+34
-96
lines changed

libc/include/llvm-libc-macros/linux/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ add_header(
1616
sys-ioctl-macros.h
1717
)
1818

19-
add_header(
20-
sys_mman_macros
21-
HDR
22-
sys-mman-macros.h
23-
)
24-
2519
add_header(
2620
sys_random_macros
2721
HDR

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

Lines changed: 0 additions & 88 deletions
This file was deleted.

libc/include/llvm-libc-macros/sys-mman-macros.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,40 @@
99
#ifndef __LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H
1010
#define __LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H
1111

12-
#ifdef __linux__
13-
#include "linux/sys-mman-macros.h"
12+
// Use definitions from <linux/mman.h> to dispatch arch-specific flag values.
13+
// For example, MCL_CURRENT/MCL_FUTURE/MCL_ONFAULT are different on different
14+
// architectures.
15+
#if __has_include(<linux/mman.h>)
16+
#include <linux/mman.h>
17+
#else
18+
#error "cannot use <sys/mman.h> without proper system headers."
19+
#endif
20+
21+
// Some posix standard flags may not be defined in system headers.
22+
// Posix mmap flags.
23+
#ifndef MAP_FAILED
24+
#define MAP_FAILED ((void *)-1)
25+
#endif
26+
27+
// Posix memory advise flags. (posix_madvise)
28+
#ifndef POSIX_MADV_NORMAL
29+
#define POSIX_MADV_NORMAL MADV_NORMAL
30+
#endif
31+
32+
#ifndef POSIX_MADV_SEQUENTIAL
33+
#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
34+
#endif
35+
36+
#ifndef POSIX_MADV_RANDOM
37+
#define POSIX_MADV_RANDOM MADV_RANDOM
38+
#endif
39+
40+
#ifndef POSIX_MADV_WILLNEED
41+
#define POSIX_MADV_WILLNEED MADV_WILLNEED
42+
#endif
43+
44+
#ifndef POSIX_MADV_DONTNEED
45+
#define POSIX_MADV_DONTNEED MADV_DONTNEED
1446
#endif
1547

1648
#endif // __LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H

0 commit comments

Comments
 (0)