diff --git a/lib/abi/src/pass.rs b/lib/abi/src/pass.rs index 8f9240c8..8db2d06f 100644 --- a/lib/abi/src/pass.rs +++ b/lib/abi/src/pass.rs @@ -80,7 +80,7 @@ unsafe impl Place for [T] { /// Automatically implements the [Place] interface for a struct, properly handling any nested /// references #[macro_export] -macro_rules! impl_place_lifetime { +macro_rules! impl_place_lifetime_struct { ( $( #[ $struct_meta:meta ] )* $struct_vis:vis struct $struct_name:ident<$struct_lifetime:lifetime> { diff --git a/lib/abi/src/process/mod.rs b/lib/abi/src/process/mod.rs index 67b920f2..9241aada 100644 --- a/lib/abi/src/process/mod.rs +++ b/lib/abi/src/process/mod.rs @@ -3,7 +3,7 @@ use core::{fmt, time::Duration}; use crate::{ - impl_place_lifetime, + impl_place_lifetime_struct, io::{FileMode, RawFd}, }; @@ -54,7 +54,7 @@ pub enum ProcessInfoElement { } // TODO not sure if I really need #[repr(C)] ABI here -impl_place_lifetime! { +impl_place_lifetime_struct! { #[doc = "Argument struct passed from the kernel to a spawned process"] #[derive(Debug)] pub struct ProgramArgumentInner<'a> { diff --git a/userspace/lib/ygglibc/build.rs b/userspace/lib/ygglibc/build.rs index 5f35af13..b1775d42 100644 --- a/userspace/lib/ygglibc/build.rs +++ b/userspace/lib/ygglibc/build.rs @@ -50,6 +50,7 @@ fn generate_header(config_path: impl AsRef, header_output: impl AsRef +#if defined(__cplusplus) +extern "C" { +#endif + typedef _Atomic int sig_atomic_t; #define SIG_IGN __sig_ignore @@ -13,4 +17,8 @@ typedef _Atomic int sig_atomic_t; #define SIG_DFL ((sig_handler_t) 0) +#if defined(__cplusplus) +} +#endif + #endif diff --git a/userspace/lib/ygglibc/include/bits/stdio.h b/userspace/lib/ygglibc/include/bits/stdio.h index cb47c0ba..4ea322a9 100644 --- a/userspace/lib/ygglibc/include/bits/stdio.h +++ b/userspace/lib/ygglibc/include/bits/stdio.h @@ -1,6 +1,10 @@ #ifndef _YGGDRASIL_STDIO_H #define _YGGDRASIL_STDIO_H 1 +#if defined(__cplusplus) +extern "C" { +#endif + struct __FILE; typedef struct __FILE FILE; @@ -8,10 +12,16 @@ extern FILE *stdin; extern FILE *stdout; extern FILE *stderr; +int asprintf(char **strp, const char *fmt, ...); int dprintf(int fd, const char *fmt, ...); int fprintf(FILE *fp, const char *fmt, ...); int printf(const char *fmt, ...); int snprintf(char *buf, size_t len, const char *fmt, ...); int sprintf(char *buf, const char *fmt, ...); +int sscanf(const char *str, const char *fmt, ...); + +#if defined(__cplusplus) +} +#endif #endif diff --git a/userspace/lib/ygglibc/include/bits/stdlib.h b/userspace/lib/ygglibc/include/bits/stdlib.h new file mode 100644 index 00000000..5bc451eb --- /dev/null +++ b/userspace/lib/ygglibc/include/bits/stdlib.h @@ -0,0 +1,14 @@ +#ifndef _YGGDRASIL_STDLIB_H +#define _YGGDRASIL_STDLIB_H 1 + +#if defined(__cplusplus) +extern "C" { +#endif + +[[noreturn]] void abort(void); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/userspace/lib/ygglibc/include/bits/time.h b/userspace/lib/ygglibc/include/bits/time.h index 5f7034fd..bb20d076 100644 --- a/userspace/lib/ygglibc/include/bits/time.h +++ b/userspace/lib/ygglibc/include/bits/time.h @@ -1,6 +1,14 @@ #ifndef _YGGDRASIL_TIME_H #define _YGGDRASIL_TIME_H 1 +#if defined(__cplusplus) +extern "C" { +#endif + typedef struct timespec __ygg_timespec_t; +#if defined(__cplusplus) +} +#endif + #endif diff --git a/userspace/lib/ygglibc/include/bits/ulimit.h b/userspace/lib/ygglibc/include/bits/ulimit.h index 542ecd71..6f713712 100644 --- a/userspace/lib/ygglibc/include/bits/ulimit.h +++ b/userspace/lib/ygglibc/include/bits/ulimit.h @@ -1,6 +1,14 @@ #ifndef _YGGDRASIL_ULIMIT_H #define _YGGDRASIL_ULIMIT_H 1 +#if defined(__cplusplus) +extern "C" { +#endif + long ulimit(int which, ...); +#if defined(__cplusplus) +} +#endif + #endif diff --git a/userspace/lib/ygglibc/include/bits/unistd.h b/userspace/lib/ygglibc/include/bits/unistd.h index 37674ac5..f9f4c8ac 100644 --- a/userspace/lib/ygglibc/include/bits/unistd.h +++ b/userspace/lib/ygglibc/include/bits/unistd.h @@ -1,10 +1,18 @@ #ifndef _YGGDRASIL_UNISTD_H #define _YGGDRASIL_UNISTD_H 1 +#if defined(__cplusplus) +extern "C" { +#endif + int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ...); extern char **environ; +#if defined(__cplusplus) +} +#endif + #endif diff --git a/userspace/lib/ygglibc/include/bits/wchar.h b/userspace/lib/ygglibc/include/bits/wchar.h index 6d22df4a..b112d09e 100644 --- a/userspace/lib/ygglibc/include/bits/wchar.h +++ b/userspace/lib/ygglibc/include/bits/wchar.h @@ -1,6 +1,10 @@ #ifndef _YGGDRASIL_WCHAR_H #define _YGGDRASIL_WCHAR_H 1 +#if defined(__cplusplus) +extern "C" { +#endif + int fwprintf(FILE *fp, const wchar_t *fmt, ...); int fwscanf(FILE *fp, const wchar_t *fmt, ...); int swprintf(wchar_t *buf, size_t len, const wchar_t *fmt, ...); @@ -8,4 +12,8 @@ int swscanf(const wchar_t *buf, const wchar_t *fmt, ...); int wprintf(const wchar_t *fmt, ...); int wscanf(const wchar_t *fmt, ...); +#if defined(__cplusplus) +} +#endif + #endif diff --git a/userspace/lib/ygglibc/include/bits/wctype.h b/userspace/lib/ygglibc/include/bits/wctype.h new file mode 100644 index 00000000..15e80646 --- /dev/null +++ b/userspace/lib/ygglibc/include/bits/wctype.h @@ -0,0 +1,16 @@ +#ifndef _YGGDRASIL_WCTYPE_H +#define _YGGDRASIL_WCTYPE_H 1 + +#if defined(__cplusplus) +extern "C" { +#endif + +#if !defined(wctype_t) +typedef int wctype_t; +#endif + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/userspace/lib/ygglibc/include/dlfcn.h b/userspace/lib/ygglibc/include/dlfcn.h index f30704a6..f171cee3 100644 --- a/userspace/lib/ygglibc/include/dlfcn.h +++ b/userspace/lib/ygglibc/include/dlfcn.h @@ -6,9 +6,17 @@ #define RTLD_GLOBAL (1 << 1) #define RTLD_LOCAL (0 << 1) +#if defined(__cplusplus) +extern "C" { +#endif + int dlclose(void *ptr); char *dlerror(void); void *dlopen(const char *path, int mode); void *dlsym(void *handle, const char *sym); +#if defined(__cplusplus) +} +#endif + #endif diff --git a/userspace/lib/ygglibc/src/cxxabi.rs b/userspace/lib/ygglibc/src/cxxabi.rs new file mode 100644 index 00000000..12879f71 --- /dev/null +++ b/userspace/lib/ygglibc/src/cxxabi.rs @@ -0,0 +1,87 @@ +use core::ffi::{c_int, c_void}; + +#[no_mangle] +unsafe extern "C" fn __cxa_begin_catch(_exception: *mut c_void) -> *mut c_void { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn __cxa_end_catch() { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn __cxa_pure_virtual() { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn __cxa_guard_acquire(_guard: *mut u64) -> c_int { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn __cxa_guard_release(_guard: *mut u64) { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn __cxa_atexit( + _destructor: extern "C" fn(*mut c_void), + _arg: *mut c_void, + _dso_handle: *mut c_void, +) -> c_int { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn __gxx_personality_v0() { + unimplemented!() +} + +#[no_mangle] +unsafe extern "C" fn _Unwind_Resume(_exception: *mut c_void) { + unimplemented!() +} + +// void *operator new(size_t x) +#[no_mangle] +unsafe extern "C" fn _Znwm(_x: usize) -> *mut c_void { + unimplemented!() +} + +// void *operator new(size_t x, std::align_val_t y) +#[no_mangle] +unsafe extern "C" fn _ZnwmSt11align_val_t(_x: usize, _y: usize) -> *mut c_void { + unimplemented!() +} + +// void *operator new[](size_t x) +#[no_mangle] +unsafe extern "C" fn _Znam(_x: usize) -> *mut c_void { + unimplemented!() +} + +// void operator delete(void *x) +#[no_mangle] +unsafe extern "C" fn _ZdlPv(_x: *mut c_void) { + unimplemented!() +} + +// void operator delete(void *x, size_t y) +#[no_mangle] +unsafe extern "C" fn _ZdlPvm(_x: *mut c_void, _y: usize) { + unimplemented!() +} + +// void operator delete(void *x, size_t y, std::align_val_t z) +#[no_mangle] +unsafe extern "C" fn _ZdlPvmSt11align_val_t(_x: *mut c_void, _y: usize) { + unimplemented!() +} + +// void operator delete[](void *x) +#[no_mangle] +unsafe extern "C" fn _ZdaPv(_x: *mut c_void) { + unimplemented!() +} diff --git a/userspace/lib/ygglibc/src/headers/locale/mod.rs b/userspace/lib/ygglibc/src/headers/locale/mod.rs index f87bcd23..48563da9 100644 --- a/userspace/lib/ygglibc/src/headers/locale/mod.rs +++ b/userspace/lib/ygglibc/src/headers/locale/mod.rs @@ -49,6 +49,15 @@ pub const LC_MONETARY: c_int = 3; pub const LC_NUMERIC: c_int = 4; pub const LC_TIME: c_int = 5; +pub const LC_COLLATE_MASK: c_int = 0; +pub const LC_CTYPE_MASK: c_int = 0; +pub const LC_MESSAGES_MASK: c_int = 0; +pub const LC_MONETARY_MASK: c_int = 0; +pub const LC_NUMERIC_MASK: c_int = 0; +pub const LC_TIME_MASK: c_int = 0; + +pub const LC_ALL_MASK: c_int = 0; + pub const LC_ALL: c_int = 6; pub const __LC_LAST: usize = 6; diff --git a/userspace/lib/ygglibc/src/headers/stdio/cbindgen.toml b/userspace/lib/ygglibc/src/headers/stdio/cbindgen.toml index 83c160a4..3d817dd5 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/cbindgen.toml +++ b/userspace/lib/ygglibc/src/headers/stdio/cbindgen.toml @@ -20,6 +20,7 @@ isize_type = "ssize_t" [export] include = ["fpos_t"] exclude = [ + "asprintf", "printf", "fprintf", "dprintf", diff --git a/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs b/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs index 632e24e2..d5410d1c 100644 --- a/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs +++ b/userspace/lib/ygglibc/src/headers/stdio/printf/mod.rs @@ -185,6 +185,16 @@ fn printf_inner(output: &mut W, format: &[u8], mut ap: VaList) -> EResult::Ok(count) } +#[no_mangle] +unsafe extern "C" fn asprintf(dst: *mut *mut c_char, fmt: *const c_char, mut args: ...) -> c_int { + vasprintf(dst, fmt, args.as_va_list()) +} + +#[no_mangle] +unsafe extern "C" fn vasprintf(_dst: *mut *mut c_char, _fmt: *const c_char, args: VaList) -> c_int { + todo!() +} + #[no_mangle] unsafe extern "C" fn dprintf(fd: c_int, fmt: *const c_char, mut args: ...) -> CIntCountResult { vdprintf(fd, fmt, args.as_va_list()) diff --git a/userspace/lib/ygglibc/src/headers/stdlib/cbindgen.toml b/userspace/lib/ygglibc/src/headers/stdlib/cbindgen.toml index 5381ea06..d5361b95 100644 --- a/userspace/lib/ygglibc/src/headers/stdlib/cbindgen.toml +++ b/userspace/lib/ygglibc/src/headers/stdlib/cbindgen.toml @@ -2,7 +2,9 @@ language = "C" style = "Type" sys_includes = [ - "stddef.h" + "stddef.h", + "locale.h", + "bits/stdlib.h" ] no_includes = true @@ -10,3 +12,6 @@ include_guard = "_STDLIB_H" usize_type = "size_t" isize_type = "ssize_t" + +[export] +exclude = ["abort"] diff --git a/userspace/lib/ygglibc/src/headers/stdlib/conv.rs b/userspace/lib/ygglibc/src/headers/stdlib/conv.rs index a7fa3043..276e01fb 100644 --- a/userspace/lib/ygglibc/src/headers/stdlib/conv.rs +++ b/userspace/lib/ygglibc/src/headers/stdlib/conv.rs @@ -3,7 +3,7 @@ use core::{ ptr::{null_mut, NonNull}, }; -use crate::util::cstr_matches_insensitive; +use crate::{headers::locale::locale_t, util::cstr_matches_insensitive}; // base64 @@ -84,6 +84,55 @@ unsafe extern "C" fn strtoull( str_to_uint_ext(s, endptr, base) } +// locale + +#[no_mangle] +unsafe extern "C" fn strtoll_l( + _s: *const c_char, + _endptr: *mut *mut c_char, + _base: c_int, + _locale: locale_t, +) -> c_longlong { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn strtoull_l( + _s: *const c_char, + _endptr: *mut *mut c_char, + _base: c_int, + _locale: locale_t, +) -> c_ulonglong { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn strtof_l( + _s: *const c_char, + _endptr: *mut *mut c_char, + _locale: locale_t, +) -> c_float { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn strtod_l( + _s: *const c_char, + _endptr: *mut *mut c_char, + _locale: locale_t, +) -> c_double { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn strtold_l( + _s: *const c_char, + _endptr: *mut *mut c_char, + _locale: locale_t, +) -> c_double { + todo!() +} + #[derive(Clone, Copy, PartialEq)] enum Radix { Oct, diff --git a/userspace/lib/ygglibc/src/headers/stdlib/wide.rs b/userspace/lib/ygglibc/src/headers/stdlib/wide.rs index bd5a9f7b..28020482 100644 --- a/userspace/lib/ygglibc/src/headers/stdlib/wide.rs +++ b/userspace/lib/ygglibc/src/headers/stdlib/wide.rs @@ -1,6 +1,28 @@ +use core::ffi::{c_char, c_int}; -// int mblen(const char *, size_t); -// size_t mbstowcs(wchar_t *restrict, const char *restrict, size_t); -// int mbtowc(wchar_t *restrict, const char *restrict, size_t); -// size_t wcstombs(char *restrict, const wchar_t *restrict, size_t); -// int wctomb(char *, wchar_t); +use crate::types::wchar_t; + +#[no_mangle] +unsafe extern "C" fn mblen(_s: *const c_char, _n: usize) -> c_int { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn mbstowcs(_dst: *mut wchar_t, _src: *const c_char, _n: usize) -> usize { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn mbtowc(_dst: *mut wchar_t, _src: *const c_char, _n: usize) -> c_int { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn wcstombs(_dst: *mut c_char, _src: *const wchar_t, _n: usize) -> usize { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn wctomb(_dst: *mut c_char, _wc: wchar_t) -> c_int { + todo!() +} diff --git a/userspace/lib/ygglibc/src/headers/sys_time/mod.rs b/userspace/lib/ygglibc/src/headers/sys_time/mod.rs index 4e6be1b0..ad30e967 100644 --- a/userspace/lib/ygglibc/src/headers/sys_time/mod.rs +++ b/userspace/lib/ygglibc/src/headers/sys_time/mod.rs @@ -1,4 +1,4 @@ -use core::ffi::c_long; +use core::ffi::{c_int, c_long, c_void}; use super::sys_types::{suseconds_t, time_t}; @@ -16,5 +16,31 @@ pub struct timespec { pub tv_nsec: c_long, } +#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)] +#[repr(C)] +pub struct itimerval { + pub it_interval: timeval, + pub it_value: timeval +} + pub type __ygg_timeval_t = timeval; pub type __ygg_timespec_t = timespec; + +pub const ITIMER_REAL: c_int = 0; +pub const ITIMER_VIRTUAL: c_int = 1; +pub const ITIMER_PROF: c_int = 2; + +#[no_mangle] +unsafe extern "C" fn getitimer(_timer: c_int, _value: *mut itimerval) -> c_int { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn gettimeofday(_time: *mut timeval, _d: *mut c_void) -> c_int { + todo!() +} + +#[no_mangle] +unsafe extern "C" fn setitimer(_timer: c_int, _new: *const itimerval, _old: *mut itimerval) -> c_int { + todo!() +} diff --git a/userspace/lib/ygglibc/src/headers/wchar/cbindgen.toml b/userspace/lib/ygglibc/src/headers/wchar/cbindgen.toml index 7ec6ba42..d88d1185 100644 --- a/userspace/lib/ygglibc/src/headers/wchar/cbindgen.toml +++ b/userspace/lib/ygglibc/src/headers/wchar/cbindgen.toml @@ -16,6 +16,7 @@ sys_includes = [ no_includes = true include_guard = "_WCHAR_H" +trailer = "#include " usize_type = "size_t" isize_type = "ssize_t" diff --git a/userspace/lib/ygglibc/src/headers/wchar/mod.rs b/userspace/lib/ygglibc/src/headers/wchar/mod.rs index e362bdd8..34fd35bc 100644 --- a/userspace/lib/ygglibc/src/headers/wchar/mod.rs +++ b/userspace/lib/ygglibc/src/headers/wchar/mod.rs @@ -1,4 +1,6 @@ -use core::ffi::c_void; +use core::ffi::{c_int, c_void}; + +use crate::types::wchar_t; use super::wctype::wint_t; @@ -6,4 +8,9 @@ pub mod io; pub mod multibyte; pub mod string; -pub type mbstate_t = c_void; +pub const WEOF: wchar_t = -1; + +#[repr(C)] +pub struct mbstate_t { + __dummy: c_int +} diff --git a/userspace/lib/ygglibc/src/headers/wctype/cbindgen.toml b/userspace/lib/ygglibc/src/headers/wctype/cbindgen.toml index f74a244a..7d0ccfcf 100644 --- a/userspace/lib/ygglibc/src/headers/wctype/cbindgen.toml +++ b/userspace/lib/ygglibc/src/headers/wctype/cbindgen.toml @@ -2,6 +2,7 @@ language = "C" style = "Type" sys_includes = [ + "bits/wctype.h", "locale.h", "ctype.h", ] @@ -13,4 +14,5 @@ usize_type = "size_t" isize_type = "ssize_t" [export] -include = ["wint_t", "wctype_t"] +include = ["wint_t"] +exclude = ["wctype_t"] diff --git a/userspace/lib/ygglibc/src/lib.rs b/userspace/lib/ygglibc/src/lib.rs index e1d001a9..73999257 100644 --- a/userspace/lib/ygglibc/src/lib.rs +++ b/userspace/lib/ygglibc/src/lib.rs @@ -33,6 +33,7 @@ mod ssp; mod sync; mod types; mod util; +mod cxxabi; pub mod headers;