Skip to content

Commit 24c1c62

Browse files
authored
[unsafe] Add unistd rules (#127)
1 parent d230164 commit 24c1c62

8 files changed

Lines changed: 1074 additions & 2 deletions

File tree

rules/src/modules.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub mod string_tgt_unsafe;
7676
pub mod unique_ptr_tgt_refcount;
7777
#[path = r#"../unique_ptr/tgt_unsafe.rs"#]
7878
pub mod unique_ptr_tgt_unsafe;
79+
#[path = r#"../unistd/tgt_unsafe.rs"#]
80+
pub mod unistd_tgt_unsafe;
7981
#[path = r#"../vector/tgt_refcount.rs"#]
8082
pub mod vector_tgt_refcount;
8183
#[path = r#"../vector/tgt_unsafe.rs"#]

rules/unistd/ir_unsafe.json

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::close("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ")"
15+
}
16+
],
17+
"params": {
18+
"a0": {
19+
"type": "i32"
20+
}
21+
},
22+
"return_type": {
23+
"type": "i32"
24+
}
25+
},
26+
"f10": {
27+
"body": [
28+
{
29+
"text": "libc::write("
30+
},
31+
{
32+
"placeholder": {
33+
"arg": 0,
34+
"access": "read"
35+
}
36+
},
37+
{
38+
"text": ", "
39+
},
40+
{
41+
"placeholder": {
42+
"arg": 1,
43+
"access": "read"
44+
}
45+
},
46+
{
47+
"text": ", "
48+
},
49+
{
50+
"placeholder": {
51+
"arg": 2,
52+
"access": "read"
53+
}
54+
},
55+
{
56+
"text": " as usize) as i64"
57+
}
58+
],
59+
"params": {
60+
"a0": {
61+
"type": "i32"
62+
},
63+
"a1": {
64+
"type": "*const ::libc::c_void",
65+
"is_unsafe_pointer": true
66+
},
67+
"a2": {
68+
"type": "u64"
69+
}
70+
},
71+
"return_type": {
72+
"type": "i64"
73+
}
74+
},
75+
"f11": {
76+
"body": [
77+
{
78+
"text": "libc::rmdir("
79+
},
80+
{
81+
"placeholder": {
82+
"arg": 0,
83+
"access": "read"
84+
}
85+
},
86+
{
87+
"text": " as *const i8)"
88+
}
89+
],
90+
"params": {
91+
"a0": {
92+
"type": "*const u8",
93+
"is_unsafe_pointer": true
94+
}
95+
},
96+
"return_type": {
97+
"type": "i32"
98+
}
99+
},
100+
"f2": {
101+
"body": [
102+
{
103+
"text": "libc::lseek("
104+
},
105+
{
106+
"placeholder": {
107+
"arg": 0,
108+
"access": "read"
109+
}
110+
},
111+
{
112+
"text": ", "
113+
},
114+
{
115+
"placeholder": {
116+
"arg": 1,
117+
"access": "read"
118+
}
119+
},
120+
{
121+
"text": ", "
122+
},
123+
{
124+
"placeholder": {
125+
"arg": 2,
126+
"access": "read"
127+
}
128+
},
129+
{
130+
"text": ")"
131+
}
132+
],
133+
"params": {
134+
"a0": {
135+
"type": "i32"
136+
},
137+
"a1": {
138+
"type": "i64"
139+
},
140+
"a2": {
141+
"type": "i32"
142+
}
143+
},
144+
"return_type": {
145+
"type": "i64"
146+
}
147+
},
148+
"f3": {
149+
"body": [
150+
{
151+
"text": "libc::read("
152+
},
153+
{
154+
"placeholder": {
155+
"arg": 0,
156+
"access": "read"
157+
}
158+
},
159+
{
160+
"text": ", "
161+
},
162+
{
163+
"placeholder": {
164+
"arg": 1,
165+
"access": "read"
166+
}
167+
},
168+
{
169+
"text": ", "
170+
},
171+
{
172+
"placeholder": {
173+
"arg": 2,
174+
"access": "read"
175+
}
176+
},
177+
{
178+
"text": " as usize) as i64"
179+
}
180+
],
181+
"params": {
182+
"a0": {
183+
"type": "i32"
184+
},
185+
"a1": {
186+
"type": "*mut ::libc::c_void",
187+
"is_unsafe_pointer": true
188+
},
189+
"a2": {
190+
"type": "u64"
191+
}
192+
},
193+
"return_type": {
194+
"type": "i64"
195+
}
196+
},
197+
"f4": {
198+
"body": [
199+
{
200+
"text": "libc::unlink("
201+
},
202+
{
203+
"placeholder": {
204+
"arg": 0,
205+
"access": "read"
206+
}
207+
},
208+
{
209+
"text": " as *const i8)"
210+
}
211+
],
212+
"params": {
213+
"a0": {
214+
"type": "*const u8",
215+
"is_unsafe_pointer": true
216+
}
217+
},
218+
"return_type": {
219+
"type": "i32"
220+
}
221+
},
222+
"f5": {
223+
"body": [
224+
{
225+
"text": "libc::pipe("
226+
},
227+
{
228+
"placeholder": {
229+
"arg": 0,
230+
"access": "read"
231+
}
232+
},
233+
{
234+
"text": ")"
235+
}
236+
],
237+
"params": {
238+
"a0": {
239+
"type": "*mut i32",
240+
"is_unsafe_pointer": true
241+
}
242+
},
243+
"return_type": {
244+
"type": "i32"
245+
}
246+
},
247+
"f6": {
248+
"body": [
249+
{
250+
"text": "libc::ftruncate("
251+
},
252+
{
253+
"placeholder": {
254+
"arg": 0,
255+
"access": "read"
256+
}
257+
},
258+
{
259+
"text": ", "
260+
},
261+
{
262+
"placeholder": {
263+
"arg": 1,
264+
"access": "read"
265+
}
266+
},
267+
{
268+
"text": ")"
269+
}
270+
],
271+
"params": {
272+
"a0": {
273+
"type": "i32"
274+
},
275+
"a1": {
276+
"type": "i64"
277+
}
278+
},
279+
"return_type": {
280+
"type": "i32"
281+
}
282+
},
283+
"f7": {
284+
"body": [
285+
{
286+
"text": "libc::isatty("
287+
},
288+
{
289+
"placeholder": {
290+
"arg": 0,
291+
"access": "read"
292+
}
293+
},
294+
{
295+
"text": ")"
296+
}
297+
],
298+
"params": {
299+
"a0": {
300+
"type": "i32"
301+
}
302+
},
303+
"return_type": {
304+
"type": "i32"
305+
}
306+
},
307+
"f8": {
308+
"body": [
309+
{
310+
"text": "libc::geteuid()"
311+
}
312+
],
313+
"return_type": {
314+
"type": "u32"
315+
}
316+
},
317+
"f9": {
318+
"body": [
319+
{
320+
"text": "libc::gethostname("
321+
},
322+
{
323+
"placeholder": {
324+
"arg": 0,
325+
"access": "read"
326+
}
327+
},
328+
{
329+
"text": " as *mut i8, "
330+
},
331+
{
332+
"placeholder": {
333+
"arg": 1,
334+
"access": "read"
335+
}
336+
},
337+
{
338+
"text": " as usize)"
339+
}
340+
],
341+
"params": {
342+
"a0": {
343+
"type": "*mut u8",
344+
"is_unsafe_pointer": true
345+
},
346+
"a1": {
347+
"type": "u64"
348+
}
349+
},
350+
"return_type": {
351+
"type": "i32"
352+
}
353+
}
354+
}

rules/unistd/src.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <unistd.h>
5+
6+
int f1(int fd) { return close(fd); }
7+
8+
off_t f2(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); }
9+
10+
ssize_t f3(int fd, void *buf, size_t count) { return read(fd, buf, count); }
11+
12+
int f4(const char *pathname) { return unlink(pathname); }
13+
14+
int f5(int pipefd[2]) { return pipe(pipefd); }
15+
16+
int f6(int fd, off_t length) { return ftruncate(fd, length); }
17+
18+
int f7(int fd) { return isatty(fd); }
19+
20+
uid_t f8(void) { return geteuid(); }
21+
22+
int f9(char *name, size_t len) { return gethostname(name, len); }
23+
24+
ssize_t f10(int fd, const void *buf, size_t count) {
25+
return write(fd, buf, count);
26+
}
27+
28+
int f11(const char *pathname) { return rmdir(pathname); }

0 commit comments

Comments
 (0)