Skip to content

Commit 96c5a16

Browse files
authored
Add support for some mmap.h functions (#286)
1 parent b1faa8c commit 96c5a16

20 files changed

+943
-1
lines changed

pkgs/unix_api/constants.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
"<sys/mman.h>":
2+
- MAP_ANONYMOUS
3+
- MAP_FIXED
4+
- MAP_PRIVATE
5+
- MAP_SHARED
6+
- MCL_CURRENT
7+
- MCL_FUTURE
8+
- MS_ASYNC
9+
- MS_INVALIDATE
10+
- MS_SYNC
11+
- POSIX_MADV_DONTNEED
12+
- POSIX_MADV_NORMAL
13+
- POSIX_MADV_RANDOM
14+
- POSIX_MADV_SEQUENTIAL
15+
- POSIX_MADV_WILLNEED
16+
- POSIX_TYPED_MEM_ALLOCATE
17+
- POSIX_TYPED_MEM_ALLOCATE_CONTIG
18+
- POSIX_TYPED_MEM_MAP_ALLOCATABLE
19+
- PROT_EXEC
20+
- PROT_NONE
21+
- PROT_READ
22+
- PROT_WRITE
123
"<sys/stat.h>":
224
- AT_SYMLINK_NOFOLLOW
325
- AT_RESOLVE_BENEATH
@@ -34,9 +56,11 @@
3456
- UF_HIDDEN
3557
"<errno.h>":
3658
- EACCES
59+
- EBADF
3760
- EDOM
3861
- EEXIST
3962
- EINTR
63+
- EINVAL
4064
- EMFILE
4165
- ENOENT
4266
- ENOSPC

pkgs/unix_api/functions.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@
2222
- prototype: "char *strerror(int)"
2323
comment: "Formats an error code as a string."
2424
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html"
25+
"<sys/mman.h>":
26+
- prototype: "int mlock(const void *, size_t)"
27+
comment: "Locks a range of process address space."
28+
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mlock.html"
29+
error_value: "-1"
30+
- prototype: "int mlockall(int)"
31+
comment: "Locks the processes address space."
32+
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mlockall.html"
33+
- prototype: "void *mmap(void *, size_t, int, int, int, off_t)"
34+
comment: "Maps pages of memory."
35+
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html"
36+
error_value: "MAP_FAILED"
37+
- prototype: "int mprotect(void *, size_t, int)"
38+
comment: "Sets the protection of mapped memory."
39+
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/mprotect.html"
40+
error_value: "-1"
41+
- prototype: "int munlock(const void *, size_t)"
42+
comment: Unlocks a range of process address space."
43+
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/munlock.html"
44+
error_value: "-1"
45+
- prototype: "int munmap(void *, size_t)"
46+
comment: "Unmaps pages of memory."
47+
url: "https://pubs.opengroup.org/onlinepubs/9699919799/functions/munmap.html"
48+
error_value: "-1"
2549
"<sys/stat.h>":
2650
- prototype: "int chmod(const char *, mode_t)"
2751
comment: "Changes the mode of a file."
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Run with `dart run ffigen --config constants-ffigen.yaml`.
2+
name: NativeAddBindings
3+
description: |
4+
Bindings for `handwritten_constants.h`.
5+
6+
Regenerate bindings with `dart run tool/generate.dart`.
7+
output: 'lib/src/handwritten_constant_bindings.g.dart'
8+
headers:
9+
entry-points:
10+
- 'src/handwritten_constants.h'
11+
12+
include-directives:
13+
- 'src/handwritten_constants.h'
14+
comments:
15+
style: any
16+
length: full
17+
ffi-native:
18+
asset-id: package:unix_api/libc_shim

pkgs/unix_api/hook/build.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ void main(List<String> args) async {
1717
libraries: [
1818
if ([OS.linux].contains(input.config.code.targetOS)) 'crypt',
1919
],
20-
sources: ['src/libc_shim.c', 'src/constants.g.c', 'src/functions.g.c'],
20+
sources: [
21+
'src/libc_shim.c',
22+
'src/constants.g.c',
23+
'src/functions.g.c',
24+
'src/handwritten_constants.c',
25+
],
2126
flags: ['-Weverything'],
2227
).run(
2328
input: input,

pkgs/unix_api/lib/src/constant_bindings.g.dart

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)