2222// and the default --- there is no such constraint and the ordinary names are
2323// used, which also avoids the cost the other arrangement pays.
2424
25- #ifndef OKM_STANDALONE
26- #include < pthread.h>
27- #endif
28-
25+ // ⚠️ DECLARED, NOT INCLUDED — AND THAT IS THE SAME RULE THE BRANCH BELOW
26+ // ALREADY FOLLOWS.
27+ //
28+ // `pthread_create_from_mach_thread` has always been declared here rather than
29+ // taken from a header, because no header declares it. The three ordinary names
30+ // were taken from `<pthread.h>`, and that header is this system's SDK — the one
31+ // thing every other implementation in this ecosystem avoids: openkal-linux
32+ // writes the system-call numbers, openkal-opensbi the SBI identifiers,
33+ // openkal-windows the Win32 declarations.
34+ //
35+ // ⚠️ Measured 2026-08-23, building this package ON this system with the target
36+ // side coming from the graph:
37+ //
38+ // …/MacOSX.sdk/usr/include/mach/mach_time.h:61:1:
39+ // error: a type specifier is required for all declarations (× 19)
40+ //
41+ // The SDK's `<pthread.h>` won the search over the C library's in the graph, and
42+ // pulled in a Mach header that its own prerequisites were not there for. On a
43+ // Linux host the same build had taken the graph's copy and said nothing, which
44+ // is why the difference is a HOST difference and shows up only here.
45+ //
46+ // ⭐ `pthread_t` IS A POINTER ON BOTH C LIBRARIES — `struct __pthread*` in musl
47+ // and `struct _opaque_pthread_t*` on this system — so `void*` is the same
48+ // argument at the ABI, which is the level `extern "C"` matches at. The value is
49+ // stored as an integer below in either case.
2950extern " C" {
3051#ifdef OKM_STANDALONE
3152int pthread_create_from_mach_thread (void ** thread, const void * attr,
3253 void * (*start)(void *), void* arg);
54+ #else
55+ int pthread_create (void ** thread, const void * attr,
56+ void * (*start)(void *), void* arg);
57+ int pthread_join (void * thread, void ** value);
3358#endif
3459}
3560
@@ -83,7 +108,7 @@ int kal_task_start(void (*entry)(void*), void* arg, kal_task* out) {
83108 void * thread = nullptr ;
84109 const int rc = pthread_create_from_mach_thread (&thread, nullptr , run, c);
85110#else
86- pthread_t id{} ;
111+ void * id = nullptr ;
87112 const int rc = ::pthread_create (&id, nullptr , run, c);
88113 if (rc == 0 ) c->thread = static_cast <unsigned long >(reinterpret_cast <okm_uptr>(id));
89114#endif
@@ -105,7 +130,8 @@ int kal_task_join(kal_task h) {
105130 reinterpret_cast <okm_long>(const_cast <okm_u32*>(&c->finished )), 0 , 0 );
106131 }
107132#else
108- const int rc = ::pthread_join (reinterpret_cast <pthread_t >(c->thread ), nullptr );
133+ const int rc = ::pthread_join (reinterpret_cast <void *>(
134+ static_cast <okm_uptr>(c->thread )), nullptr );
109135 if (rc != 0 ) return translate_posix (rc);
110136#endif
111137 kal_free (c, sizeof (context), alignof (context));
0 commit comments