Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc-dep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2024"

[dependencies]
libc = "0.2"
nix = { version = "0.30", features = ["socket", "net", "fs", "poll", "time", "user", "dir", "term", "event", "hostname"] }
1 change: 1 addition & 0 deletions libcc2rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2024"
[dependencies]
libcc2rs-macros = { path = "../libcc2rs-macros", version = "0.1.0" }
libc = "0.2"
nix = { version = "0.30", features = ["socket", "net", "fs", "poll", "time", "user", "dir", "term", "event", "hostname"] }
2 changes: 1 addition & 1 deletion rule-preprocessor/src/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn build_rustc_args(crate_root: &Path) -> Vec<String> {
args.push("-L".to_string());
args.push(format!("dependency={}", deps.display()));

for dep in &["libcc2rs", "libc", "brotli_sys", "rustls_ffi"] {
for dep in &["libcc2rs", "libc", "brotli_sys", "rustls_ffi", "nix"] {
if let Some(rlib) = find_rlib(deps.as_path(), dep) {
args.push("--extern".to_string());
args.push(format!("{}={}", dep, rlib.display()));
Expand Down
1 change: 1 addition & 0 deletions rules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ libc = "0.2.148"
libcc2rs = { version = "0.1.0", path = "../libcc2rs" }
brotli-sys = "0.3"
rustls-ffi = { version = "0.15.3", default-features = false }
nix = { version = "0.30", features = ["socket", "net", "fs", "poll", "time", "user", "dir", "term", "event", "hostname"] }
2 changes: 2 additions & 0 deletions rules/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ pub mod time_tgt_unsafe;
pub mod unique_ptr_tgt_refcount;
#[path = r#"../unique_ptr/tgt_unsafe.rs"#]
pub mod unique_ptr_tgt_unsafe;
#[path = r#"../unistd/tgt_refcount.rs"#]
pub mod unistd_tgt_refcount;
#[path = r#"../unistd/tgt_unsafe.rs"#]
pub mod unistd_tgt_unsafe;
#[path = r#"../vector/tgt_refcount.rs"#]
Expand Down
50 changes: 50 additions & 0 deletions rules/unistd/tgt_refcount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

use libcc2rs::*;

fn f4(a0: Ptr<u8>) -> i32 {
match nix::unistd::unlink(a0.to_rust_string().as_str()) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
-1
}
}
}

fn f8() -> u32 {
nix::unistd::geteuid().as_raw()
}

fn f9(a0: Ptr<u8>, a1: usize) -> i32 {
match nix::unistd::gethostname() {
Ok(__name) => {
let __bytes = __name.as_encoded_bytes();
let __n = __bytes.len().min(a1.saturating_sub(1));
let mut __dst = a0.clone();
for __b in &__bytes[..__n] {
__dst.write(*__b);
__dst += 1;
}
if a1 > 0 {
__dst.write(0);
}
0
}
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
-1
}
}
}

fn f11(a0: Ptr<u8>) -> i32 {
match ::std::fs::remove_dir(a0.to_rust_string()) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e.raw_os_error().unwrap_or(::libc::EIO));
-1
}
}
}
13 changes: 10 additions & 3 deletions tests/lit/lit/formats/Cpp2RustTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ def build_rust(self):

parent = Path(__file__).resolve().parent.parent.parent.parent.parent
cc2rs_dir = parent / "libcc2rs" / "target" / "release"
libc_dep_deps = parent / "libc-dep" / "target" / "release" / "deps"
# pick the most recently compiled libc
libc_rlib = max(
(parent / "libc-dep" / "target" / "release" / "deps").glob(
"liblibc-*.rlib"
),
libc_dep_deps.glob("liblibc-*.rlib"),
key=lambda p: p.stat().st_mtime,
)
nix_rlib = max(
libc_dep_deps.glob("libnix-*.rlib"),
key=lambda p: p.stat().st_mtime,
)
cmd = [
Expand All @@ -229,10 +232,14 @@ def build_rust(self):
str(self.tmp_dir),
"-L",
f"dependency={cc2rs_dir / 'deps'}",
"-L",
f"dependency={libc_dep_deps}",
"--extern",
f"libcc2rs={cc2rs_dir / 'liblibcc2rs.rlib'}",
"--extern",
f"libc={libc_rlib}",
"--extern",
f"nix={nix_rlib}",
]
_, err, returncode = lit.util.executeCommand(cmd, str(self.tmp_dir))
if exp.should_not_compile:
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/out/refcount/stdcopy_ostream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ fn main_0() -> i32 {
);
(*ofs.borrow_mut()).try_clone().unwrap()
};
libc::unlink((file.as_pointer() as Ptr<u8>));
match nix::unistd::unlink((file.as_pointer() as Ptr<u8>).to_rust_string().as_str()) {
Ok(()) => 0,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
-1
}
};
return 0;
}
5 changes: 0 additions & 5 deletions tests/unit/stdcopy_ostream.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

// XFAIL: refcount

#include <algorithm>
#include <fstream>
#include <iterator>
Expand Down
Loading