Browse Source

Merge branch 'procfs' into 'master'

Implement #include<sys/user.h> and #include<sys/procfs.h>

See merge request redox-os/relibc!266
Jeremy Soller 5 năm trước cách đây
mục cha
commit
a8a73f87c7

+ 11 - 0
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

+ 7 - 0
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

+ 30 - 0
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,
+) {
+}

+ 1 - 1
src/header/sys_user/cbindgen.toml → 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"
 

+ 28 - 1
src/header/sys_user/mod.rs → 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,
 ) {
 }

+ 3 - 1
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;

+ 7 - 0
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

+ 73 - 0
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,
+) {
+}