From 4cb8b22849ed7c2e2c133280694d0e9e29009f45 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 7 Apr 2026 10:01:34 +0100 Subject: [PATCH] Minor corrections for `core:sys/darwin` --- core/sys/darwin/Foundation/objc.odin | 4 +- core/sys/darwin/Foundation/objc_helper.odin | 35 ++++++++++++++++- core/sys/darwin/copyfile.odin | 1 + core/sys/darwin/mach_darwin.odin | 39 +++++++++++++++++++ core/sys/darwin/proc.odin | 1 + core/sys/darwin/sync.odin | 1 + core/sys/darwin/xnu_system_call_helpers.odin | 1 + core/sys/darwin/xnu_system_call_numbers.odin | 1 + core/sys/darwin/xnu_system_call_wrappers.odin | 1 + 9 files changed, 82 insertions(+), 2 deletions(-) diff --git a/core/sys/darwin/Foundation/objc.odin b/core/sys/darwin/Foundation/objc.odin index 82d6199ce..5e90e106a 100644 --- a/core/sys/darwin/Foundation/objc.odin +++ b/core/sys/darwin/Foundation/objc.odin @@ -7,6 +7,8 @@ foreign import "system:Foundation.framework" import "base:intrinsics" import "core:c" +SELECTOR :: intrinsics.objc_find_selector + IMP :: proc "c" (object: id, sel: SEL, #c_vararg args: ..any) -> id @(default_calling_convention="c") @@ -163,4 +165,4 @@ objc_AssociationPolicy :: enum c.uintptr_t { Copy_Nonatomic = 3, Retain = 01401, Copy = 01403, -} +} \ No newline at end of file diff --git a/core/sys/darwin/Foundation/objc_helper.odin b/core/sys/darwin/Foundation/objc_helper.odin index 0748d700b..84cf01700 100644 --- a/core/sys/darwin/Foundation/objc_helper.odin +++ b/core/sys/darwin/Foundation/objc_helper.odin @@ -17,6 +17,19 @@ Class_VTable_Info :: struct { protocol_vtable: rawptr, } + +Selector_Variant :: union { + SEL, // Selector + cstring, // Selector name +} + +Method_Info :: struct { + method: rawptr, + selector: Selector_Variant, + type_code: string, +} + + @(require_results) class_get_metaclass :: #force_inline proc "contextless" (cls: Class) -> Class { return (^Class)(cls)^ @@ -27,6 +40,12 @@ object_get_vtable_info :: proc "contextless" (obj: id) -> ^Class_VTable_Info { return (^Class_VTable_Info)(object_getIndexedIvars(obj)) } +@(require_results) +object_get_protocol_vtable :: #force_inline proc "contextless" ($T: typeid, obj: id) -> ^T { + info := object_get_vtable_info(obj) + return (^T)(info.protocol_vtable) +} + @(require_results) make_subclasser :: #force_inline proc(vtable: ^$T, impl: proc(cls: Class, vt: ^T)) -> Object_VTable_Info { return Object_VTable_Info{ @@ -133,4 +152,18 @@ alloc_user_object :: proc "contextless" (cls: Class, _context: Maybe(runtime.Con obj_info._context = _context.? } return obj -} \ No newline at end of file +} + +@(require_results) +super_msg_send :: #force_inline proc "contextless" (self: ^$T, $R: typeid, selector: SEL) -> R + where intrinsics.type_is_subtype_of(T, intrinsics.objc_object) { + + msg_sendSuper := (proc "c" (^objc_super, SEL) -> id)(objc_msgSendSuper) + + super := objc_super{ + receiver = self, + super_class = self->superclass() , + } + + return R(msg_sendSuper(&super, selector)) +} diff --git a/core/sys/darwin/copyfile.odin b/core/sys/darwin/copyfile.odin index 6c58b8067..0950d935c 100644 --- a/core/sys/darwin/copyfile.odin +++ b/core/sys/darwin/copyfile.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin import "core:sys/posix" diff --git a/core/sys/darwin/mach_darwin.odin b/core/sys/darwin/mach_darwin.odin index 9520e0e00..f23c2ff45 100644 --- a/core/sys/darwin/mach_darwin.odin +++ b/core/sys/darwin/mach_darwin.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin foreign import mach "system:System" @@ -5,6 +6,44 @@ foreign import mach "system:System" import "core:c" import "base:intrinsics" +HOST_INFO_MAX :: 1024 +HOST_BASIC_INFO :: 1 +HOST_SCHED_INFO :: 3 +HOST_RESOURCE_SIZES :: 4 +HOST_PRIORITY_INFO :: 5 +HOST_SEMAPHORE_TRAPS :: 7 +HOST_MACH_MSG_TRAP :: 8 +HOST_VM_PURGABLE :: 9 +HOST_DEBUG_INFO_INTERNAL :: 10 +HOST_CAN_HAS_DEBUGGER :: 11 +HOST_PREFERRED_USER_ARCH :: 12 +HOST_CAN_HAS_DEBUGGER_COUNT :: 1 +HOST_BASIC_INFO_COUNT :: 12 +HOST_SCHED_INFO_COUNT :: 2 +HOST_RESOURCE_SIZES_COUNT :: 5 +HOST_PRIORITY_INFO_COUNT :: 8 +HOST_LOAD_INFO :: 1 +HOST_VM_INFO :: 2 +HOST_CPU_LOAD_INFO :: 3 +HOST_VM_INFO64 :: 4 +HOST_EXTMOD_INFO64 :: 5 +HOST_EXPIRED_TASK_INFO :: 6 +HOST_LOAD_INFO_COUNT :: 6 +HOST_VM_PURGABLE_COUNT :: 68 +HOST_VM_INFO64_COUNT :: 38 +HOST_VM_INFO64_LATEST_COUNT :: 38 +HOST_VM_INFO64_REV1_COUNT :: 38 +HOST_VM_INFO64_REV0_COUNT :: 24 +HOST_EXTMOD_INFO64_COUNT :: 12 +HOST_EXTMOD_INFO64_LATEST_COUNT :: 12 +HOST_VM_INFO_COUNT :: 15 +HOST_VM_INFO_LATEST_COUNT :: 15 +HOST_VM_INFO_REV2_COUNT :: 15 +HOST_VM_INFO_REV1_COUNT :: 14 +HOST_VM_INFO_REV0_COUNT :: 12 +HOST_CPU_LOAD_INFO_COUNT :: 4 +HOST_PREFERRED_USER_ARCH_COUNT :: 2 + mach_port_t :: distinct c.uint task_t :: mach_port_t diff --git a/core/sys/darwin/proc.odin b/core/sys/darwin/proc.odin index ccd05f478..9e510dfaa 100644 --- a/core/sys/darwin/proc.odin +++ b/core/sys/darwin/proc.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin import "base:intrinsics" diff --git a/core/sys/darwin/sync.odin b/core/sys/darwin/sync.odin index 5f4f16fc3..d1f676b1f 100644 --- a/core/sys/darwin/sync.odin +++ b/core/sys/darwin/sync.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin // #define OS_WAIT_ON_ADDR_AVAILABILITY \ diff --git a/core/sys/darwin/xnu_system_call_helpers.odin b/core/sys/darwin/xnu_system_call_helpers.odin index ae8373f99..d7ea69ed6 100644 --- a/core/sys/darwin/xnu_system_call_helpers.odin +++ b/core/sys/darwin/xnu_system_call_helpers.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin import "core:c" diff --git a/core/sys/darwin/xnu_system_call_numbers.odin b/core/sys/darwin/xnu_system_call_numbers.odin index 00ab75a15..f26e2a9bd 100644 --- a/core/sys/darwin/xnu_system_call_numbers.odin +++ b/core/sys/darwin/xnu_system_call_numbers.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin // IMPORTANT NOTE: direct syscall usage is not allowed by Apple's review process of apps and should diff --git a/core/sys/darwin/xnu_system_call_wrappers.odin b/core/sys/darwin/xnu_system_call_wrappers.odin index 43bcb543b..06f377af1 100644 --- a/core/sys/darwin/xnu_system_call_wrappers.odin +++ b/core/sys/darwin/xnu_system_call_wrappers.odin @@ -1,3 +1,4 @@ +#+build darwin package darwin import "core:c"