diff --git a/libuwuc/src/error.rs b/libuwuc/src/error.rs index 8ef22f1..aa734f0 100644 --- a/libuwuc/src/error.rs +++ b/libuwuc/src/error.rs @@ -1,18 +1,20 @@ use core::{cell::UnsafeCell, ptr::addr_of}; -#[thread_local] -static ERRNO: UnsafeCell = UnsafeCell::new(0); +use crate::utils::SyncUnsafeCell; + +// Todo: This should be a thread local once we have threads. +static ERRNO: SyncUnsafeCell = SyncUnsafeCell(UnsafeCell::new(0)); pub fn errno_location() -> *const i32 { addr_of!(ERRNO).cast() } pub fn errno() -> i32 { - unsafe { *ERRNO.get() } + unsafe { *ERRNO.0.get() } } pub fn set_errno(errno: i32) { - unsafe { ERRNO.get().write(errno) } + unsafe { ERRNO.0.get().write(errno) } } pub const EPERM: i32 = 1; /* Operation not permitted */ diff --git a/libuwuc/src/mem.rs b/libuwuc/src/mem.rs index 2fb80bb..10f7454 100644 --- a/libuwuc/src/mem.rs +++ b/libuwuc/src/mem.rs @@ -79,7 +79,7 @@ mod tests { fn memcmp_eq_one() { let a = [1]; let b = [1]; - let result = unsafe { super::memcmp(a.as_ptr(), b.as_ptr(), 1)}; + let result = unsafe { super::memcmp(a.as_ptr(), b.as_ptr(), 1) }; assert_eq!(result, 0); } @@ -103,7 +103,7 @@ mod tests { fn memcmp_lt_one() { let a = [0]; let b = [1]; - let result = unsafe { super::memcmp(a.as_ptr(), b.as_ptr(), 1)}; + let result = unsafe { super::memcmp(a.as_ptr(), b.as_ptr(), 1) }; assert_eq!(result, -1); } @@ -127,7 +127,7 @@ mod tests { fn memcmp_gt_one() { let a = [255]; let b = [1]; - let result = unsafe { super::memcmp(a.as_ptr(), b.as_ptr(), 1)}; + let result = unsafe { super::memcmp(a.as_ptr(), b.as_ptr(), 1) }; assert_eq!(result, 1); } diff --git a/libuwuc/src/stubs.rs b/libuwuc/src/stubs.rs index e69de29..8b13789 100644 --- a/libuwuc/src/stubs.rs +++ b/libuwuc/src/stubs.rs @@ -0,0 +1 @@ + diff --git a/libuwuc/src/sys/mod.rs b/libuwuc/src/sys/mod.rs index 82b93c0..31c7a4f 100644 --- a/libuwuc/src/sys/mod.rs +++ b/libuwuc/src/sys/mod.rs @@ -5,4 +5,4 @@ cfg_if::cfg_if! { } else { compile_error!("uwuc does not support this target yet!"); } -} \ No newline at end of file +} diff --git a/libuwuc/src/sys/x86_64/helpers.rs b/libuwuc/src/sys/x86_64/helpers.rs index a27018d..eb22d92 100644 --- a/libuwuc/src/sys/x86_64/helpers.rs +++ b/libuwuc/src/sys/x86_64/helpers.rs @@ -4,4 +4,4 @@ macro_rules! trap { ::core::arch::asm!("ud2"); }; } -pub(crate) use trap; \ No newline at end of file +pub(crate) use trap; diff --git a/libuwuc/src/sys/x86_64/syscall/mod.rs b/libuwuc/src/sys/x86_64/syscall/mod.rs index b327a05..2a272f2 100644 --- a/libuwuc/src/sys/x86_64/syscall/mod.rs +++ b/libuwuc/src/sys/x86_64/syscall/mod.rs @@ -113,4 +113,4 @@ macro_rules! syscall { }}; } -pub use syscall; \ No newline at end of file +pub use syscall; diff --git a/rawc/build.rs b/rawc/build.rs index 6438874..25a3852 100644 --- a/rawc/build.rs +++ b/rawc/build.rs @@ -1,4 +1,4 @@ fn main() { println!("cargo:rustc-link-arg=-nostartfiles"); println!("cargo:rustc-link-arg=-nostdlib"); -} \ No newline at end of file +} diff --git a/rawc/src/string.rs b/rawc/src/string.rs index ab964ca..3640aac 100644 --- a/rawc/src/string.rs +++ b/rawc/src/string.rs @@ -13,7 +13,6 @@ pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, size: usize) -> i3 libuwuc::mem::memcmp(s1, s2, size) } - #[no_mangle] pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, size: usize) -> i32 { libuwuc::mem::memcmp(s1, s2, size) diff --git a/tests/c/argv.c b/tests/c/argv.c index 1535639..274d6bf 100644 --- a/tests/c/argv.c +++ b/tests/c/argv.c @@ -1,9 +1,9 @@ -#include +#include -int main(int argc, char* argv[]) { - char *self = argv[0]; - char first = self[0]; - if (first != '/') { - return 1; - } +int main(int argc, char *argv[]) { + char *self = argv[0]; + char first = self[0]; + if (first != '/') { + return 1; + } } \ No newline at end of file diff --git a/tests/c/errno.c b/tests/c/errno.c index e5cc2b0..c91ff5c 100644 --- a/tests/c/errno.c +++ b/tests/c/errno.c @@ -1,7 +1,6 @@ -//@ignore doens't initialize fs yet -#include +#include int main(void) { - int err = errno; - return err; -} \ No newline at end of file + int err = errno; + return err; +} diff --git a/tests/c/getenv.c b/tests/c/getenv.c index cfaf1f1..a4a348c 100644 --- a/tests/c/getenv.c +++ b/tests/c/getenv.c @@ -1,13 +1,14 @@ #include int main(int argc, char *argv[]) { - char *env = getenv("PATH"); - if (!env) { - return 1; - } + char *env = getenv("PATH"); + if (!env) { + return 1; + } - char *env2 = getenv("__some absolutely NONSENSE that no one would ever define please.."); - if (env2) { - return 1; - } + char *env2 = getenv( + "__some absolutely NONSENSE that no one would ever define please.."); + if (env2) { + return 1; + } } diff --git a/tests/c/malloc.c b/tests/c/malloc.c index cd8862e..818263b 100644 --- a/tests/c/malloc.c +++ b/tests/c/malloc.c @@ -1,8 +1,8 @@ -#include +#include int main(void) { - char *alloc = (char*) malloc(10); - *alloc = 1; - *(alloc + 9) = 2; - free(alloc); + char *alloc = (char *)malloc(10); + *alloc = 1; + *(alloc + 9) = 2; + free(alloc); } \ No newline at end of file diff --git a/tests/c/mem.c b/tests/c/mem.c index 1aca930..b231301 100644 --- a/tests/c/mem.c +++ b/tests/c/mem.c @@ -1,13 +1,13 @@ -#include +#include int main(void) { - char buf[10]; + char buf[10]; - memset(buf, 34, sizeof(buf)); + memset(buf, 34, sizeof(buf)); - for (int i = 0; i < 10; ++i) { - if (buf[i] != 34) { - return 1; - } + for (int i = 0; i < 10; ++i) { + if (buf[i] != 34) { + return 1; } + } } \ No newline at end of file diff --git a/tests/c/simple_printf.c b/tests/c/simple_printf.c index ed19438..e56f7a5 100644 --- a/tests/c/simple_printf.c +++ b/tests/c/simple_printf.c @@ -1,8 +1,8 @@ -#include +#include int main(int argc, char *argv[]) { - int result = printf("Hello, world!\n"); - if (result != 14) { - return 1; - } + int result = printf("Hello, world!\n"); + if (result != 14) { + return 1; + } } diff --git a/tests/c/strtol.c b/tests/c/strtol.c index 3d2a611..11fbc04 100644 --- a/tests/c/strtol.c +++ b/tests/c/strtol.c @@ -1,9 +1,9 @@ -#include +#include int main(void) { - char *str = "12"; - long value = strtol(str, NULL, 10); - if (value != 12) { - return 1; - } + char *str = "12"; + long value = strtol(str, NULL, 10); + if (value != 12) { + return 1; + } }