diff --git a/rules/poll/ir_unsafe.json b/rules/poll/ir_unsafe.json new file mode 100644 index 00000000..121c8fce --- /dev/null +++ b/rules/poll/ir_unsafe.json @@ -0,0 +1,51 @@ +{ + "f1": { + "body": [ + { + "text": "libc::poll(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": " as ::libc::nfds_t, " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "*mut ::libc::pollfd", + "is_unsafe_pointer": true + }, + "a1": { + "type": "u64" + }, + "a2": { + "type": "i32" + } + }, + "return_type": { + "type": "i32" + } + } +} diff --git a/rules/poll/src.cpp b/rules/poll/src.cpp new file mode 100644 index 00000000..06deebd6 --- /dev/null +++ b/rules/poll/src.cpp @@ -0,0 +1,8 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int f1(struct pollfd *fds, nfds_t nfds, int timeout) { + return poll(fds, nfds, timeout); +} diff --git a/rules/poll/tgt_unsafe.rs b/rules/poll/tgt_unsafe.rs new file mode 100644 index 00000000..34ded1fd --- /dev/null +++ b/rules/poll/tgt_unsafe.rs @@ -0,0 +1,6 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +unsafe fn f1(a0: *mut ::libc::pollfd, a1: u64, a2: i32) -> i32 { + libc::poll(a0, a1 as ::libc::nfds_t, a2) +} diff --git a/rules/select/ir_unsafe.json b/rules/select/ir_unsafe.json new file mode 100644 index 00000000..23b58098 --- /dev/null +++ b/rules/select/ir_unsafe.json @@ -0,0 +1,78 @@ +{ + "f1": { + "body": [ + { + "text": "libc::select(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 4, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "*mut ::libc::fd_set", + "is_unsafe_pointer": true + }, + "a2": { + "type": "*mut ::libc::fd_set", + "is_unsafe_pointer": true + }, + "a3": { + "type": "*mut ::libc::fd_set", + "is_unsafe_pointer": true + }, + "a4": { + "type": "*mut ::libc::timeval", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + } +} diff --git a/rules/select/src.cpp b/rules/select/src.cpp new file mode 100644 index 00000000..6994faec --- /dev/null +++ b/rules/select/src.cpp @@ -0,0 +1,9 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int f1(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) { + return select(nfds, readfds, writefds, exceptfds, timeout); +} diff --git a/rules/select/tgt_unsafe.rs b/rules/select/tgt_unsafe.rs new file mode 100644 index 00000000..b7580f28 --- /dev/null +++ b/rules/select/tgt_unsafe.rs @@ -0,0 +1,12 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +unsafe fn f1( + a0: i32, + a1: *mut ::libc::fd_set, + a2: *mut ::libc::fd_set, + a3: *mut ::libc::fd_set, + a4: *mut ::libc::timeval, +) -> i32 { + libc::select(a0, a1, a2, a3, a4) +} diff --git a/rules/socket/ir_unsafe.json b/rules/socket/ir_unsafe.json index c37b5314..d5af4452 100644 --- a/rules/socket/ir_unsafe.json +++ b/rules/socket/ir_unsafe.json @@ -9,6 +9,128 @@ "type": "i32" } }, + "f10": { + "body": [ + { + "text": "libc::send(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": " as usize, " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ") as i64" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "*const ::libc::c_void", + "is_unsafe_pointer": true + }, + "a2": { + "type": "u64" + }, + "a3": { + "type": "i32" + } + }, + "return_type": { + "type": "i64" + } + }, + "f11": { + "body": [ + { + "text": "libc::socketpair(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "i32" + }, + "a2": { + "type": "i32" + }, + "a3": { + "type": "*mut i32", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + }, "f2": { "body": [ { @@ -50,5 +172,261 @@ "type": "i32" }, "target_os": "linux" + }, + "f6": { + "body": [ + { + "text": "libc::socket(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "i32" + }, + "a2": { + "type": "i32" + } + }, + "return_type": { + "type": "i32" + } + }, + "f7": { + "body": [ + { + "text": "libc::setsockopt(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 4, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "i32" + }, + "a2": { + "type": "i32" + }, + "a3": { + "type": "*const ::libc::c_void", + "is_unsafe_pointer": true + }, + "a4": { + "type": "u32" + } + }, + "return_type": { + "type": "i32" + } + }, + "f8": { + "body": [ + { + "text": "libc::getsockopt(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 4, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "i32" + }, + "a2": { + "type": "i32" + }, + "a3": { + "type": "*mut ::libc::c_void", + "is_unsafe_pointer": true + }, + "a4": { + "type": "*mut u32", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + }, + "f9": { + "body": [ + { + "text": "libc::recv(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": " as usize, " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ") as i64" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "*mut ::libc::c_void", + "is_unsafe_pointer": true + }, + "a2": { + "type": "u64" + }, + "a3": { + "type": "i32" + } + }, + "return_type": { + "type": "i64" + } } } diff --git a/rules/socket/src.cpp b/rules/socket/src.cpp index b49b50d4..3a511c15 100644 --- a/rules/socket/src.cpp +++ b/rules/socket/src.cpp @@ -22,3 +22,27 @@ int f5() { return SOCK_NONBLOCK; } #endif + +int f6(int domain, int type, int protocol) { + return socket(domain, type, protocol); +} + +int f7(int sockfd, int level, int optname, const void *optval, socklen_t optlen) { + return setsockopt(sockfd, level, optname, optval, optlen); +} + +int f8(int sockfd, int level, int optname, void *optval, socklen_t *optlen) { + return getsockopt(sockfd, level, optname, optval, optlen); +} + +ssize_t f9(int sockfd, void *buf, size_t len, int flags) { + return recv(sockfd, buf, len, flags); +} + +ssize_t f10(int sockfd, const void *buf, size_t len, int flags) { + return send(sockfd, buf, len, flags); +} + +int f11(int domain, int type, int protocol, int sv[2]) { + return socketpair(domain, type, protocol, sv); +} diff --git a/rules/socket/tgt_unsafe.rs b/rules/socket/tgt_unsafe.rs index f39b4c40..d07d4b2b 100644 --- a/rules/socket/tgt_unsafe.rs +++ b/rules/socket/tgt_unsafe.rs @@ -19,3 +19,27 @@ unsafe fn f4() -> i32 { unsafe fn f5() -> i32 { libc::SOCK_NONBLOCK } + +unsafe fn f6(a0: i32, a1: i32, a2: i32) -> i32 { + libc::socket(a0, a1, a2) +} + +unsafe fn f7(a0: i32, a1: i32, a2: i32, a3: *const ::libc::c_void, a4: u32) -> i32 { + libc::setsockopt(a0, a1, a2, a3, a4) +} + +unsafe fn f8(a0: i32, a1: i32, a2: i32, a3: *mut ::libc::c_void, a4: *mut u32) -> i32 { + libc::getsockopt(a0, a1, a2, a3, a4) +} + +unsafe fn f9(a0: i32, a1: *mut ::libc::c_void, a2: u64, a3: i32) -> i64 { + libc::recv(a0, a1, a2 as usize, a3) as i64 +} + +unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: u64, a3: i32) -> i64 { + libc::send(a0, a1, a2 as usize, a3) as i64 +} + +unsafe fn f11(a0: i32, a1: i32, a2: i32, a3: *mut i32) -> i32 { + libc::socketpair(a0, a1, a2, a3) +} diff --git a/rules/src/modules.rs b/rules/src/modules.rs index 9920f884..b2a3b83d 100644 --- a/rules/src/modules.rs +++ b/rules/src/modules.rs @@ -62,6 +62,10 @@ pub mod math_tgt_unsafe; pub mod pair_tgt_refcount; #[path = r#"../pair/tgt_unsafe.rs"#] pub mod pair_tgt_unsafe; +#[path = r#"../poll/tgt_unsafe.rs"#] +pub mod poll_tgt_unsafe; +#[path = r#"../select/tgt_unsafe.rs"#] +pub mod select_tgt_unsafe; #[path = r#"../socket/tgt_unsafe.rs"#] pub mod socket_tgt_unsafe; #[path = r#"../stdio/tgt_refcount.rs"#]