Skip to content

Commit 229d098

Browse files
committed
Plug libc_shim in lib.rs
1 parent 358ea1b commit 229d098

25 files changed

Lines changed: 320 additions & 141 deletions

libcc2rs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub use reinterpret::ByteRepr;
77
mod rc;
88
pub use rc::*;
99

10+
mod libc_shims;
11+
pub use libc_shims::*;
12+
1013
mod fn_ptr;
1114
pub use fn_ptr::FnPtr;
1215

libcc2rs/src/libc_shims/dirent.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use crate::{ByteRepr, Value};
55
use std::cell::RefCell;
66
use std::rc::Rc;
77

8-
pub struct dirent {
8+
pub struct Dirent {
99
pub d_ino: Value<u64>,
1010
pub d_off: Value<i64>,
1111
pub d_reclen: Value<u16>,
1212
pub d_type: Value<u8>,
1313
pub d_name: Value<Box<[u8]>>,
1414
}
1515

16-
impl Default for dirent {
16+
impl Default for Dirent {
1717
fn default() -> Self {
1818
Self {
1919
d_ino: Rc::new(RefCell::new(0)),
@@ -25,7 +25,7 @@ impl Default for dirent {
2525
}
2626
}
2727

28-
impl Clone for dirent {
28+
impl Clone for Dirent {
2929
fn clone(&self) -> Self {
3030
Self {
3131
d_ino: Rc::new(RefCell::new(*self.d_ino.borrow())),
@@ -37,7 +37,7 @@ impl Clone for dirent {
3737
}
3838
}
3939

40-
impl ByteRepr for dirent {}
40+
impl ByteRepr for Dirent {}
4141

4242
pub struct CDir {
4343
pub entries: Vec<(u64, Vec<u8>, u8)>,

libcc2rs/src/libc_shims/ifaddrs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4-
use super::sockaddr;
4+
use super::Sockaddr;
55
use crate::{ByteRepr, Ptr, Value};
66
use std::cell::RefCell;
77
use std::rc::Rc;
88

9-
pub struct ifaddrs {
10-
pub ifa_next: Value<Ptr<ifaddrs>>,
9+
pub struct Ifaddrs {
10+
pub ifa_next: Value<Ptr<Ifaddrs>>,
1111
pub ifa_name: Value<Ptr<u8>>,
1212
pub ifa_flags: Value<u32>,
13-
pub ifa_addr: Value<Ptr<sockaddr>>,
14-
pub ifa_netmask: Value<Ptr<sockaddr>>,
13+
pub ifa_addr: Value<Ptr<Sockaddr>>,
14+
pub ifa_netmask: Value<Ptr<Sockaddr>>,
1515
}
1616

17-
impl Default for ifaddrs {
17+
impl Default for Ifaddrs {
1818
fn default() -> Self {
1919
Self {
2020
ifa_next: Rc::new(RefCell::new(Ptr::null())),
@@ -26,7 +26,7 @@ impl Default for ifaddrs {
2626
}
2727
}
2828

29-
impl Clone for ifaddrs {
29+
impl Clone for Ifaddrs {
3030
fn clone(&self) -> Self {
3131
Self {
3232
ifa_next: Rc::new(RefCell::new(self.ifa_next.borrow().clone())),
@@ -38,6 +38,6 @@ impl Clone for ifaddrs {
3838
}
3939
}
4040

41-
impl ByteRepr for ifaddrs {}
41+
impl ByteRepr for Ifaddrs {}
4242

4343
impl ByteRepr for ::libc::ifaddrs {}

libcc2rs/src/libc_shims/ip.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ use std::cell::RefCell;
66
use std::rc::Rc;
77

88
#[derive(Default)]
9-
pub struct in_addr {
9+
pub struct InAddr {
1010
pub s_addr: Value<u32>,
1111
}
1212

13-
pub struct in6_addr {
13+
pub struct In6Addr {
1414
pub s6_addr: Value<Box<[u8]>>,
1515
}
1616

17-
impl in6_addr {
17+
impl In6Addr {
1818
pub fn s6_addr(&self) -> Ptr<u8> {
1919
self.s6_addr.as_pointer()
2020
}
2121
}
2222

23-
impl Default for in6_addr {
23+
impl Default for In6Addr {
2424
fn default() -> Self {
2525
Self {
2626
s6_addr: Rc::new(RefCell::new(vec![0u8; 16].into_boxed_slice())),
2727
}
2828
}
2929
}
3030

31-
impl Clone for in_addr {
31+
impl Clone for InAddr {
3232
fn clone(&self) -> Self {
3333
Self {
3434
s_addr: Rc::new(RefCell::new(*self.s_addr.borrow())),
3535
}
3636
}
3737
}
3838

39-
impl Clone for in6_addr {
39+
impl Clone for In6Addr {
4040
fn clone(&self) -> Self {
4141
Self {
4242
s6_addr: Rc::new(RefCell::new(self.s6_addr.borrow().clone())),
4343
}
4444
}
4545
}
4646

47-
impl ByteRepr for in_addr {
47+
impl ByteRepr for InAddr {
4848
fn byte_size() -> usize {
4949
4
5050
}
@@ -58,7 +58,7 @@ impl ByteRepr for in_addr {
5858
}
5959
}
6060

61-
impl ByteRepr for in6_addr {
61+
impl ByteRepr for In6Addr {
6262
fn byte_size() -> usize {
6363
16
6464
}

libcc2rs/src/libc_shims/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4-
#![allow(non_camel_case_types)]
5-
64
mod dirent;
75
mod ifaddrs;
86
mod ip;

libcc2rs/src/libc_shims/netdb.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4-
use super::sockaddr;
4+
use super::Sockaddr;
55
use crate::{ByteRepr, Ptr, Value};
66
use std::cell::RefCell;
77
use std::rc::Rc;
88

9-
pub struct addrinfo {
9+
pub struct Addrinfo {
1010
pub ai_flags: Value<i32>,
1111
pub ai_family: Value<i32>,
1212
pub ai_socktype: Value<i32>,
1313
pub ai_protocol: Value<i32>,
1414
pub ai_addrlen: Value<u32>,
15-
pub ai_addr: Value<Ptr<sockaddr>>,
15+
pub ai_addr: Value<Ptr<Sockaddr>>,
1616
pub ai_canonname: Value<Ptr<u8>>,
17-
pub ai_next: Value<Ptr<addrinfo>>,
17+
pub ai_next: Value<Ptr<Addrinfo>>,
1818
}
1919

20-
impl Default for addrinfo {
20+
impl Default for Addrinfo {
2121
fn default() -> Self {
2222
Self {
2323
ai_flags: Rc::new(RefCell::new(0)),
@@ -32,7 +32,7 @@ impl Default for addrinfo {
3232
}
3333
}
3434

35-
impl Clone for addrinfo {
35+
impl Clone for Addrinfo {
3636
fn clone(&self) -> Self {
3737
Self {
3838
ai_flags: Rc::new(RefCell::new(*self.ai_flags.borrow())),
@@ -47,6 +47,6 @@ impl Clone for addrinfo {
4747
}
4848
}
4949

50-
impl ByteRepr for addrinfo {}
50+
impl ByteRepr for Addrinfo {}
5151

5252
impl ByteRepr for ::libc::addrinfo {}

libcc2rs/src/libc_shims/poll.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use crate::{ByteRepr, Value};
55
use std::cell::RefCell;
66
use std::rc::Rc;
77

8-
pub struct pollfd {
8+
pub struct Pollfd {
99
pub fd: Value<i32>,
1010
pub events: Value<i16>,
1111
pub revents: Value<i16>,
1212
}
1313

14-
impl Default for pollfd {
14+
impl Default for Pollfd {
1515
fn default() -> Self {
1616
Self {
1717
fd: Rc::new(RefCell::new(0)),
@@ -21,7 +21,7 @@ impl Default for pollfd {
2121
}
2222
}
2323

24-
impl Clone for pollfd {
24+
impl Clone for Pollfd {
2525
fn clone(&self) -> Self {
2626
Self {
2727
fd: Rc::new(RefCell::new(*self.fd.borrow())),
@@ -31,6 +31,6 @@ impl Clone for pollfd {
3131
}
3232
}
3333

34-
impl ByteRepr for pollfd {}
34+
impl ByteRepr for Pollfd {}
3535

3636
impl ByteRepr for ::libc::pollfd {}

libcc2rs/src/libc_shims/pwd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{ByteRepr, Ptr, Value};
55
use std::cell::RefCell;
66
use std::rc::Rc;
77

8-
pub struct passwd {
8+
pub struct Passwd {
99
pub pw_name: Value<Ptr<u8>>,
1010
pub pw_passwd: Value<Ptr<u8>>,
1111
pub pw_uid: Value<u32>,
@@ -15,7 +15,7 @@ pub struct passwd {
1515
pub pw_shell: Value<Ptr<u8>>,
1616
}
1717

18-
impl Default for passwd {
18+
impl Default for Passwd {
1919
fn default() -> Self {
2020
Self {
2121
pw_name: Rc::new(RefCell::new(Ptr::null())),
@@ -29,7 +29,7 @@ impl Default for passwd {
2929
}
3030
}
3131

32-
impl Clone for passwd {
32+
impl Clone for Passwd {
3333
fn clone(&self) -> Self {
3434
Self {
3535
pw_name: Rc::new(RefCell::new(self.pw_name.borrow().clone())),
@@ -43,6 +43,6 @@ impl Clone for passwd {
4343
}
4444
}
4545

46-
impl ByteRepr for passwd {}
46+
impl ByteRepr for Passwd {}
4747

4848
impl ByteRepr for ::libc::passwd {}

0 commit comments

Comments
 (0)