Skip to content

Commit 5b42028

Browse files
committed
Add more rules
1 parent bb191b7 commit 5b42028

11 files changed

Lines changed: 109 additions & 0 deletions

File tree

rules/dirent/src.cpp

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+
#include <dirent.h>
5+
6+
using t1 = DIR *;
7+
8+
DIR *f1(const char *name) { return opendir(name); }
9+
10+
struct dirent *f2(DIR *dirp) { return readdir(dirp); }
11+
12+
int f3(DIR *dirp) { return closedir(dirp); }

rules/dirent/tgt_unsafe.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
fn types() -> Result<(), Box<dyn std::error::Error>> {
5+
let t1: *mut ::libc::DIR = std::ptr::null_mut();
6+
Ok(())
7+
}
8+
9+
unsafe fn f1(a0: *const u8) -> *mut ::libc::DIR {
10+
libc::opendir(a0 as *const i8)
11+
}
12+
13+
unsafe fn f2(a0: *mut ::libc::DIR) -> *mut ::libc::dirent {
14+
libc::readdir(a0)
15+
}
16+
17+
unsafe fn f3(a0: *mut ::libc::DIR) -> i32 {
18+
libc::closedir(a0)
19+
}

rules/fnmatch/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 <fnmatch.h>
5+
6+
int f1(const char *pattern, const char *string, int flags) {
7+
return fnmatch(pattern, string, flags);
8+
}

rules/fnmatch/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: *const u8, a1: *const u8, a2: i32) -> i32 {
5+
libc::fnmatch(a0 as *const i8, a1 as *const i8, a2)
6+
}

rules/net_if/src.cpp

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+
#include <net/if.h>
5+
6+
unsigned int f1(const char *ifname) { return if_nametoindex(ifname); }

rules/net_if/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: *const u8) -> u32 {
5+
libc::if_nametoindex(a0 as *const i8)
6+
}

rules/socket/src.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,17 @@ int f15(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
6969
int f16(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
7070
return bind(sockfd, addr, addrlen);
7171
}
72+
73+
int f17(int sockfd, int backlog) {
74+
return listen(sockfd, backlog);
75+
}
76+
77+
ssize_t f18(int sockfd, void *buf, size_t len, int flags,
78+
struct sockaddr *src_addr, socklen_t *addrlen) {
79+
return recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
80+
}
81+
82+
ssize_t f19(int sockfd, const void *buf, size_t len, int flags,
83+
const struct sockaddr *dest_addr, socklen_t addrlen) {
84+
return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
85+
}

rules/socket/tgt_unsafe.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,29 @@ unsafe fn f15(a0: i32, a1: *mut ::libc::sockaddr, a2: *mut u32, a3: i32) -> i32
6464
unsafe fn f16(a0: i32, a1: *const ::libc::sockaddr, a2: u32) -> i32 {
6565
libc::bind(a0, a1, a2)
6666
}
67+
68+
unsafe fn f17(a0: i32, a1: i32) -> i32 {
69+
libc::listen(a0, a1)
70+
}
71+
72+
unsafe fn f18(
73+
a0: i32,
74+
a1: *mut ::libc::c_void,
75+
a2: u64,
76+
a3: i32,
77+
a4: *mut ::libc::sockaddr,
78+
a5: *mut u32,
79+
) -> i64 {
80+
libc::recvfrom(a0, a1, a2 as usize, a3, a4, a5) as i64
81+
}
82+
83+
unsafe fn f19(
84+
a0: i32,
85+
a1: *const ::libc::c_void,
86+
a2: u64,
87+
a3: i32,
88+
a4: *const ::libc::sockaddr,
89+
a5: u32,
90+
) -> i64 {
91+
libc::sendto(a0, a1, a2 as usize, a3, a4, a5) as i64
92+
}

rules/src/modules.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ pub mod cstring_tgt_unsafe;
3636
pub mod deque_tgt_refcount;
3737
#[path = r#"../deque/tgt_unsafe.rs"#]
3838
pub mod deque_tgt_unsafe;
39+
#[path = r#"../dirent/tgt_unsafe.rs"#]
40+
pub mod dirent_tgt_unsafe;
3941
#[path = r#"../errno/tgt_unsafe.rs"#]
4042
pub mod errno_tgt_unsafe;
43+
#[path = r#"../fnmatch/tgt_unsafe.rs"#]
44+
pub mod fnmatch_tgt_unsafe;
4145
#[path = r#"../fstream/tgt_refcount.rs"#]
4246
pub mod fstream_tgt_refcount;
4347
#[path = r#"../fstream/tgt_unsafe.rs"#]
@@ -64,6 +68,8 @@ pub mod map_tgt_refcount;
6468
pub mod map_tgt_unsafe;
6569
#[path = r#"../math/tgt_unsafe.rs"#]
6670
pub mod math_tgt_unsafe;
71+
#[path = r#"../net_if/tgt_unsafe.rs"#]
72+
pub mod net_if_tgt_unsafe;
6773
#[path = r#"../netdb/tgt_unsafe.rs"#]
6874
pub mod netdb_tgt_unsafe;
6975
#[path = r#"../pair/tgt_refcount.rs"#]

rules/stdio/src.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ FILE *f20(int fd, const char *mode) { return fdopen(fd, mode); }
6060
int f22(const char *a0, const char *a1) {
6161
return rename(a0, a1);
6262
}
63+
64+
int f23(FILE *stream) { return getc(stream); }

0 commit comments

Comments
 (0)