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
26 changes: 26 additions & 0 deletions libcc2rs/src/libc_shims/fdset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

use std::collections::BTreeSet;

#[derive(Clone, Default)]
pub struct CFdSet {
fds: BTreeSet<i32>,
}

impl crate::ByteRepr for CFdSet {}

impl CFdSet {
pub fn zero(&mut self) {
self.fds.clear();
}
pub fn set(&mut self, fd: i32) {
self.fds.insert(fd);
}
pub fn clr(&mut self, fd: i32) {
self.fds.remove(&fd);
}
pub fn isset(&self, fd: i32) -> bool {
self.fds.contains(&fd)
}
}
2 changes: 2 additions & 0 deletions libcc2rs/src/libc_shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT license that can be found in the LICENSE file.

mod dirent;
mod fdset;
mod ifaddrs;
mod ip;
mod netdb;
Expand All @@ -13,6 +14,7 @@ mod termios;
mod time;

pub use dirent::*;
pub use fdset::*;
pub use ifaddrs::*;
pub use ip::*;
pub use netdb::*;
Expand Down
24 changes: 24 additions & 0 deletions rules/select/tgt_refcount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

use libcc2rs::*;

fn t1() -> CFdSet {
Default::default()
}

fn f2(a0: i32, a1: Ptr<CFdSet>) {
a1.with_mut(|__s| __s.set(a0));
}

fn f3(a0: i32, a1: Ptr<CFdSet>) {
a1.with_mut(|__s| __s.clr(a0));
}

fn f4(a0: i32, a1: Ptr<CFdSet>) -> i32 {
if a1.with(|__s| __s.isset(a0)) { 1 } else { 0 }
}

fn f5(a0: Ptr<CFdSet>) {
a0.with_mut(|__s| __s.zero());
}
2 changes: 2 additions & 0 deletions rules/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub mod pwd_tgt_refcount;
pub mod pwd_tgt_unsafe;
#[path = r#"../rustls/tgt_unsafe.rs"#]
pub mod rustls_tgt_unsafe;
#[path = r#"../select/tgt_refcount.rs"#]
pub mod select_tgt_refcount;
#[path = r#"../select/tgt_unsafe.rs"#]
pub mod select_tgt_unsafe;
#[path = r#"../signal/tgt_unsafe.rs"#]
Expand Down
1 change: 0 additions & 1 deletion tests/unit/fd_set_macros.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// no-compile: refcount
#include <assert.h>
#include <sys/select.h>

Expand Down
41 changes: 41 additions & 0 deletions tests/unit/out/refcount/fd_set_macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
extern crate libcc2rs;
use libcc2rs::*;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::{Read, Seek, Write};
use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
pub fn main() {
std::process::exit(main_0());
}
fn main_0() -> i32 {
let set: Value<CFdSet> = Rc::new(RefCell::new(Default::default()));
(set.as_pointer()).with_mut(|__s| __s.zero());
assert!(
((!(if (set.as_pointer()).with(|__s| __s.isset(3)) {
1
} else {
0
} != 0) as i32)
!= 0)
);
(set.as_pointer()).with_mut(|__s| __s.set(3));
assert!(
(if (set.as_pointer()).with(|__s| __s.isset(3)) {
1
} else {
0
} != 0)
);
(set.as_pointer()).with_mut(|__s| __s.clr(3));
assert!(
((!(if (set.as_pointer()).with(|__s| __s.isset(3)) {
1
} else {
0
} != 0) as i32)
!= 0)
);
return 0;
}
Loading