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 @@
11const std = @import("../std.zig");
2const maxInt = std.math.maxInt;
23usingnamespace std.c;
34
45extern "c" fn __errno_location() *c_int;
56pub const _errno = __errno_location;
67
8pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
9
710pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
811pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
912pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
std/os.zig+1-1
......@@ -1961,7 +1961,7 @@ pub fn mmap(
19611961) MMapError![]align(mem.page_size) u8 {
19621962 const err = if (builtin.link_libc) blk: {
19631963 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];
19651965 break :blk @intCast(usize, system._errno().*);
19661966 } else blk: {
19671967 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;
2222pub const STDOUT_FILENO = 1;
2323pub 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
2555pub const FUTEX_WAIT = 0;
2656pub const FUTEX_WAKE = 1;
2757pub const FUTEX_FD = 2;
......@@ -44,22 +74,31 @@ pub const PROT_EXEC = 4;
4474pub const PROT_GROWSDOWN = 0x01000000;
4575pub const PROT_GROWSUP = 0x02000000;
4676
47pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
77/// Share changes
4878pub const MAP_SHARED = 0x01;
79
80/// Changes are private
4981pub const MAP_PRIVATE = 0x02;
82
83/// share + validate extension flags
84pub const MAP_SHARED_VALIDATE = 0x03;
85
86/// Mask for type of mapping
5087pub const MAP_TYPE = 0x0f;
88
89/// Interpret addr exactly
5190pub const MAP_FIXED = 0x10;
91
92/// don't use a file
5293pub const MAP_ANONYMOUS = 0x20;
53pub const MAP_NORESERVE = 0x4000;
54pub const MAP_GROWSDOWN = 0x0100;
55pub const MAP_DENYWRITE = 0x0800;
56pub const MAP_EXECUTABLE = 0x1000;
57pub const MAP_LOCKED = 0x2000;
58pub const MAP_POPULATE = 0x8000;
59pub const MAP_NONBLOCK = 0x10000;
60pub const MAP_STACK = 0x20000;
61pub const MAP_HUGETLB = 0x40000;
62pub const MAP_FILE = 0;
94
95/// For anonymous mmap, memory could be uninitialized
96pub const MAP_UNINITIALIZED = 0x4000000;
97
98// MAP_ 0x0100 - 0x80000 flags are per architecture
99
100/// MAP_FIXED which doesn't unmap underlying mapping
101pub const MAP_FIXED_NOREPLACE = 0x100000;
63102
64103pub const F_OK = 0;
65104pub const X_OK = 1;
std/os/bits/linux/arm64.zig+29-6
......@@ -331,12 +331,35 @@ pub const F_GETOWN_EX = 16;
331331
332332pub const F_GETOWNER_UIDS = 17;
333333
334pub const AT_FDCWD = -100;
335pub const AT_SYMLINK_NOFOLLOW = 0x100;
336pub const AT_REMOVEDIR = 0x200;
337pub const AT_SYMLINK_FOLLOW = 0x400;
338pub const AT_NO_AUTOMOUNT = 0x800;
339pub const AT_EMPTY_PATH = 0x1000;
334/// stack-like segment
335pub const MAP_GROWSDOWN = 0x0100;
336
337/// ETXTBSY
338pub const MAP_DENYWRITE = 0x0800;
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
341364pub const VDSO_USEFUL = true;
342365pub 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;
394394
395395pub const F_GETOWNER_UIDS = 17;
396396
397pub const AT_FDCWD = -100;
398pub const AT_SYMLINK_NOFOLLOW = 0x100;
399pub const AT_REMOVEDIR = 0x200;
400pub const AT_SYMLINK_FOLLOW = 0x400;
401pub const AT_NO_AUTOMOUNT = 0x800;
402pub const AT_EMPTY_PATH = 0x1000;
397/// only give out 32bit addresses
398pub const MAP_32BIT = 0x40;
399
400/// stack-like segment
401pub const MAP_GROWSDOWN = 0x0100;
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
404430pub const VDSO_USEFUL = true;
405431pub const VDSO_CGT_SYM = "__vdso_clock_gettime";