|
| 1 | +using BitFlags |
| 2 | +import .Sys # explicitly imported to allow docs generation to override |
| 3 | + |
| 4 | +@bitflag MmapProtection::Cuint begin |
| 5 | + PROT_NONE = 0x00 |
| 6 | + PROT_READ = 0x01 |
| 7 | + PROT_WRITE = 0x02 |
| 8 | + PROT_EXEC = 0x04 |
| 9 | +end |
| 10 | +Base.cconvert(::Type{T}, pf::MmapProtection) where {T <: Integer} = T(pf) |
| 11 | + |
| 12 | +@staticexpand @bitflag MmapFlags::Cuint begin |
| 13 | + MAP_FILE = 0x00 |
| 14 | + MAP_SHARED = 0x01 |
| 15 | + MAP_PRIVATE = 0x02 |
| 16 | + MAP_FIXED = 0x0010 |
| 17 | + MAP_ANONYMOUS = @static Sys.isbsd() ? 0x1000 : 0x0020 |
| 18 | + @static if Sys.islinux() |
| 19 | + MAP_32BIT = 0x0040 |
| 20 | + MAP_GROWSDOWN = 0x0100 |
| 21 | + MAP_DENYWRITE = 0x0800 |
| 22 | + MAP_EXECUTABLE = 0x1000 |
| 23 | + MAP_LOCKED = 0x2000 |
| 24 | + MAP_NORESERVE = 0x4000 |
| 25 | + MAP_POPULATE = 0x8000 |
| 26 | + MAP_NONBLOCK = 0x1_0000 |
| 27 | + MAP_STACK = 0x2_0000 |
| 28 | + MAP_HUGETLB = 0x4_0000 |
| 29 | + MAP_SYNC = 0x8_0000 |
| 30 | + MAP_FIXED_NOREPLACE = 0x10_0000 |
| 31 | + end |
| 32 | + @static if Sys.isapple() || (VERSION >= v"1.1" && (Sys.isnetbsd() || Sys.isdragonfly())) |
| 33 | + MAP_RENAME = 0x0020 |
| 34 | + MAP_NORESERVE = 0x0040 |
| 35 | + MAP_INHERIT = 0x0080 |
| 36 | + MAP_NOEXTEND = 0x0100 |
| 37 | + MAP_HASSEMAPHORE = 0x0200 |
| 38 | + end |
| 39 | + @static if VERSION >= v"1.1" && Sys.isfreebsd() |
| 40 | + MAP_STACK = 0x0400 |
| 41 | + MAP_NOSYNC = 0x0800 |
| 42 | + MAP_GUARD = 0x2000 |
| 43 | + MAP_EXCL = 0x4000 |
| 44 | + MAP_NOCORE = 0x4_0000 |
| 45 | + MAP_32BIT = 0x8_0000 |
| 46 | + elseif VERSION >= v"1.1" && Sys.isdragonfly() |
| 47 | + MAP_STACK = 0x0400 |
| 48 | + MAP_NOSYNC = 0x0800 |
| 49 | + MAP_VPAGETABLE = 0x2000 |
| 50 | + MAP_TRYFIXED = 0x1_0000 |
| 51 | + MAP_NOCORE = 0x2_0000 |
| 52 | + MAP_SIZEALIGN = 0x4_0000 |
| 53 | + elseif VERSION >= v"1.1" && Sys.isopenbsd() |
| 54 | + MAP_STACK = 0x4000 |
| 55 | + MAP_CONCEAL = 0x8000 |
| 56 | + elseif VERSION >= v"1.1" && Sys.isnetbsd() |
| 57 | + MAP_REMAPDUP = 0x0004 |
| 58 | + MAP_TRYFIXED = 0x0400 |
| 59 | + MAP_WIRED = 0x0800 |
| 60 | + MAP_STACK = 0x2000 |
| 61 | + end |
| 62 | +end |
| 63 | +Base.cconvert(::Type{T}, mf::MmapFlags) where {T <: Integer} = T(mf) |
| 64 | + |
| 65 | +# Provide this weird mode? |
| 66 | +#@static if Sys.islinux() |
| 67 | +#const MAP_SHARED_VALIDATE = MmapFlags(0x03) |
| 68 | +#end |
| 69 | + |
| 70 | +@staticexpand @enum AdviseFlags::Cint begin |
| 71 | + MADV_NORMAL = 0 |
| 72 | + MADV_RANDOM = 1 |
| 73 | + MADV_SEQUENTIAL = 2 |
| 74 | + MADV_WILLNEED = 3 |
| 75 | + MADV_DONTNEED = 4 |
| 76 | + @static if Sys.islinux() |
| 77 | + MADV_FREE = 8 |
| 78 | + MADV_REMOVE = 9 |
| 79 | + MADV_DONTFORK = 10 |
| 80 | + MADV_DOFORK = 11 |
| 81 | + MADV_MERGEABLE = 12 |
| 82 | + MADV_UNMERGEABLE = 13 |
| 83 | + MADV_HUGEPAGE = 14 |
| 84 | + MADV_NOHUGEPAGE = 15 |
| 85 | + MADV_DONTDUMP = 16 |
| 86 | + MADV_DODUMP = 17 |
| 87 | + MADV_WIPEONFORK = 18 |
| 88 | + MADV_KEEPONFORK = 19 |
| 89 | + MADV_COLD = 20 |
| 90 | + MADV_PAGEOUT = 21 |
| 91 | + MADV_HWPOISON = 100 |
| 92 | + MADV_SOFT_OFFLINE = 101 |
| 93 | + elseif Sys.isapple() |
| 94 | + MADV_FREE = 5 |
| 95 | + elseif VERSION >= v"1.1" && (Sys.isfreebsd() || Sys.isdragonfly()) |
| 96 | + MADV_FREE = 5 |
| 97 | + MADV_NOSYNC = 6 |
| 98 | + MADV_AUTOSYNC = 7 |
| 99 | + MADV_NOCORE = 8 |
| 100 | + MADV_CORE = 9 |
| 101 | + @static if Sys.isfreebsd() |
| 102 | + MADV_PROTECT = 10 |
| 103 | + else |
| 104 | + MADV_INVAL = 10 |
| 105 | + MADV_SETMAP = 11 |
| 106 | + end |
| 107 | + elseif VERSION >= v"1.1" && (Sys.isopenbsd() || Sys.isnetbsd()) |
| 108 | + MADV_SPACEAVAIL = 5 |
| 109 | + MADV_FREE = 6 |
| 110 | + end |
| 111 | +end |
| 112 | +Base.cconvert(::Type{T}, af::AdviseFlags) where {T <: Integer} = T(af) |
| 113 | + |
| 114 | +# documentation requires the types to be defined first, so do after the fact |
| 115 | +let _flag_docs |
| 116 | + function _flag_docs(T) |
| 117 | + buf = IOBuffer() |
| 118 | + for c in instances(T) |
| 119 | + println(buf, c) |
| 120 | + end |
| 121 | + return rstrip(String(take!(buf))) |
| 122 | + end |
| 123 | + |
| 124 | + @doc """ |
| 125 | + @bitflag UnixMmap.MmapProtection |
| 126 | +
|
| 127 | + Set of bit flags which control the memory protections applied to the memory mapped |
| 128 | + region. The flag should be either `PROT_NONE` or some bitwise-or combination of |
| 129 | + the remaining flags. |
| 130 | +
|
| 131 | + The flags available on $(Sys.KERNEL) are: |
| 132 | + ```julia |
| 133 | + $(_flag_docs(MmapProtection)) |
| 134 | + ``` |
| 135 | + """ MmapProtection |
| 136 | + |
| 137 | + @doc """ |
| 138 | + @bitflag UnixMmap.MmapFlags |
| 139 | +
|
| 140 | + Set of bit flags which control the handling of the memory mappged region. The flag |
| 141 | + should be a bitwise-or combination of flags. |
| 142 | +
|
| 143 | + The flags available on $(Sys.KERNEL) are: |
| 144 | + ```julia |
| 145 | + $(_flag_docs(MmapFlags)) |
| 146 | + ``` |
| 147 | + """ MmapFlags |
| 148 | + |
| 149 | + @doc """ |
| 150 | + @enum UnixMmap.AdviseFlags |
| 151 | +
|
| 152 | + Set of flags which advise the kernel on handling of the memory mapped region. |
| 153 | +
|
| 154 | + The flags available on $(Sys.KERNEL) are: |
| 155 | + ```julia |
| 156 | + $(_flag_docs(AdviseFlags)) |
| 157 | + ``` |
| 158 | + """ AdviseFlags |
| 159 | +end |
0 commit comments