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