1 /**
2  * D header file for GNU/Linux.
3  *
4  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
5  * Authors:   Arun Chandrasekaran <aruncxy@gmail.com>
6  */
7 module core.sys.linux.sys.prctl;
8 
9 version (linux):
10 extern (C):
11 @nogc:
12 nothrow:
13 
14 enum: uint
15 {
16     PR_SET_PDEATHSIG                    = 1,
17     PR_GET_PDEATHSIG                    = 2,
18 
19     PR_GET_DUMPABLE                     = 3,
20     PR_SET_DUMPABLE                     = 4,
21 
22     PR_GET_UNALIGN                      = 5,
23     PR_SET_UNALIGN                      = 6,
24 
25     PR_UNALIGN_NOPRINT                  = 1,
26     PR_UNALIGN_SIGBUS                   = 2,
27 
28     PR_GET_KEEPCAPS                     = 7,
29     PR_SET_KEEPCAPS                     = 8,
30 
31     PR_GET_FPEMU                        = 9,
32     PR_SET_FPEMU                        = 10,
33     PR_FPEMU_NOPRINT                    = 1,
34     PR_FPEMU_SIGFPE                     = 2,
35 
36     PR_GET_FPEXC                        = 11,
37     PR_SET_FPEXC                        = 12,
38     PR_FP_EXC_SW_ENABLE                 = 0x80,
39     PR_FP_EXC_DIV                       = 0x010000,
40     PR_FP_EXC_OVF                       = 0x020000,
41     PR_FP_EXC_UND                       = 0x040000,
42     PR_FP_EXC_RES                       = 0x080000,
43     PR_FP_EXC_INV                       = 0x100000,
44     PR_FP_EXC_DISABLED                  = 0,
45     PR_FP_EXC_NONRECOV                  = 1,
46     PR_FP_EXC_ASYNC                     = 2,
47     PR_FP_EXC_PRECISE                   = 3,
48 
49     PR_GET_TIMING                       = 13,
50     PR_SET_TIMING                       = 14,
51     PR_TIMING_STATISTICAL               = 0,
52     PR_TIMING_TIMESTAMP                 = 1,
53 
54     PR_SET_NAME                         = 15,
55     PR_GET_NAME                         = 16,
56 
57     PR_GET_ENDIAN                       = 19,
58     PR_SET_ENDIAN                       = 20,
59     PR_ENDIAN_BIG                       = 0,
60     PR_ENDIAN_LITTLE                    = 1,
61     PR_ENDIAN_PPC_LITTLE                = 2,
62 
63     PR_GET_SECCOMP                      = 21,
64     PR_SET_SECCOMP                      = 22,
65 
66     PR_CAPBSET_READ                     = 23,
67     PR_CAPBSET_DROP                     = 24,
68 
69     PR_GET_TSC                          = 25,
70     PR_SET_TSC                          = 26,
71     PR_TSC_ENABLE                       = 1,
72     PR_TSC_SIGSEGV                      = 2,
73 
74     PR_GET_SECUREBITS                   = 27,
75     PR_SET_SECUREBITS                   = 28,
76 
77 
78     PR_SET_TIMERSLACK                   = 29,
79     PR_GET_TIMERSLACK                   = 30,
80 
81     PR_TASK_PERF_EVENTS_DISABLE         = 31,
82     PR_TASK_PERF_EVENTS_ENABLE          = 32,
83 
84 
85     PR_MCE_KILL                         = 33,
86     PR_MCE_KILL_CLEAR                   = 0,
87     PR_MCE_KILL_SET                     = 1,
88 
89     PR_MCE_KILL_LATE                    = 0,
90     PR_MCE_KILL_EARLY                   = 1,
91     PR_MCE_KILL_DEFAULT                 = 2,
92 
93     PR_MCE_KILL_GET                     = 34,
94 
95     PR_SET_MM                           = 35,
96     PR_SET_MM_START_CODE                = 1,
97     PR_SET_MM_END_CODE                  = 2,
98     PR_SET_MM_START_DATA                = 3,
99     PR_SET_MM_END_DATA                  = 4,
100     PR_SET_MM_START_STACK               = 5,
101     PR_SET_MM_START_BRK                 = 6,
102     PR_SET_MM_BRK                       = 7,
103     PR_SET_MM_ARG_START                 = 8,
104     PR_SET_MM_ARG_END                   = 9,
105     PR_SET_MM_ENV_START                 = 10,
106     PR_SET_MM_ENV_END                   = 11,
107     PR_SET_MM_AUXV                      = 12,
108     PR_SET_MM_EXE_FILE                  = 13,
109     PR_SET_MM_MAP                       = 14,
110     PR_SET_MM_MAP_SIZE                  = 15,
111 
112     PR_SET_PTRACER                      = 0x59616d61,
113     PR_SET_PTRACER_ANY                  = (cast (uint)-1),
114 
115     PR_SET_CHILD_SUBREAPER              = 36,
116     PR_GET_CHILD_SUBREAPER              = 37,
117 
118     PR_SET_NO_NEW_PRIVS                 = 38,
119     PR_GET_NO_NEW_PRIVS                 = 39,
120 
121     PR_GET_TID_ADDRESS                  = 40,
122 
123     PR_SET_THP_DISABLE                  = 41,
124     PR_GET_THP_DISABLE                  = 42,
125 }
126 
127 struct prctl_mm_map
128 {
129     ulong    start_code;
130     ulong    end_code;
131     ulong    start_data;
132     ulong    end_data;
133     ulong    start_brk;
134     ulong    brk;
135     ulong    start_stack;
136     ulong    arg_start;
137     ulong    arg_end;
138     ulong    env_start;
139     ulong    env_end;
140     ulong*   auxv;
141     uint     auxv_size;
142     uint     exe_fd;
143 }
144 
145 int prctl(int option, size_t arg2, size_t arg3, size_t arg4, size_t arg5);
146 
147 //
148 // Example usage to set and get the task name.
149 //
150 // byte[16] oldname = cast(byte[]) "1234567890123456";
151 // oldname[oldname.length-1] = 0;
152 // prctl(PR_SET_NAME, cast(size_t) oldname.ptr, cast(size_t) null, cast(size_t) null, cast(size_t) null);
153 // byte[16] newname;
154 // prctl(PR_GET_NAME, cast(size_t) newname.ptr, cast(size_t) null, cast(size_t) null, cast(size_t) null);
155 // int i;
156 // foreach (b; newname)
157 // {
158 //         assert(b == oldname[i]);
159 //             i++;
160 // }
161 // writeln(cast(string) newname);