mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
darwin: remove syscall usage (without -no-crt) to comply to Apple guidelines
This commit is contained in:
@@ -5,11 +5,24 @@ package runtime
|
|||||||
import "base:intrinsics"
|
import "base:intrinsics"
|
||||||
|
|
||||||
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||||
WRITE :: 0x2000004
|
|
||||||
STDERR :: 2
|
STDERR :: 2
|
||||||
ret := intrinsics.syscall(WRITE, STDERR, uintptr(raw_data(data)), uintptr(len(data)))
|
when ODIN_NO_CRT {
|
||||||
if ret < 0 {
|
WRITE :: 0x2000004
|
||||||
return 0, _OS_Errno(-ret)
|
ret := intrinsics.syscall(WRITE, STDERR, uintptr(raw_data(data)), uintptr(len(data)))
|
||||||
|
if ret < 0 {
|
||||||
|
return 0, _OS_Errno(-ret)
|
||||||
|
}
|
||||||
|
return int(ret), 0
|
||||||
|
} else {
|
||||||
|
foreign {
|
||||||
|
write :: proc(handle: i32, buffer: [^]byte, count: uint) -> int ---
|
||||||
|
__error :: proc() -> ^i32 ---
|
||||||
|
}
|
||||||
|
|
||||||
|
if ret := write(STDERR, raw_data(data), len(data)); ret >= 0 {
|
||||||
|
return int(ret), 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, _OS_Errno(__error()^)
|
||||||
}
|
}
|
||||||
return int(ret), 0
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package darwin
|
|||||||
import "core:c"
|
import "core:c"
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
|
// IMPORTANT NOTE: direct syscall usage is not allowed by Apple's review process of apps and should
|
||||||
|
// be entirely avoided in the builtin Odin collections, these are here for users if they don't
|
||||||
|
// care about the Apple review process.
|
||||||
|
|
||||||
// this package uses the sys prefix for the proc names to indicate that these aren't native syscalls but directly call such
|
// this package uses the sys prefix for the proc names to indicate that these aren't native syscalls but directly call such
|
||||||
sys_write_string :: proc (fd: c.int, message: string) -> bool {
|
sys_write_string :: proc (fd: c.int, message: string) -> bool {
|
||||||
return syscall_write(fd, raw_data(message), cast(u64)len(message))
|
return syscall_write(fd, raw_data(message), cast(u64)len(message))
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package darwin
|
package darwin
|
||||||
|
|
||||||
|
// IMPORTANT NOTE: direct syscall usage is not allowed by Apple's review process of apps and should
|
||||||
|
// be entirely avoided in the builtin Odin collections, these are here for users if they don't
|
||||||
|
// care about the Apple review process.
|
||||||
|
|
||||||
unix_offset_syscall :: proc "contextless" (number: System_Call_Number) -> uintptr {
|
unix_offset_syscall :: proc "contextless" (number: System_Call_Number) -> uintptr {
|
||||||
return uintptr(number) + uintptr(0x2000000)
|
return uintptr(number) + uintptr(0x2000000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package darwin
|
|||||||
import "core:c"
|
import "core:c"
|
||||||
import "base:intrinsics"
|
import "base:intrinsics"
|
||||||
|
|
||||||
|
// IMPORTANT NOTE: direct syscall usage is not allowed by Apple's review process of apps and should
|
||||||
|
// be entirely avoided in the builtin Odin collections, these are here for users if they don't
|
||||||
|
// care about the Apple review process.
|
||||||
|
|
||||||
/* flock */
|
/* flock */
|
||||||
LOCK_SH :: 1 /* shared lock */
|
LOCK_SH :: 1 /* shared lock */
|
||||||
LOCK_EX :: 2 /* exclusive lock */
|
LOCK_EX :: 2 /* exclusive lock */
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ init_cpu_features :: proc "contextless" () {
|
|||||||
@(static) features: CPU_Features
|
@(static) features: CPU_Features
|
||||||
defer cpu_features = features
|
defer cpu_features = features
|
||||||
|
|
||||||
try_set :: proc "contextless" (name: string, feature: CPU_Feature) -> (ok: bool) {
|
try_set :: proc "contextless" (name: cstring, feature: CPU_Feature) -> (ok: bool) {
|
||||||
support: b32
|
support: b32
|
||||||
if ok = unix.sysctlbyname(name, &support); ok && support {
|
if ok = unix.sysctlbyname(name, &support); ok && support {
|
||||||
features += { feature }
|
features += { feature }
|
||||||
|
|||||||
@@ -3,29 +3,60 @@ package unix
|
|||||||
|
|
||||||
import "base:intrinsics"
|
import "base:intrinsics"
|
||||||
|
|
||||||
import "core:c"
|
|
||||||
import "core:sys/darwin"
|
import "core:sys/darwin"
|
||||||
|
|
||||||
_ :: darwin
|
_ :: darwin
|
||||||
|
|
||||||
sysctl :: proc "contextless" (mib: []i32, val: ^$T) -> (ok: bool) {
|
sysctl :: proc "contextless" (mib: []i32, val: ^$T) -> (ok: bool) {
|
||||||
result_size := c.size_t(size_of(T))
|
result_size := uint(size_of(T))
|
||||||
res := darwin.syscall_sysctl(
|
when ODIN_NO_CRT {
|
||||||
raw_data(mib), len(mib),
|
res := darwin.syscall_sysctl(
|
||||||
val, &result_size,
|
raw_data(mib), len(mib),
|
||||||
nil, 0,
|
val, &result_size,
|
||||||
)
|
nil, 0,
|
||||||
return res == 0
|
)
|
||||||
|
return res == 0
|
||||||
|
} else {
|
||||||
|
foreign {
|
||||||
|
@(link_name="sysctl") _sysctl :: proc(
|
||||||
|
name: [^]i32, namelen: u32,
|
||||||
|
oldp: rawptr, oldlenp: ^uint,
|
||||||
|
newp: rawptr, newlen: uint,
|
||||||
|
) -> i32 ---
|
||||||
|
}
|
||||||
|
res := _sysctl(
|
||||||
|
raw_data(mib), u32(len(mib)),
|
||||||
|
val, &result_size,
|
||||||
|
nil, 0,
|
||||||
|
)
|
||||||
|
return res == 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sysctlbyname :: proc "contextless" (name: string, val: ^$T) -> (ok: bool) {
|
sysctlbyname :: proc "contextless" (name: cstring, val: ^$T) -> (ok: bool) {
|
||||||
result_size := c.size_t(size_of(T))
|
result_size := uint(size_of(T))
|
||||||
res := darwin.syscall_sysctlbyname(
|
when ODIN_NO_CRT {
|
||||||
name,
|
res := darwin.syscall_sysctlbyname(
|
||||||
val, &result_size,
|
string(name),
|
||||||
nil, 0,
|
val, &result_size,
|
||||||
)
|
nil, 0,
|
||||||
return res == 0
|
)
|
||||||
|
return res == 0
|
||||||
|
} else {
|
||||||
|
foreign {
|
||||||
|
@(link_name="sysctlbyname") _sysctlbyname :: proc(
|
||||||
|
name: cstring,
|
||||||
|
oldp: rawptr, oldlenp: ^uint,
|
||||||
|
newp: rawptr, newlen: uint,
|
||||||
|
) -> i32 ---
|
||||||
|
}
|
||||||
|
res := _sysctlbyname(
|
||||||
|
name,
|
||||||
|
val, &result_size,
|
||||||
|
nil, 0,
|
||||||
|
)
|
||||||
|
return res == 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See sysctl.h for darwin for details
|
// See sysctl.h for darwin for details
|
||||||
|
|||||||
Reference in New Issue
Block a user