mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-20 08:26:47 +00:00
os2: initial implementation for Darwin&BSDs, process API is only thing incomplete
This commit is contained in:
@@ -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
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
CTL_USER :: 8
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user