[libc-commits] [libc] 8d615a5 - [libc] move sys/mman macros to /include

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Sep 23 09:36:48 PDT 2022


Author: Michael Jones
Date: 2022-09-23T09:36:34-07:00
New Revision: 8d615a5e8af238ad4c010820634130c531205df4

URL: https://github.com/llvm/llvm-project/commit/8d615a5e8af238ad4c010820634130c531205df4
DIFF: https://github.com/llvm/llvm-project/commit/8d615a5e8af238ad4c010820634130c531205df4.diff

LOG: [libc] move sys/mman macros to /include

Previously the mman macros were in api.td, but platform differences are
easier to handle with preprocessor macros so they have been moved to
include. Also I completed the list of macros (at least for what I need
soon) and fixed some previously incorrect values.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D134491

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

Modified: 
    libc/config/linux/api.td
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-macros/CMakeLists.txt
    libc/include/llvm-libc-macros/linux/CMakeLists.txt
    libc/include/sys/mman.h.def

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 8dbe3aa3b3e85..508ef3721a64e 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -196,22 +196,6 @@ def ErrnoAPI : PublicAPI<"errno.h"> {
 def SysMManAPI : PublicAPI<"sys/mman.h"> {
   let Types = ["off_t", "size_t"];
   let Macros = [
-    SimpleMacroDef<"PROT_NONE", "0">,
-    SimpleMacroDef<"PROT_READ", "1">,
-    SimpleMacroDef<"PROT_WRITE", "2">,
-    SimpleMacroDef<"PROT_EXEC", "4">,
-
-    SimpleMacroDef<"MAP_FIXED", "1">,
-    SimpleMacroDef<"MAP_PRIVATE", "2">,
-    SimpleMacroDef<"MAP_SHARED", "4">,
-
-    SimpleMacroDef<"MAP_FAILED", "((void*)-1)">,
-
-    // TODO: The value of 0x20 is good for x86_64, but has to be extended
-    // in some manner to accommodate other machine architectures.
-    SimpleMacroDef<"MAP_ANONYMOUS", "0x20">
-
-    // TODO: Add other MAP_* macros used by Linux.
   ];
 
 }

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index cc7ec17b9afb8..63eb88247de04 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -203,6 +203,7 @@ add_gen_header(
     .llvm_libc_common_h
     .llvm-libc-types.off_t
     .llvm-libc-types.ssize_t
+    .llvm-libc-macros.sys_mman_macros
 )
 
 add_gen_header(

diff  --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 1a53b535dadba..380cb288ed971 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -22,6 +22,14 @@ add_header(
     .linux.sys_stat_macros
 )
 
+add_header(
+  sys_mman_macros
+  HDR
+    sys-mman-macros.h
+  DEPENDS
+    .linux.sys_mman_macros
+)
+
 add_header(
   sys_resource_macros
   HDR

diff  --git a/libc/include/llvm-libc-macros/linux/CMakeLists.txt b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
index 3fb9efcbfdf71..aac9e9768d924 100644
--- a/libc/include/llvm-libc-macros/linux/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
@@ -4,6 +4,12 @@ add_header(
     fcntl-macros.h
 )
 
+add_header(
+  sys_mman_macros
+  HDR
+    sys-mman-macros.h
+)
+
 add_header(
   sys_stat_macros
   HDR

diff  --git a/libc/include/llvm-libc-macros/linux/sys-mman-macros.h b/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
new file mode 100644
index 0000000000000..1925c3c7cd3da
--- /dev/null
+++ b/libc/include/llvm-libc-macros/linux/sys-mman-macros.h
@@ -0,0 +1,88 @@
+//===-- Definition of macros from sys/mman.h ------------------------------===//
+//
+// 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_MACROS_LINUX_SYS_MMAN_MACROS_H
+#define __LLVM_LIBC_MACROS_LINUX_SYS_MMAN_MACROS_H
+
+// Memory protection flags. (mmap, munmap, mprotect)
+#define PROT_NONE 0x0
+#define PROT_READ 0x1
+#define PROT_WRITE 0x2
+#define PROT_EXEC 0x4
+// These protection flags are only valid for mprotect.
+#define PROT_GROWSUP 0x1000000
+#define PROT_GROWSDOWN 0x2000000
+
+// Memory mapping flags. (mmap, munmap)
+#define MAP_FAILED ((void *)-1)
+// These are the sharing types, and exactly one of these must be set.
+#define MAP_FILE 0x0 // Compatibility flag. Ignored.
+#define MAP_SHARED 0x1
+#define MAP_PRIVATE 0x2
+#define MAP_SHARED_VALIDATE 0x3
+// 0x4-0xf are unused.
+// These are the other flags, and zero or more of these can be set.
+#define MAP_FIXED 0x10
+#define MAP_ANONYMOUS 0x20
+#define MAP_ANON MAP_ANONYMOUS
+#define MAP_32BIT 0x40
+// 0x80 is unused.
+#define MAP_GROWSDOWN 0x100
+#define MAP_DENYWRITE 0x800
+#define MAP_EXECUTABLE 0x1000 // Compatibility flag. Ignored.
+#define MAP_LOCKED 0x2000
+#define MAP_NORESERVE 0x4000
+#define MAP_POPULATE 0x8000
+#define MAP_NONBLOCK 0x10000
+#define MAP_STACK 0x20000
+#define MAP_HUGETLB 0x40000
+#define MAP_SYNC 0x80000
+#define MAP_FIXED_NOREPLACE 0x100000
+// HUGETLB support macros. If ma_HUGHTLB is set, the bits under MAP_HUGE_MASK
+// represent the base-2 logarithm of the desired page size, and MAP_HUGE_2MB/1GB
+// are common sizes.
+#define MAP_HUGE_SHIFT 26
+#define MAP_HUGE_MASK 0x3f
+#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT)
+#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
+
+// Memory sync flags. (msync)
+#define MS_ASYNC 1
+#define MS_INVALIDATE 2
+#define MS_SYNC 4
+
+// Memory advice flags. (madvise)
+#define MADV_NORMAL 0
+#define MADV_RANDOM 1
+#define MADV_SEQUENTIAL 2
+#define MADV_WILLNEED 3
+#define MADV_DONTNEED 4
+#define MADV_FREE 8
+#define MADV_REMOVE 9
+#define MADV_DONTFORK 10
+#define MADV_DOFORK 11
+#define MADV_MERGEABLE 12
+#define MADV_UNMERGEABLE 13
+#define MADV_HUGEPAGE 14
+#define MADV_NOHUGEPAGE 15
+#define MADV_DONTDUMP 16
+#define MADV_DODUMP 17
+#define MADV_WIPEONFORK 18
+#define MADV_KEEPONFORK 19
+#define MADV_COLD 20
+#define MADV_PAGEOUT 21
+#define MADV_HWPOISON 100
+
+// Posix memory advise flags. (posix_madvise)
+#define POSIX_MADV_NORMAL MADV_NORMAL
+#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
+#define POSIX_MADV_RANDOM MADV_RANDOM
+#define POSIX_MADV_WILLNEED MADV_WILLNEED
+#define POSIX_MADV_DONTNEED MADV_DONTNEED
+
+#endif // __LLVM_LIBC_MACROS_LINUX_SYS_MMAN_MACROS_H

diff  --git a/libc/include/llvm-libc-macros/sys-mman-macros.h b/libc/include/llvm-libc-macros/sys-mman-macros.h
new file mode 100644
index 0000000000000..4e2231871466a
--- /dev/null
+++ b/libc/include/llvm-libc-macros/sys-mman-macros.h
@@ -0,0 +1,16 @@
+//===-- Macros defined in sys/mman.h header file --------------------------===//
+//
+// 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_MACROS_SYS_MMAN_MACROS_H
+#define __LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H
+
+#ifdef __unix__
+#include "linux/sys-mman-macros.h"
+#endif
+
+#endif // __LLVM_LIBC_MACROS_SYS_MMAN_MACROS_H

diff  --git a/libc/include/sys/mman.h.def b/libc/include/sys/mman.h.def
index 23435c768cb0a..ab9fde1bb9204 100644
--- a/libc/include/sys/mman.h.def
+++ b/libc/include/sys/mman.h.def
@@ -11,6 +11,8 @@
 
 #include <__llvm-libc-common.h>
 
+#include <llvm-libc-macros/sys-mman-macros.h>
+
 %%public_api()
 
 #endif // LLVM_LIBC_SYS_MMAN_H


        


More information about the libc-commits mailing list