File tree Expand file tree Collapse file tree 3 files changed +19
-11
lines changed
Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ mmap() bindings for Crystal
55## Todo:
66- [x] mremap
77- [x] mprotect
8- - [ ] madvise
8+ - [x ] madvise
99- [x] mlock
1010- [x] msync
1111
Original file line number Diff line number Diff line change 11lib LibC
22 {% if flag?(:linux ) % }
3- MS_SYNC = 4
3+ MS_SYNC = 4
44 MREMAP_MAYMOVE = 1
55
6- MAP_HUGETLB = 0x040000
6+ MAP_DONTFORK = 10
7+ MAP_DONTDUMP = 16
8+ MAP_WIPEONFORK = 18
9+
10+ MAP_HUGETLB = 0x040000
711 MAP_HUGE_2MB = 21 << 26
812 MAP_HUGE_1GB = 30 << 26
913 {% else % }
10- MAP_HUGETLB = 0
14+ MAP_DONTFORK = 0
15+ MAP_DONTDUMP = 0
16+ MAP_WIPEONFORK = 0
17+
18+ MAP_HUGETLB = 0
1119 MAP_HUGE_2MB = 0
1220 MAP_HUGE_1GB = 0
1321 {% end % }
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ module Mmap
88
99 @[Flags ]
1010 enum Prot
11- None = LibC ::PROT_NONE
12- Read = LibC ::PROT_READ
13- Write = LibC ::PROT_WRITE
11+ None = LibC ::PROT_NONE
12+ Read = LibC ::PROT_READ
13+ Write = LibC ::PROT_WRITE
1414 ReadWrite = Read | Write
15- Exec = LibC ::PROT_EXEC
15+ Exec = LibC ::PROT_EXEC
1616 end
1717
1818 @[Flags ]
@@ -23,7 +23,7 @@ module Mmap
2323 # Linux only.
2424 # Only works with anonymous memory.
2525 # Would be nice if the man page mentioned that
26- Huge = LibC ::MAP_HUGETLB
26+ Huge = LibC ::MAP_HUGETLB
2727 Huge_2mb = LibC ::MAP_HUGETLB | LibC ::MAP_HUGE_2MB
2828 Huge_1gb = LibC ::MAP_HUGETLB | LibC ::MAP_HUGE_1GB
2929 # Stack = LibC::MAP_STACK # Linux: flag exists but not implemented
@@ -63,9 +63,9 @@ module Mmap
6363 raise RuntimeError .from_errno(" mprotect" ) if r != 0
6464 end
6565
66- def madvise () : Nil
66+ def madvise (advice ) : Nil
6767 ptr = range_checked_pointer(0 , @size )
68- r = LibC .madvise(ptr, @size , )
68+ r = LibC .madvise(ptr, @size , advice )
6969 raise RuntimeError .from_errno(" madvise" ) if r != 0
7070 end
7171
You can’t perform that action at this time.
0 commit comments