diff --git a/rules/locale/ir_unsafe.json b/rules/locale/ir_unsafe.json new file mode 100644 index 0000000..09a799e --- /dev/null +++ b/rules/locale/ir_unsafe.json @@ -0,0 +1,40 @@ +{ + "f1": { + "body": [ + { + "text": "libc::setlocale(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": " as *const i8) as *mut u8" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "*const u8", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "*mut u8", + "is_unsafe_pointer": true + } + } +} diff --git a/rules/locale/src.cpp b/rules/locale/src.cpp new file mode 100644 index 0000000..188a39e --- /dev/null +++ b/rules/locale/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 + +char *f1(int category, const char *locale) { + return setlocale(category, locale); +} diff --git a/rules/locale/tgt_unsafe.rs b/rules/locale/tgt_unsafe.rs new file mode 100644 index 0000000..53d2d1a --- /dev/null +++ b/rules/locale/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: i32, a1: *const u8) -> *mut u8 { + libc::setlocale(a0, a1 as *const i8) as *mut u8 +} diff --git a/rules/netdb/ir_unsafe.json b/rules/netdb/ir_unsafe.json new file mode 100644 index 0000000..8b4897a --- /dev/null +++ b/rules/netdb/ir_unsafe.json @@ -0,0 +1,88 @@ +{ + "f1": { + "body": [ + { + "text": "libc::getaddrinfo(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": " as *const i8, " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": " as *const i8, " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 3, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "*const u8", + "is_unsafe_pointer": true + }, + "a1": { + "type": "*const u8", + "is_unsafe_pointer": true + }, + "a2": { + "type": "*const ::libc::addrinfo", + "is_unsafe_pointer": true + }, + "a3": { + "type": "*mut *mut ::libc::addrinfo", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + }, + "f2": { + "body": [ + { + "text": "libc::freeaddrinfo(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "*mut ::libc::addrinfo", + "is_unsafe_pointer": true + } + } + } +} diff --git a/rules/netdb/src.cpp b/rules/netdb/src.cpp new file mode 100644 index 0000000..be8e42c --- /dev/null +++ b/rules/netdb/src.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int f1(const char *node, const char *service, const struct addrinfo *hints, + struct addrinfo **res) { + return getaddrinfo(node, service, hints, res); +} + +void f2(struct addrinfo *res) { return freeaddrinfo(res); } diff --git a/rules/netdb/tgt_unsafe.rs b/rules/netdb/tgt_unsafe.rs new file mode 100644 index 0000000..6e40b3d --- /dev/null +++ b/rules/netdb/tgt_unsafe.rs @@ -0,0 +1,15 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +unsafe fn f1( + a0: *const u8, + a1: *const u8, + a2: *const ::libc::addrinfo, + a3: *mut *mut ::libc::addrinfo, +) -> i32 { + libc::getaddrinfo(a0 as *const i8, a1 as *const i8, a2, a3) +} + +unsafe fn f2(a0: *mut ::libc::addrinfo) { + libc::freeaddrinfo(a0) +} diff --git a/rules/pwd/ir_unsafe.json b/rules/pwd/ir_unsafe.json new file mode 100644 index 0000000..9350198 --- /dev/null +++ b/rules/pwd/ir_unsafe.json @@ -0,0 +1,27 @@ +{ + "f1": { + "body": [ + { + "text": "libc::getpwuid(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "u32" + } + }, + "return_type": { + "type": "*mut ::libc::passwd", + "is_unsafe_pointer": true + } + } +} diff --git a/rules/pwd/src.cpp b/rules/pwd/src.cpp new file mode 100644 index 0000000..5836bac --- /dev/null +++ b/rules/pwd/src.cpp @@ -0,0 +1,6 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +struct passwd *f1(uid_t uid) { return getpwuid(uid); } diff --git a/rules/pwd/tgt_unsafe.rs b/rules/pwd/tgt_unsafe.rs new file mode 100644 index 0000000..275499a --- /dev/null +++ b/rules/pwd/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: u32) -> *mut ::libc::passwd { + libc::getpwuid(a0) +} diff --git a/rules/signal/ir_unsafe.json b/rules/signal/ir_unsafe.json new file mode 100644 index 0000000..5b2436f --- /dev/null +++ b/rules/signal/ir_unsafe.json @@ -0,0 +1,52 @@ +{ + "f1": { + "body": [ + { + "text": "libc::sigaction(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 2, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "*const ::libc::sigaction", + "is_unsafe_pointer": true + }, + "a2": { + "type": "*mut ::libc::sigaction", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + } +} diff --git a/rules/signal/src.cpp b/rules/signal/src.cpp new file mode 100644 index 0000000..9ff7721 --- /dev/null +++ b/rules/signal/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(int signum, const struct sigaction *act, struct sigaction *oldact) { + return sigaction(signum, act, oldact); +} diff --git a/rules/signal/tgt_unsafe.rs b/rules/signal/tgt_unsafe.rs new file mode 100644 index 0000000..dfa56f8 --- /dev/null +++ b/rules/signal/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: i32, a1: *const ::libc::sigaction, a2: *mut ::libc::sigaction) -> i32 { + libc::sigaction(a0, a1, a2) +} diff --git a/rules/src/modules.rs b/rules/src/modules.rs index 8faa0a0..b04c66f 100644 --- a/rules/src/modules.rs +++ b/rules/src/modules.rs @@ -52,20 +52,28 @@ pub mod iostream_tgt_unsafe; pub mod ip_tgt_unsafe; #[path = r#"../limits/tgt_unsafe.rs"#] pub mod limits_tgt_unsafe; +#[path = r#"../locale/tgt_unsafe.rs"#] +pub mod locale_tgt_unsafe; #[path = r#"../map/tgt_refcount.rs"#] pub mod map_tgt_refcount; #[path = r#"../map/tgt_unsafe.rs"#] pub mod map_tgt_unsafe; #[path = r#"../math/tgt_unsafe.rs"#] pub mod math_tgt_unsafe; +#[path = r#"../netdb/tgt_unsafe.rs"#] +pub mod netdb_tgt_unsafe; #[path = r#"../pair/tgt_refcount.rs"#] 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#"../pwd/tgt_unsafe.rs"#] +pub mod pwd_tgt_unsafe; #[path = r#"../select/tgt_unsafe.rs"#] pub mod select_tgt_unsafe; +#[path = r#"../signal/tgt_unsafe.rs"#] +pub mod signal_tgt_unsafe; #[path = r#"../socket/tgt_unsafe.rs"#] pub mod socket_tgt_unsafe; #[path = r#"../stat/tgt_unsafe.rs"#] @@ -78,6 +86,8 @@ pub mod stdio_tgt_unsafe; pub mod string_tgt_refcount; #[path = r#"../string/tgt_unsafe.rs"#] pub mod string_tgt_unsafe; +#[path = r#"../termios/tgt_unsafe.rs"#] +pub mod termios_tgt_unsafe; #[path = r#"../unique_ptr/tgt_refcount.rs"#] pub mod unique_ptr_tgt_refcount; #[path = r#"../unique_ptr/tgt_unsafe.rs"#] diff --git a/rules/termios/ir_unsafe.json b/rules/termios/ir_unsafe.json new file mode 100644 index 0000000..8a24240 --- /dev/null +++ b/rules/termios/ir_unsafe.json @@ -0,0 +1,88 @@ +{ + "f1": { + "body": [ + { + "text": "libc::tcsetattr(" + }, + { + "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": "*const ::libc::termios", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + }, + "f2": { + "body": [ + { + "text": "libc::tcgetattr(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ", " + }, + { + "placeholder": { + "arg": 1, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "i32" + }, + "a1": { + "type": "*mut ::libc::termios", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "i32" + } + } +} diff --git a/rules/termios/src.cpp b/rules/termios/src.cpp new file mode 100644 index 0000000..32f014b --- /dev/null +++ b/rules/termios/src.cpp @@ -0,0 +1,10 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int f1(int fd, int optional_actions, const struct termios *termios_p) { + return tcsetattr(fd, optional_actions, termios_p); +} + +int f2(int fd, struct termios *termios_p) { return tcgetattr(fd, termios_p); } diff --git a/rules/termios/tgt_unsafe.rs b/rules/termios/tgt_unsafe.rs new file mode 100644 index 0000000..1d40338 --- /dev/null +++ b/rules/termios/tgt_unsafe.rs @@ -0,0 +1,10 @@ +// 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: i32, a2: *const ::libc::termios) -> i32 { + libc::tcsetattr(a0, a1, a2) +} + +unsafe fn f2(a0: i32, a1: *mut ::libc::termios) -> i32 { + libc::tcgetattr(a0, a1) +}