-
-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Haiku OS support #3230
Add Haiku OS support #3230
Conversation
This patch makes Odin to compile on Haiku which is a good first step. Now, all that's needed to do is to figure out how to do futexes, which I am blaming for the program crashing.
This reverts commit 7290c69.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small files looking good, does the futex sim have tests or are they implemented the same as something we got already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest looks fine, good work 👍
} | ||
|
||
@(private="file") | ||
B_GENERAL_ERROR_BASE :: min(i32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do -(1<<31)
instead here to keep it untyped.
core/sync/futex_haiku.odin
Outdated
} | ||
|
||
_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expect: u32, duration: time.Duration) -> bool { | ||
// FIXME: Add timeout! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure that you do! This is necessary for the sync primitives
core/sys/haiku/types.odin
Outdated
phys_addr_t :: u64 when ODIN_ARCH == .amd64 || ODIN_ARCH == .arm64 else u32 | ||
phys_size_t :: phys_addr_t | ||
generic_addr_t :: u64 when ODIN_ARCH == .amd64 || ODIN_ARCH == .arm64 else u32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not uintptr
here?
src/build_settings.cpp
Outdated
global_module_path_set = true; | ||
|
||
|
||
// array_free(&path_buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?
src/threading.cpp
Outdated
|
||
void lock() { | ||
while (spinlock.test_and_set(std::memory_order_acquire)) { | ||
; // spin... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least put a cpu_relax in there of some sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an alternative for this in the compiler codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intrinsics.cpu_relax()
in Odin.
auto head = &waitq->list; | ||
for (auto waiter = head->next; waiter != head; waiter = waiter->next) { | ||
if (waiter->futex == f) { | ||
pthread_kill(waiter->thread, SIGCONT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Haiku not have a distinction between signal and broadcast?
core/sync/futex_haiku.odin
Outdated
package sync | ||
|
||
import "core:c" | ||
import "core:c/libc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use libc here the atomics. package sync has all of the atomics stuff in it already.
core/sync/futex_haiku.odin
Outdated
waitq_lock :: proc "contextless" (waitq: ^Wait_Queue) { | ||
// FIXME: Get rid of context here. | ||
context = runtime.default_context() | ||
for libc.atomic_flag_test_and_set_explicit(&waitq.lock, .acquire) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the atomics built into the language.
core/sync/futex_haiku.odin
Outdated
waitq_unlock :: proc "contextless" (waitq: ^Wait_Queue) { | ||
// FIXME: Get rid of context here. | ||
context = runtime.default_context() | ||
libc.atomic_flag_clear_explicit(&waitq.lock, .release) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the atomics built into the language.
in the future probably native non-pthread implementation for haiku will be required
futex for Haiku was simulated using libc, implementation taken from here https://tavianator.com/2023/futex.html |
core:sync works although has some FIXMEs
core:fmt works
core:sys/haiku is added
generally in Odin Haiku is considered a Unix-like OS, even though technically it is not true
(core:os additions are quite remarkable in their raw quality, albeit being functional enough. As sys/haiku grows, core:os_haiku improves too though)