authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-09-11 01:34:10+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-09-11 22:32:22+02:00
log7b961a876b56d5926fe7ba6437a0459da9aa60bc
tree37e2d913c2fe07b5394c66a2d27dc684315ad374
parent68bf29c31efb770d7e25d0922c9305673e606f36
signaturelock-open Commit is signed but in an unrecognized format.

std: add prctl definition for linux


3 files changed, 163 insertions(+), 0 deletions(-)

lib/std/os/bits/linux.zig+1
...@@ -25,6 +25,7 @@ pub usingnamespace switch (builtin.arch) {...@@ -25,6 +25,7 @@ pub usingnamespace switch (builtin.arch) {
25};25};
2626
27pub usingnamespace @import("linux/netlink.zig");27pub usingnamespace @import("linux/netlink.zig");
28pub usingnamespace @import("linux/prctl.zig");
2829
29const is_mips = builtin.arch.isMIPS();30const is_mips = builtin.arch.isMIPS();
3031
lib/std/os/bits/linux/prctl.zig created+158
...@@ -0,0 +1,158 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2020 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7pub const PR_SET_PDEATHSIG = 1;
8pub const PR_GET_PDEATHSIG = 2;
9
10pub const PR_GET_DUMPABLE = 3;
11pub const PR_SET_DUMPABLE = 4;
12
13pub const PR_GET_UNALIGN = 5;
14pub const PR_SET_UNALIGN = 6;
15pub const PR_UNALIGN_NOPRINT = 1;
16pub const PR_UNALIGN_SIGBUS = 2;
17
18pub const PR_GET_KEEPCAPS = 7;
19pub const PR_SET_KEEPCAPS = 8;
20
21pub const PR_GET_FPEMU = 9;
22pub const PR_SET_FPEMU = 10;
23pub const PR_FPEMU_NOPRINT = 1;
24pub const PR_FPEMU_SIGFPE = 2;
25
26pub const PR_GET_FPEXC = 11;
27pub const PR_SET_FPEXC = 12;
28pub const PR_FP_EXC_SW_ENABLE = 0x80;
29pub const PR_FP_EXC_DIV = 0x010000;
30pub const PR_FP_EXC_OVF = 0x020000;
31pub const PR_FP_EXC_UND = 0x040000;
32pub const PR_FP_EXC_RES = 0x080000;
33pub const PR_FP_EXC_INV = 0x100000;
34pub const PR_FP_EXC_DISABLED = 0;
35pub const PR_FP_EXC_NONRECOV = 1;
36pub const PR_FP_EXC_ASYNC = 2;
37pub const PR_FP_EXC_PRECISE = 3;
38
39pub const PR_GET_TIMING = 13;
40pub const PR_SET_TIMING = 14;
41pub const PR_TIMING_STATISTICAL = 0;
42pub const PR_TIMING_TIMESTAMP = 1;
43
44pub const PR_SET_NAME = 15;
45pub const PR_GET_NAME = 16;
46
47pub const PR_GET_ENDIAN = 19;
48pub const PR_SET_ENDIAN = 20;
49pub const PR_ENDIAN_BIG = 0;
50pub const PR_ENDIAN_LITTLE = 1;
51pub const PR_ENDIAN_PPC_LITTLE = 2;
52
53pub const PR_GET_SECCOMP = 21;
54pub const PR_SET_SECCOMP = 22;
55
56pub const PR_CAPBSET_READ = 23;
57pub const PR_CAPBSET_DROP = 24;
58
59pub const PR_GET_TSC = 25;
60pub const PR_SET_TSC = 26;
61pub const PR_TSC_ENABLE = 1;
62pub const PR_TSC_SIGSEGV = 2;
63
64pub const PR_GET_SECUREBITS = 27;
65pub const PR_SET_SECUREBITS = 28;
66
67pub const PR_SET_TIMERSLACK = 29;
68pub const PR_GET_TIMERSLACK = 30;
69
70pub const PR_TASK_PERF_EVENTS_DISABLE = 31;
71pub const PR_TASK_PERF_EVENTS_ENABLE = 32;
72
73pub const PR_MCE_KILL = 33;
74pub const PR_MCE_KILL_CLEAR = 0;
75pub const PR_MCE_KILL_SET = 1;
76
77pub const PR_MCE_KILL_LATE = 0;
78pub const PR_MCE_KILL_EARLY = 1;
79pub const PR_MCE_KILL_DEFAULT = 2;
80
81pub const PR_MCE_KILL_GET = 34;
82
83pub const PR_SET_MM = 35;
84pub const PR_SET_MM_START_CODE = 1;
85pub const PR_SET_MM_END_CODE = 2;
86pub const PR_SET_MM_START_DATA = 3;
87pub const PR_SET_MM_END_DATA = 4;
88pub const PR_SET_MM_START_STACK = 5;
89pub const PR_SET_MM_START_BRK = 6;
90pub const PR_SET_MM_BRK = 7;
91pub const PR_SET_MM_ARG_START = 8;
92pub const PR_SET_MM_ARG_END = 9;
93pub const PR_SET_MM_ENV_START = 10;
94pub const PR_SET_MM_ENV_END = 11;
95pub const PR_SET_MM_AUXV = 12;
96pub const PR_SET_MM_EXE_FILE = 13;
97pub const PR_SET_MM_MAP = 14;
98pub const PR_SET_MM_MAP_SIZE = 15;
99
100pub const prctl_mm_map = extern struct {
101 start_code: u64,
102 end_code: u64,
103 start_data: u64,
104 end_data: u64,
105 start_brk: u64,
106 brk: u64,
107 start_stack: u64,
108 arg_start: u64,
109 arg_end: u64,
110 env_start: u64,
111 env_end: u64,
112 auxv: *u64,
113 auxv_size: u32,
114 exe_fd: u32,
115};
116
117pub const PR_SET_PTRACER = 0x59616d61;
118pub const PR_SET_PTRACER_ANY = std.math.maxInt(c_ulong);
119
120pub const PR_SET_CHILD_SUBREAPER = 36;
121pub const PR_GET_CHILD_SUBREAPER = 37;
122
123pub const PR_SET_NO_NEW_PRIVS = 38;
124pub const PR_GET_NO_NEW_PRIVS = 39;
125
126pub const PR_GET_TID_ADDRESS = 40;
127
128pub const PR_SET_THP_DISABLE = 41;
129pub const PR_GET_THP_DISABLE = 42;
130
131pub const PR_MPX_ENABLE_MANAGEMENT = 43;
132pub const PR_MPX_DISABLE_MANAGEMENT = 44;
133
134pub const PR_SET_FP_MODE = 45;
135pub const PR_GET_FP_MODE = 46;
136pub const PR_FP_MODE_FR = 1 << 0;
137pub const PR_FP_MODE_FRE = 1 << 1;
138
139pub const PR_CAP_AMBIENT = 47;
140pub const PR_CAP_AMBIENT_IS_SET = 1;
141pub const PR_CAP_AMBIENT_RAISE = 2;
142pub const PR_CAP_AMBIENT_LOWER = 3;
143pub const PR_CAP_AMBIENT_CLEAR_ALL = 4;
144
145pub const PR_SVE_SET_VL = 50;
146pub const PR_SVE_SET_VL_ONEXEC = 1 << 18;
147pub const PR_SVE_GET_VL = 51;
148pub const PR_SVE_VL_LEN_MASK = 0xffff;
149pub const PR_SVE_VL_INHERIT = 1 << 17;
150
151pub const PR_GET_SPECULATION_CTRL = 52;
152pub const PR_SET_SPECULATION_CTRL = 53;
153pub const PR_SPEC_STORE_BYPASS = 0;
154pub const PR_SPEC_NOT_AFFECTED = 0;
155pub const PR_SPEC_PRCTL = 1 << 0;
156pub const PR_SPEC_ENABLE = 1 << 1;
157pub const PR_SPEC_DISABLE = 1 << 2;
158pub const PR_SPEC_FORCE_DISABLE = 1 << 3;
lib/std/os/linux.zig+4
...@@ -1259,6 +1259,10 @@ pub fn fdatasync(fd: fd_t) usize {...@@ -1259,6 +1259,10 @@ pub fn fdatasync(fd: fd_t) usize {
1259 return syscall1(.fdatasync, @bitCast(usize, @as(isize, fd)));1259 return syscall1(.fdatasync, @bitCast(usize, @as(isize, fd)));
1260}1260}
12611261
1262pub fn prctl(option: i32, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
1263 return syscall5(.prctl, @bitCast(usize, @as(isize, option)), arg2, arg3, arg4, arg5);
1264}
1265
1262test "" {1266test "" {
1263 if (builtin.os.tag == .linux) {1267 if (builtin.os.tag == .linux) {
1264 _ = @import("linux/test.zig");1268 _ = @import("linux/test.zig");