authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-07 09:53:05-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-07-07 09:53:05-04:00
log38ba4127290d860cadcf078eeda7213094f6c3c7
tree38cda37cc4a33441618412e68f1de813faaab944
parente12eb5e7f6d257323adf949c9c850323b9d4ebba
parent111e5ed0a24ca7e96d24e0967b6c28226c0f3297
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2837 from daurnimator/linux-AT_

std: improvements to linux constants

5 files changed, 115 insertions(+), 24 deletions(-)

std/c/linux.zig+3
...@@ -1,9 +1,12 @@...@@ -1,9 +1,12 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const maxInt = std.math.maxInt;
2usingnamespace std.c;3usingnamespace std.c;
34
4extern "c" fn __errno_location() *c_int;5extern "c" fn __errno_location() *c_int;
5pub const _errno = __errno_location;6pub const _errno = __errno_location;
67
8pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
9
7pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;10pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
8pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;11pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
9pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;12pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
std/os.zig+1-1
...@@ -1961,7 +1961,7 @@ pub fn mmap(...@@ -1961,7 +1961,7 @@ pub fn mmap(
1961) MMapError![]align(mem.page_size) u8 {1961) MMapError![]align(mem.page_size) u8 {
1962 const err = if (builtin.link_libc) blk: {1962 const err = if (builtin.link_libc) blk: {
1963 const rc = std.c.mmap(ptr, length, prot, flags, fd, offset);1963 const rc = std.c.mmap(ptr, length, prot, flags, fd, offset);
1964 if (rc != MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];1964 if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
1965 break :blk @intCast(usize, system._errno().*);1965 break :blk @intCast(usize, system._errno().*);
1966 } else blk: {1966 } else blk: {
1967 const rc = system.mmap(ptr, length, prot, flags, fd, offset);1967 const rc = system.mmap(ptr, length, prot, flags, fd, offset);
std/os/bits/linux.zig+50-11
...@@ -22,6 +22,36 @@ pub const STDIN_FILENO = 0;...@@ -22,6 +22,36 @@ pub const STDIN_FILENO = 0;
22pub const STDOUT_FILENO = 1;22pub const STDOUT_FILENO = 1;
23pub const STDERR_FILENO = 2;23pub const STDERR_FILENO = 2;
2424
25/// Special value used to indicate openat should use the current working directory
26pub const AT_FDCWD = 100;
27
28/// Do not follow symbolic links
29pub const AT_SYMLINK_NOFOLLOW = 0x100;
30
31/// Remove directory instead of unlinking file
32pub const AT_REMOVEDIR = 0x200;
33
34/// Follow symbolic links.
35pub const AT_SYMLINK_FOLLOW = 0x400;
36
37/// Suppress terminal automount traversal
38pub const AT_NO_AUTOMOUNT = 0x800;
39
40/// Allow empty relative pathname
41pub const AT_EMPTY_PATH = 0x1000;
42
43/// Type of synchronisation required from statx()
44pub const AT_STATX_SYNC_TYPE = 0x6000;
45
46/// - Do whatever stat() does
47pub const AT_STATX_SYNC_AS_STAT = 0x0000;
48
49/// - Force the attributes to be sync'd with the server
50pub const AT_STATX_FORCE_SYNC = 0x2000;
51
52/// - Don't sync attributes with the server
53pub const AT_STATX_DONT_SYNC = 0x4000;
54
25pub const FUTEX_WAIT = 0;55pub const FUTEX_WAIT = 0;
26pub const FUTEX_WAKE = 1;56pub const FUTEX_WAKE = 1;
27pub const FUTEX_FD = 2;57pub const FUTEX_FD = 2;
...@@ -44,22 +74,31 @@ pub const PROT_EXEC = 4;...@@ -44,22 +74,31 @@ pub const PROT_EXEC = 4;
44pub const PROT_GROWSDOWN = 0x01000000;74pub const PROT_GROWSDOWN = 0x01000000;
45pub const PROT_GROWSUP = 0x02000000;75pub const PROT_GROWSUP = 0x02000000;
4676
47pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));77/// Share changes
48pub const MAP_SHARED = 0x01;78pub const MAP_SHARED = 0x01;
79
80/// Changes are private
49pub const MAP_PRIVATE = 0x02;81pub const MAP_PRIVATE = 0x02;
82
83/// share + validate extension flags
84pub const MAP_SHARED_VALIDATE = 0x03;
85
86/// Mask for type of mapping
50pub const MAP_TYPE = 0x0f;87pub const MAP_TYPE = 0x0f;
88
89/// Interpret addr exactly
51pub const MAP_FIXED = 0x10;90pub const MAP_FIXED = 0x10;
91
92/// don't use a file
52pub const MAP_ANONYMOUS = 0x20;93pub const MAP_ANONYMOUS = 0x20;
53pub const MAP_NORESERVE = 0x4000;94
54pub const MAP_GROWSDOWN = 0x0100;95/// For anonymous mmap, memory could be uninitialized
55pub const MAP_DENYWRITE = 0x0800;96pub const MAP_UNINITIALIZED = 0x4000000;
56pub const MAP_EXECUTABLE = 0x1000;97
57pub const MAP_LOCKED = 0x2000;98// MAP_ 0x0100 - 0x80000 flags are per architecture
58pub const MAP_POPULATE = 0x8000;99
59pub const MAP_NONBLOCK = 0x10000;100/// MAP_FIXED which doesn't unmap underlying mapping
60pub const MAP_STACK = 0x20000;101pub const MAP_FIXED_NOREPLACE = 0x100000;
61pub const MAP_HUGETLB = 0x40000;
62pub const MAP_FILE = 0;
63102
64pub const F_OK = 0;103pub const F_OK = 0;
65pub const X_OK = 1;104pub const X_OK = 1;
std/os/bits/linux/arm64.zig+29-6
...@@ -331,12 +331,35 @@ pub const F_GETOWN_EX = 16;...@@ -331,12 +331,35 @@ pub const F_GETOWN_EX = 16;
331331
332pub const F_GETOWNER_UIDS = 17;332pub const F_GETOWNER_UIDS = 17;
333333
334pub const AT_FDCWD = -100;334/// stack-like segment
335pub const AT_SYMLINK_NOFOLLOW = 0x100;335pub const MAP_GROWSDOWN = 0x0100;
336pub const AT_REMOVEDIR = 0x200;336
337pub const AT_SYMLINK_FOLLOW = 0x400;337/// ETXTBSY
338pub const AT_NO_AUTOMOUNT = 0x800;338pub const MAP_DENYWRITE = 0x0800;
339pub const AT_EMPTY_PATH = 0x1000;339
340/// mark it as an executable
341pub const MAP_EXECUTABLE = 0x1000;
342
343/// pages are locked
344pub const MAP_LOCKED = 0x2000;
345
346/// don't check for reservations
347pub const MAP_NORESERVE = 0x4000;
348
349/// populate (prefault) pagetables
350pub const MAP_POPULATE = 0x8000;
351
352/// do not block on IO
353pub const MAP_NONBLOCK = 0x10000;
354
355/// give out an address that is best suited for process/thread stacks
356pub const MAP_STACK = 0x20000;
357
358/// create a huge page mapping
359pub const MAP_HUGETLB = 0x40000;
360
361/// perform synchronous page faults for the mapping
362pub const MAP_SYNC = 0x80000;
340363
341pub const VDSO_USEFUL = true;364pub const VDSO_USEFUL = true;
342pub const VDSO_CGT_SYM = "__kernel_clock_gettime";365pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
std/os/bits/linux/x86_64.zig+32-6
...@@ -394,12 +394,38 @@ pub const F_GETOWN_EX = 16;...@@ -394,12 +394,38 @@ pub const F_GETOWN_EX = 16;
394394
395pub const F_GETOWNER_UIDS = 17;395pub const F_GETOWNER_UIDS = 17;
396396
397pub const AT_FDCWD = -100;397/// only give out 32bit addresses
398pub const AT_SYMLINK_NOFOLLOW = 0x100;398pub const MAP_32BIT = 0x40;
399pub const AT_REMOVEDIR = 0x200;399
400pub const AT_SYMLINK_FOLLOW = 0x400;400/// stack-like segment
401pub const AT_NO_AUTOMOUNT = 0x800;401pub const MAP_GROWSDOWN = 0x0100;
402pub const AT_EMPTY_PATH = 0x1000;402
403/// ETXTBSY
404pub const MAP_DENYWRITE = 0x0800;
405
406/// mark it as an executable
407pub const MAP_EXECUTABLE = 0x1000;
408
409/// pages are locked
410pub const MAP_LOCKED = 0x2000;
411
412/// don't check for reservations
413pub const MAP_NORESERVE = 0x4000;
414
415/// populate (prefault) pagetables
416pub const MAP_POPULATE = 0x8000;
417
418/// do not block on IO
419pub const MAP_NONBLOCK = 0x10000;
420
421/// give out an address that is best suited for process/thread stacks
422pub const MAP_STACK = 0x20000;
423
424/// create a huge page mapping
425pub const MAP_HUGETLB = 0x40000;
426
427/// perform synchronous page faults for the mapping
428pub const MAP_SYNC = 0x80000;
403429
404pub const VDSO_USEFUL = true;430pub const VDSO_USEFUL = true;
405pub const VDSO_CGT_SYM = "__vdso_clock_gettime";431pub const VDSO_CGT_SYM = "__vdso_clock_gettime";