diff --git a/include/sys/user.h b/include/sys/user.h new file mode 100644 index 0000000000000000000000000000000000000000..cc0333a6286957250b91e09febb6e4ce53a96540 --- /dev/null +++ b/include/sys/user.h @@ -0,0 +1,11 @@ +#ifndef _SYS_USER_H +#define _SYS_USER_H +#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) +#include <arch/x64/user.h> +#elif defined(__aarch64__) +#include <arch/aarch64/user.h> +#else +#error "Unknown architecture" +#endif + +#endif \ No newline at end of file diff --git a/src/header/arch_aarch64_user/cbindgen.toml b/src/header/arch_aarch64_user/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..2000868e87b71b1fafd3a44f2c9e49015f95c5d5 --- /dev/null +++ b/src/header/arch_aarch64_user/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = [] +include_guard = "_AARCH64_USER_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/header/arch_aarch64_user/mod.rs b/src/header/arch_aarch64_user/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..6f25a5da8022e2be08c72a74e22bbafcea22a378 --- /dev/null +++ b/src/header/arch_aarch64_user/mod.rs @@ -0,0 +1,30 @@ +use crate::platform::types::*; + +#[repr(C)] +pub struct user_regs_struct { + pub regs: [c_ulonglong; 31], + pub sp: c_ulonglong, + pub pc: c_ulonglong, + pub pstate: c_ulonglong, +} + +#[repr(C)] +pub struct user_fpsimd_struct { + pub vregs: [c_double; 32], // BUG: rust doesn't have f128 which is equivalent for long double + pub fpsr: c_uint, + pub fpcr: c_uint, +} + +pub type elf_greg_t = c_ulong; +pub type elf_gregset_t = [c_ulong; 34]; +pub type elf_fpregset_t = user_fpsimd_struct; + +#[no_mangle] +pub extern "C" fn _cbindgen_only_generates_structs_if_they_are_mentioned_which_is_dumb_aarch64_user( + a: user_regs_struct, + b: user_fpsimd_struct, + c: elf_gregset_t, + d: elf_greg_t, + e: elf_fpregset_t, +) { +} diff --git a/src/header/sys_user/cbindgen.toml b/src/header/arch_x64_user/cbindgen.toml similarity index 72% rename from src/header/sys_user/cbindgen.toml rename to src/header/arch_x64_user/cbindgen.toml index 63c05e2adcf029bd5a037f149dded486f4389060..04a2ccea4e595973efbb040e602944cacbba3237 100644 --- a/src/header/sys_user/cbindgen.toml +++ b/src/header/arch_x64_user/cbindgen.toml @@ -1,5 +1,5 @@ sys_includes = [] -include_guard = "_SYS_USER_H" +include_guard = "_X64_USER_H" language = "C" style = "Tag" diff --git a/src/header/sys_user/mod.rs b/src/header/arch_x64_user/mod.rs similarity index 61% rename from src/header/sys_user/mod.rs rename to src/header/arch_x64_user/mod.rs index 37ef15544fb14ddc972886b2f165d070fa6a60ad..92d34b62794ef2e9b00e55445ec1fe1de0246d62 100644 --- a/src/header/sys_user/mod.rs +++ b/src/header/arch_x64_user/mod.rs @@ -48,9 +48,36 @@ pub struct user_regs_struct { pub gs: c_ulong, } +pub type elf_greg_t = c_ulong; + +pub type elf_gregset_t = [c_ulong; 27]; +pub type elf_fpregset_t = user_fpregs_struct; +#[repr(C)] +pub struct user { + pub regs: user_regs_struct, + pub u_fpvalid: c_int, + pub i387: user_fpregs_struct, + pub u_tsize: c_ulong, + pub u_dsize: c_ulong, + pub u_ssize: c_ulong, + pub start_code: c_ulong, + pub start_stack: c_ulong, + pub signal: c_long, + pub reserved: c_int, + pub u_ar0: *mut user_regs_struct, + pub u_fpstate: *mut user_fpregs_struct, + pub magic: c_ulong, + pub u_comm: [c_char; 32], + pub u_debugreg: [c_ulong; 8], +} + #[no_mangle] -pub extern "C" fn _cbindgen_only_generates_structs_if_they_are_mentioned_which_is_dumb( +pub extern "C" fn _cbindgen_only_generates_structs_if_they_are_mentioned_which_is_dumb_x86_user( a: user_fpregs_struct, b: user_regs_struct, + c: user, + d: elf_gregset_t, + e: elf_greg_t, + f: elf_fpregset_t, ) { } diff --git a/src/header/mod.rs b/src/header/mod.rs index 80da6f421406b244fccab553137a650777e2328a..c6167c59bb3699798ea91415148338bac56df88f 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -47,9 +47,11 @@ pub mod sys_time; pub mod sys_timeb; //pub mod sys_times; pub mod _wctype; +pub mod arch_aarch64_user; +pub mod arch_x64_user; +pub mod sys_procfs; pub mod sys_uio; pub mod sys_un; -pub mod sys_user; pub mod sys_utsname; pub mod sys_wait; pub mod termios; diff --git a/src/header/sys_procfs/cbindgen.toml b/src/header/sys_procfs/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..9328ff99d387d714a1d8865a25f6e702ee619249 --- /dev/null +++ b/src/header/sys_procfs/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = ["sys/user.h"] +include_guard = "_SYS_PROCFS_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/header/sys_procfs/mod.rs b/src/header/sys_procfs/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..a70aa9f6c1d2d7fa96edb3307d51477885859a07 --- /dev/null +++ b/src/header/sys_procfs/mod.rs @@ -0,0 +1,73 @@ +#[cfg(target_arch = "aarch64")] +use crate::header::arch_aarch64_user::*; +#[cfg(target_arch = "x86_64")] +use crate::header::arch_x64_user::*; +use crate::platform::types::*; + +pub const ELF_PRARGSZ: size_t = 80; + +#[repr(C)] +pub struct elf_siginfo { + pub si_signo: c_int, + pub si_code: c_int, + pub si_errno: c_int, +} + +#[repr(C)] +pub struct time { + pub tv_sec: c_long, + pub tv_usec: c_long, +} + +#[repr(C)] +pub struct elf_prstatus { + pub pr_info: elf_siginfo, + pub pr_cursig: c_short, + pub pr_sigpend: c_ulong, + pub pr_sighold: c_ulong, + pub pr_pid: pid_t, + pub pr_ppid: pid_t, + pub pr_pgrp: pid_t, + pub pr_sid: pid_t, + pub pr_utime: time, + pub pr_stime: time, + pub pr_cutime: time, + pub pr_cstime: time, + pub pr_reg: elf_gregset_t, + pub pr_fpvalid: c_int, +} + +#[repr(C)] +pub struct elf_prpsinfo { + pub pr_state: c_char, + pub pr_sname: c_char, + pub pr_zomb: c_char, + pub pr_nice: c_char, + pub pr_flag: c_uint, + pub pr_uid: c_uint, + pub pr_gid: c_uint, + pub pr_pid: c_int, + pub pr_ppid: c_int, + pub pr_pgrp: c_int, + pub pr_sid: c_int, + pub pr_fname: [c_char; 16], + pub pr_psargs: [c_char; ELF_PRARGSZ], +} + +pub type psaddr_t = *mut c_void; +pub type prgregset_t = elf_gregset_t; +pub type prfpregset_t = elf_fpregset_t; +pub type lwpid_t = pid_t; +pub type prstatus_t = elf_prstatus; +pub type prpsinfo_t = elf_prpsinfo; + +#[no_mangle] +pub extern "C" fn _cbindgen_only_generates_structs_if_they_are_mentioned_which_is_dumb_procfs( + a: psaddr_t, + b: prgregset_t, + c: prfpregset_t, + d: lwpid_t, + e: prstatus_t, + f: prpsinfo_t, +) { +}