Skip to content

Commit db023f2

Browse files
authored
[unsafe] Rules for poll/select/socket (#133)
1 parent 7a29f51 commit db023f2

10 files changed

Lines changed: 594 additions & 0 deletions

File tree

rules/poll/ir_unsafe.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::poll("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ", "
15+
},
16+
{
17+
"placeholder": {
18+
"arg": 1,
19+
"access": "read"
20+
}
21+
},
22+
{
23+
"text": " as ::libc::nfds_t, "
24+
},
25+
{
26+
"placeholder": {
27+
"arg": 2,
28+
"access": "read"
29+
}
30+
},
31+
{
32+
"text": ")"
33+
}
34+
],
35+
"params": {
36+
"a0": {
37+
"type": "*mut ::libc::pollfd",
38+
"is_unsafe_pointer": true
39+
},
40+
"a1": {
41+
"type": "u64"
42+
},
43+
"a2": {
44+
"type": "i32"
45+
}
46+
},
47+
"return_type": {
48+
"type": "i32"
49+
}
50+
}
51+
}

rules/poll/src.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <poll.h>
5+
6+
int f1(struct pollfd *fds, nfds_t nfds, int timeout) {
7+
return poll(fds, nfds, timeout);
8+
}

rules/poll/tgt_unsafe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1(a0: *mut ::libc::pollfd, a1: u64, a2: i32) -> i32 {
5+
libc::poll(a0, a1 as ::libc::nfds_t, a2)
6+
}

rules/select/ir_unsafe.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"f1": {
3+
"body": [
4+
{
5+
"text": "libc::select("
6+
},
7+
{
8+
"placeholder": {
9+
"arg": 0,
10+
"access": "read"
11+
}
12+
},
13+
{
14+
"text": ", "
15+
},
16+
{
17+
"placeholder": {
18+
"arg": 1,
19+
"access": "read"
20+
}
21+
},
22+
{
23+
"text": ", "
24+
},
25+
{
26+
"placeholder": {
27+
"arg": 2,
28+
"access": "read"
29+
}
30+
},
31+
{
32+
"text": ", "
33+
},
34+
{
35+
"placeholder": {
36+
"arg": 3,
37+
"access": "read"
38+
}
39+
},
40+
{
41+
"text": ", "
42+
},
43+
{
44+
"placeholder": {
45+
"arg": 4,
46+
"access": "read"
47+
}
48+
},
49+
{
50+
"text": ")"
51+
}
52+
],
53+
"params": {
54+
"a0": {
55+
"type": "i32"
56+
},
57+
"a1": {
58+
"type": "*mut ::libc::fd_set",
59+
"is_unsafe_pointer": true
60+
},
61+
"a2": {
62+
"type": "*mut ::libc::fd_set",
63+
"is_unsafe_pointer": true
64+
},
65+
"a3": {
66+
"type": "*mut ::libc::fd_set",
67+
"is_unsafe_pointer": true
68+
},
69+
"a4": {
70+
"type": "*mut ::libc::timeval",
71+
"is_unsafe_pointer": true
72+
}
73+
},
74+
"return_type": {
75+
"type": "i32"
76+
}
77+
}
78+
}

rules/select/src.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <sys/select.h>
5+
6+
int f1(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
7+
struct timeval *timeout) {
8+
return select(nfds, readfds, writefds, exceptfds, timeout);
9+
}

rules/select/tgt_unsafe.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1(
5+
a0: i32,
6+
a1: *mut ::libc::fd_set,
7+
a2: *mut ::libc::fd_set,
8+
a3: *mut ::libc::fd_set,
9+
a4: *mut ::libc::timeval,
10+
) -> i32 {
11+
libc::select(a0, a1, a2, a3, a4)
12+
}

0 commit comments

Comments
 (0)