diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-01 21:31:30 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-14 01:44:37 +0200 |
| commit | a4d459f6517d23e6dc2129112e99a14ef158a45e (patch) | |
| tree | 554fe29447aa9fad0874e71b406b371a47a7f4a9 /core/sys | |
| parent | ff0ca0bd5388450b357549e33a81489cd2b75158 (diff) | |
os2: initial implementation for Darwin&BSDs, process API is only thing incomplete
Diffstat (limited to 'core/sys')
| -rw-r--r-- | core/sys/darwin/proc.odin | 142 | ||||
| -rw-r--r-- | core/sys/posix/unistd.odin | 9 | ||||
| -rw-r--r-- | core/sys/unix/sysctl_darwin.odin | 4 | ||||
| -rw-r--r-- | core/sys/unix/sysctl_freebsd.odin | 2 |
4 files changed, 153 insertions, 4 deletions
diff --git a/core/sys/darwin/proc.odin b/core/sys/darwin/proc.odin new file mode 100644 index 000000000..a49383670 --- /dev/null +++ b/core/sys/darwin/proc.odin @@ -0,0 +1,142 @@ +package darwin + +import "base:intrinsics" + +import "core:sys/posix" + +foreign import lib "system:System.framework" + +// Incomplete bindings to the proc API on MacOS, add to when needed. + +foreign lib { + proc_pidinfo :: proc(pid: posix.pid_t, flavor: PID_Info_Flavor, arg: i64, buffer: rawptr, buffersize: i32) -> i32 --- + proc_pidpath :: proc(pid: posix.pid_t, buffer: [^]byte, buffersize: u32) -> i32 --- + proc_listallpids :: proc(buffer: [^]i32, buffersize: i32) -> i32 --- +} + +MAXCOMLEN :: 16 + +proc_bsdinfo :: struct { + pbi_flags: PBI_Flags, + pbi_status: u32, + pbi_xstatus: u32, + pbi_pid: u32, + pbi_ppid: u32, + pbi_uid: posix.uid_t, + pbi_gid: posix.gid_t, + pbi_ruid: posix.uid_t, + pbi_rgid: posix.gid_t, + pbi_svuid: posix.uid_t, + pbi_svgid: posix.gid_t, + rfu_1: u32, + pbi_comm: [MAXCOMLEN]byte `fmt:"s,0"`, + pbi_name: [2 * MAXCOMLEN]byte `fmt:"s,0"`, + pbi_nfiles: u32, + pbi_pgid: u32, + pbi_pjobc: u32, + e_tdev: u32, + e_tpgid: u32, + pbi_nice: i32, + pbi_start_tvsec: u64, + pbi_start_tvusec: u64, +} + +proc_bsdshortinfo :: struct { + pbsi_pid: u32, + pbsi_ppid: u32, + pbsi_pgid: u32, + pbsi_status: u32, + pbsi_comm: [MAXCOMLEN]byte `fmt:"s,0"`, + pbsi_flags: PBI_Flags, + pbsi_uid: posix.uid_t, + pbsi_gid: posix.gid_t, + pbsi_ruid: posix.uid_t, + pbsi_rgid: posix.gid_t, + pbsi_svuid: posix.uid_t, + pbsi_svgid: posix.gid_t, + pbsi_rfu: u32, +} + +proc_vnodepathinfo :: struct { + pvi_cdir: vnode_info_path, + pvi_rdir: vnode_info_path, +} + +vnode_info_path :: struct { + vip_vi: vnode_info, + vip_path: [posix.PATH_MAX]byte, +} + +vnode_info :: struct { + vi_stat: vinfo_stat, + vi_type: i32, + vi_pad: i32, + vi_fsid: fsid_t, +} + +vinfo_stat :: struct { + vst_dev: u32, + vst_mode: u16, + vst_nlink: u16, + vst_ino: u64, + vst_uid: posix.uid_t, + vst_gid: posix.gid_t, + vst_atime: i64, + vst_atimensec: i64, + vst_mtime: i64, + vst_mtimensec: i64, + vst_ctime: i64, + vst_ctimensec: i64, + vst_birthtime: i64, + vst_birthtimensec: i64, + vst_size: posix.off_t, + vst_blocks: i64, + vst_blksize: i32, + vst_flags: u32, + vst_gen: u32, + vst_rdev: u32, + vst_qspare: [2]i64, +} + +fsid_t :: distinct [2]i32 + +PBI_Flag_Bits :: enum u32 { + SYSTEM = intrinsics.constant_log2(0x0001), + TRACED = intrinsics.constant_log2(0x0002), + INEXIT = intrinsics.constant_log2(0x0004), + PWAIT = intrinsics.constant_log2(0x0008), + LP64 = intrinsics.constant_log2(0x0010), + SLEADER = intrinsics.constant_log2(0x0020), + CTTY = intrinsics.constant_log2(0x0040), + CONTROLT = intrinsics.constant_log2(0x0080), + THCWD = intrinsics.constant_log2(0x0100), + PC_THROTTLE = intrinsics.constant_log2(0x0200), + PC_SUSP = intrinsics.constant_log2(0x0400), + PC_KILL = intrinsics.constant_log2(0x0600), + PA_THROTTLE = intrinsics.constant_log2(0x0800), + PA_SUSP = intrinsics.constant_log2(0x1000), + PA_PSUGID = intrinsics.constant_log2(0x2000), + EXEC = intrinsics.constant_log2(0x4000), +} +PBI_Flags :: bit_set[PBI_Flag_Bits; u32] + +PID_Info_Flavor :: enum i32 { + LISTFDS = 1, + TASKALLINFO, + BSDINFO, + TASKINFO, + THREADINFO, + LISTTHREADS, + REGIONINFO, + REGIONPATHINFO, + VNODEPATHINFO, + THREADPATHINFO, + PATHINFO, + WORKQUEUEINFO, + SHORTBSDINFO, + LISTFILEPORTS, + THREADID64INFO, + RUSAGE, +} + +PIDPATHINFO_MAXSIZE :: 4*posix.PATH_MAX diff --git a/core/sys/posix/unistd.odin b/core/sys/posix/unistd.odin index 8e08860b4..6ed9e5d11 100644 --- a/core/sys/posix/unistd.odin +++ b/core/sys/posix/unistd.odin @@ -211,7 +211,7 @@ foreign lib { [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/_exit.html ]] */ - _exit :: proc(status: c.int) --- + _exit :: proc(status: c.int) -> ! --- /* The exec family of functions shall replace the current process image with a new process image. @@ -416,8 +416,11 @@ foreign lib { } cwd = posix.getcwd(raw_data(buf), len(buf)) - if errno := posix.errno(); cwd == nil && errno != .ERANGE { - fmt.panicf("getcwd failure: %v", posix.strerror(errno)) + if cwd == nil { + errno := posix.errno() + if errno != .ERANGE { + fmt.panicf("getcwd failure: %v", posix.strerror(errno)) + } } } diff --git a/core/sys/unix/sysctl_darwin.odin b/core/sys/unix/sysctl_darwin.odin index 14d3c113a..92222bdfe 100644 --- a/core/sys/unix/sysctl_darwin.odin +++ b/core/sys/unix/sysctl_darwin.odin @@ -67,6 +67,8 @@ CTL_KERN :: 1 KERN_VERSION :: 4 // Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:darwin-8020.121.3~4/RELEASE_X86_64 KERN_OSRELDATE :: 26 // i32: OS release date KERN_OSVERSION :: 65 // Build number, e.g. 21F79 + KERN_PROCARGS :: 38 + KERN_PROCARGS2 :: 49 CTL_VM :: 2 CTL_VFS :: 3 CTL_NET :: 4 @@ -82,4 +84,4 @@ CTL_HW :: 6 HW_AVAILCPU :: 25 /* int: number of available CPUs */ CTL_MACHDEP :: 7 -CTL_USER :: 8
\ No newline at end of file +CTL_USER :: 8 diff --git a/core/sys/unix/sysctl_freebsd.odin b/core/sys/unix/sysctl_freebsd.odin index 35c5db02c..8ca40ef1b 100644 --- a/core/sys/unix/sysctl_freebsd.odin +++ b/core/sys/unix/sysctl_freebsd.odin @@ -23,6 +23,8 @@ CTL_KERN :: 1 KERN_OSRELEASE :: 2 KERN_OSREV :: 3 KERN_VERSION :: 4 + KERN_PROC :: 14 + KERN_PROC_PATHNAME :: 12 CTL_VM :: 2 CTL_VFS :: 3 CTL_NET :: 4 |