authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-05 17:25:24-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-05 17:25:24-05:00
logcf7505da1f60757d9fabda20560191bba72ebdbe
tree709e6de0a46293752d9f3dcf67de9565eecc8a1b
parent78840c4ab20d844ca866fa0ab437d72fdec62d0d
parentb42ffbe9e82896c55c68412f99463f54c5e56f21
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6974 from daurnimator/prctl-cleanup

prctl improvements

2 files changed, 138 insertions(+), 53 deletions(-)

lib/std/os.zig+6-3
......@@ -5636,16 +5636,19 @@ pub const PrctlError = error{
56365636 PermissionDenied,
56375637} || UnexpectedError;
56385638
5639pub fn prctl(option: i32, args: anytype) PrctlError!u31 {
5639pub fn prctl(option: PR, args: anytype) PrctlError!u31 {
56405640 if (@typeInfo(@TypeOf(args)) != .Struct)
56415641 @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args)));
56425642 if (args.len > 4)
56435643 @compileError("prctl takes a maximum of 4 optional arguments");
56445644
56455645 var buf: [4]usize = undefined;
5646 inline for (args) |arg, i| buf[i] = arg;
5646 {
5647 comptime var i = 0;
5648 inline while (i < args.len) : (i += 1) buf[i] = args[i];
5649 }
56475650
5648 const rc = system.prctl(option, buf[0], buf[1], buf[2], buf[3]);
5651 const rc = system.prctl(@enumToInt(option), buf[0], buf[1], buf[2], buf[3]);
56495652 switch (errno(rc)) {
56505653 0 => return @intCast(u31, rc),
56515654 EACCES => return error.AccessDenied,
lib/std/os/bits/linux/prctl.zig+132-50
......@@ -4,27 +4,109 @@
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
66
7pub const PR_SET_PDEATHSIG = 1;
8pub const PR_GET_PDEATHSIG = 2;
7pub const PR = extern enum(i32) {
8 SET_PDEATHSIG = 1,
9 GET_PDEATHSIG = 2,
910
10pub const PR_GET_DUMPABLE = 3;
11pub const PR_SET_DUMPABLE = 4;
11 GET_DUMPABLE = 3,
12 SET_DUMPABLE = 4,
1213
13pub const PR_GET_UNALIGN = 5;
14pub const PR_SET_UNALIGN = 6;
14 GET_UNALIGN = 5,
15 SET_UNALIGN = 6,
16
17 GET_KEEPCAPS = 7,
18 SET_KEEPCAPS = 8,
19
20 GET_FPEMU = 9,
21 SET_FPEMU = 10,
22
23 GET_FPEXC = 11,
24 SET_FPEXC = 12,
25
26 GET_TIMING = 13,
27 SET_TIMING = 14,
28
29 SET_NAME = 15,
30 GET_NAME = 16,
31
32 GET_ENDIAN = 19,
33 SET_ENDIAN = 20,
34
35 GET_SECCOMP = 21,
36 SET_SECCOMP = 22,
37
38 CAPBSET_READ = 23,
39 CAPBSET_DROP = 24,
40
41 GET_TSC = 25,
42 SET_TSC = 26,
43
44 GET_SECUREBITS = 27,
45 SET_SECUREBITS = 28,
46
47 SET_TIMERSLACK = 29,
48 GET_TIMERSLACK = 30,
49
50 TASK_PERF_EVENTS_DISABLE = 31,
51 TASK_PERF_EVENTS_ENABLE = 32,
52
53 MCE_KILL = 33,
54
55 MCE_KILL_GET = 34,
56
57 SET_MM = 35,
58
59 SET_PTRACER = 0x59616d61,
60
61 SET_CHILD_SUBREAPER = 36,
62 GET_CHILD_SUBREAPER = 37,
63
64 SET_NO_NEW_PRIVS = 38,
65 GET_NO_NEW_PRIVS = 39,
66
67 GET_TID_ADDRESS = 40,
68
69 SET_THP_DISABLE = 41,
70 GET_THP_DISABLE = 42,
71
72 MPX_ENABLE_MANAGEMENT = 43,
73 MPX_DISABLE_MANAGEMENT = 44,
74
75 SET_FP_MODE = 45,
76 GET_FP_MODE = 46,
77
78 CAP_AMBIENT = 47,
79
80 SVE_SET_VL = 50,
81 SVE_GET_VL = 51,
82
83 GET_SPECULATION_CTRL = 52,
84 SET_SPECULATION_CTRL = 53,
85
86 _,
87};
88
89pub const PR_SET_PDEATHSIG = @enumToInt(PR.PR_SET_PDEATHSIG);
90pub const PR_GET_PDEATHSIG = @enumToInt(PR.PR_GET_PDEATHSIG);
91
92pub const PR_GET_DUMPABLE = @enumToInt(PR.PR_GET_DUMPABLE);
93pub const PR_SET_DUMPABLE = @enumToInt(PR.PR_SET_DUMPABLE);
94
95pub const PR_GET_UNALIGN = @enumToInt(PR.PR_GET_UNALIGN);
96pub const PR_SET_UNALIGN = @enumToInt(PR.PR_SET_UNALIGN);
1597pub const PR_UNALIGN_NOPRINT = 1;
1698pub const PR_UNALIGN_SIGBUS = 2;
1799
18pub const PR_GET_KEEPCAPS = 7;
19pub const PR_SET_KEEPCAPS = 8;
100pub const PR_GET_KEEPCAPS = @enumToInt(PR.PR_GET_KEEPCAPS);
101pub const PR_SET_KEEPCAPS = @enumToInt(PR.PR_SET_KEEPCAPS);
20102
21pub const PR_GET_FPEMU = 9;
22pub const PR_SET_FPEMU = 10;
103pub const PR_GET_FPEMU = @enumToInt(PR.PR_GET_FPEMU);
104pub const PR_SET_FPEMU = @enumToInt(PR.PR_SET_FPEMU);
23105pub const PR_FPEMU_NOPRINT = 1;
24106pub const PR_FPEMU_SIGFPE = 2;
25107
26pub const PR_GET_FPEXC = 11;
27pub const PR_SET_FPEXC = 12;
108pub const PR_GET_FPEXC = @enumToInt(PR.PR_GET_FPEXC);
109pub const PR_SET_FPEXC = @enumToInt(PR.PR_SET_FPEXC);
28110pub const PR_FP_EXC_SW_ENABLE = 0x80;
29111pub const PR_FP_EXC_DIV = 0x010000;
30112pub const PR_FP_EXC_OVF = 0x020000;
......@@ -36,41 +118,41 @@ pub const PR_FP_EXC_NONRECOV = 1;
36118pub const PR_FP_EXC_ASYNC = 2;
37119pub const PR_FP_EXC_PRECISE = 3;
38120
39pub const PR_GET_TIMING = 13;
40pub const PR_SET_TIMING = 14;
121pub const PR_GET_TIMING = @enumToInt(PR.PR_GET_TIMING);
122pub const PR_SET_TIMING = @enumToInt(PR.PR_SET_TIMING);
41123pub const PR_TIMING_STATISTICAL = 0;
42124pub const PR_TIMING_TIMESTAMP = 1;
43125
44pub const PR_SET_NAME = 15;
45pub const PR_GET_NAME = 16;
126pub const PR_SET_NAME = @enumToInt(PR.PR_SET_NAME);
127pub const PR_GET_NAME = @enumToInt(PR.PR_GET_NAME);
46128
47pub const PR_GET_ENDIAN = 19;
48pub const PR_SET_ENDIAN = 20;
129pub const PR_GET_ENDIAN = @enumToInt(PR.PR_GET_ENDIAN);
130pub const PR_SET_ENDIAN = @enumToInt(PR.PR_SET_ENDIAN);
49131pub const PR_ENDIAN_BIG = 0;
50132pub const PR_ENDIAN_LITTLE = 1;
51133pub const PR_ENDIAN_PPC_LITTLE = 2;
52134
53pub const PR_GET_SECCOMP = 21;
54pub const PR_SET_SECCOMP = 22;
135pub const PR_GET_SECCOMP = @enumToInt(PR.PR_GET_SECCOMP);
136pub const PR_SET_SECCOMP = @enumToInt(PR.PR_SET_SECCOMP);
55137
56pub const PR_CAPBSET_READ = 23;
57pub const PR_CAPBSET_DROP = 24;
138pub const PR_CAPBSET_READ = @enumToInt(PR.PR_CAPBSET_READ);
139pub const PR_CAPBSET_DROP = @enumToInt(PR.PR_CAPBSET_DROP);
58140
59pub const PR_GET_TSC = 25;
60pub const PR_SET_TSC = 26;
141pub const PR_GET_TSC = @enumToInt(PR.PR_GET_TSC);
142pub const PR_SET_TSC = @enumToInt(PR.PR_SET_TSC);
61143pub const PR_TSC_ENABLE = 1;
62144pub const PR_TSC_SIGSEGV = 2;
63145
64pub const PR_GET_SECUREBITS = 27;
65pub const PR_SET_SECUREBITS = 28;
146pub const PR_GET_SECUREBITS = @enumToInt(PR.PR_GET_SECUREBITS);
147pub const PR_SET_SECUREBITS = @enumToInt(PR.PR_SET_SECUREBITS);
66148
67pub const PR_SET_TIMERSLACK = 29;
68pub const PR_GET_TIMERSLACK = 30;
149pub const PR_SET_TIMERSLACK = @enumToInt(PR.PR_SET_TIMERSLACK);
150pub const PR_GET_TIMERSLACK = @enumToInt(PR.PR_GET_TIMERSLACK);
69151
70pub const PR_TASK_PERF_EVENTS_DISABLE = 31;
71pub const PR_TASK_PERF_EVENTS_ENABLE = 32;
152pub const PR_TASK_PERF_EVENTS_DISABLE = @enumToInt(PR.PR_TASK_PERF_EVENTS_DISABLE);
153pub const PR_TASK_PERF_EVENTS_ENABLE = @enumToInt(PR.PR_TASK_PERF_EVENTS_ENABLE);
72154
73pub const PR_MCE_KILL = 33;
155pub const PR_MCE_KILL = @enumToInt(PR.PR_MCE_KILL);
74156pub const PR_MCE_KILL_CLEAR = 0;
75157pub const PR_MCE_KILL_SET = 1;
76158
......@@ -78,9 +160,9 @@ pub const PR_MCE_KILL_LATE = 0;
78160pub const PR_MCE_KILL_EARLY = 1;
79161pub const PR_MCE_KILL_DEFAULT = 2;
80162
81pub const PR_MCE_KILL_GET = 34;
163pub const PR_MCE_KILL_GET = @enumToInt(PR.PR_MCE_KILL_GET);
82164
83pub const PR_SET_MM = 35;
165pub const PR_SET_MM = @enumToInt(PR.PR_SET_MM);
84166pub const PR_SET_MM_START_CODE = 1;
85167pub const PR_SET_MM_END_CODE = 2;
86168pub const PR_SET_MM_START_DATA = 3;
......@@ -114,42 +196,42 @@ pub const prctl_mm_map = extern struct {
114196 exe_fd: u32,
115197};
116198
117pub const PR_SET_PTRACER = 0x59616d61;
199pub const PR_SET_PTRACER = @enumToInt(PR.PR_SET_PTRACER);
118200pub const PR_SET_PTRACER_ANY = std.math.maxInt(c_ulong);
119201
120pub const PR_SET_CHILD_SUBREAPER = 36;
121pub const PR_GET_CHILD_SUBREAPER = 37;
202pub const PR_SET_CHILD_SUBREAPER = @enumToInt(PR.PR_SET_CHILD_SUBREAPER);
203pub const PR_GET_CHILD_SUBREAPER = @enumToInt(PR.PR_GET_CHILD_SUBREAPER);
122204
123pub const PR_SET_NO_NEW_PRIVS = 38;
124pub const PR_GET_NO_NEW_PRIVS = 39;
205pub const PR_SET_NO_NEW_PRIVS = @enumToInt(PR.PR_SET_NO_NEW_PRIVS);
206pub const PR_GET_NO_NEW_PRIVS = @enumToInt(PR.PR_GET_NO_NEW_PRIVS);
125207
126pub const PR_GET_TID_ADDRESS = 40;
208pub const PR_GET_TID_ADDRESS = @enumToInt(PR.PR_GET_TID_ADDRESS);
127209
128pub const PR_SET_THP_DISABLE = 41;
129pub const PR_GET_THP_DISABLE = 42;
210pub const PR_SET_THP_DISABLE = @enumToInt(PR.PR_SET_THP_DISABLE);
211pub const PR_GET_THP_DISABLE = @enumToInt(PR.PR_GET_THP_DISABLE);
130212
131pub const PR_MPX_ENABLE_MANAGEMENT = 43;
132pub const PR_MPX_DISABLE_MANAGEMENT = 44;
213pub const PR_MPX_ENABLE_MANAGEMENT = @enumToInt(PR.PR_MPX_ENABLE_MANAGEMENT);
214pub const PR_MPX_DISABLE_MANAGEMENT = @enumToInt(PR.PR_MPX_DISABLE_MANAGEMENT);
133215
134pub const PR_SET_FP_MODE = 45;
135pub const PR_GET_FP_MODE = 46;
216pub const PR_SET_FP_MODE = @enumToInt(PR.PR_SET_FP_MODE);
217pub const PR_GET_FP_MODE = @enumToInt(PR.PR_GET_FP_MODE);
136218pub const PR_FP_MODE_FR = 1 << 0;
137219pub const PR_FP_MODE_FRE = 1 << 1;
138220
139pub const PR_CAP_AMBIENT = 47;
221pub const PR_CAP_AMBIENT = @enumToInt(PR.PR_CAP_AMBIENT);
140222pub const PR_CAP_AMBIENT_IS_SET = 1;
141223pub const PR_CAP_AMBIENT_RAISE = 2;
142224pub const PR_CAP_AMBIENT_LOWER = 3;
143225pub const PR_CAP_AMBIENT_CLEAR_ALL = 4;
144226
145pub const PR_SVE_SET_VL = 50;
227pub const PR_SVE_SET_VL = @enumToInt(PR.PR_SVE_SET_VL);
146228pub const PR_SVE_SET_VL_ONEXEC = 1 << 18;
147pub const PR_SVE_GET_VL = 51;
229pub const PR_SVE_GET_VL = @enumToInt(PR.PR_SVE_GET_VL);
148230pub const PR_SVE_VL_LEN_MASK = 0xffff;
149231pub const PR_SVE_VL_INHERIT = 1 << 17;
150232
151pub const PR_GET_SPECULATION_CTRL = 52;
152pub const PR_SET_SPECULATION_CTRL = 53;
233pub const PR_GET_SPECULATION_CTRL = @enumToInt(PR.PR_GET_SPECULATION_CTRL);
234pub const PR_SET_SPECULATION_CTRL = @enumToInt(PR.PR_SET_SPECULATION_CTRL);
153235pub const PR_SPEC_STORE_BYPASS = 0;
154236pub const PR_SPEC_NOT_AFFECTED = 0;
155237pub const PR_SPEC_PRCTL = 1 << 0;