actboy168 / bee.lua

Lua runtime and toolset
MIT License
158 stars 30 forks source link

Misuse of NetBSD internal futex syscall: timespec type mismatch #49

Closed riastradh closed 2 months ago

riastradh commented 2 months ago

The NetBSD kernel's futex implementation is not a public interface at the moment -- not recommended to use it until it is actually exposed as a libc stub with a type declaration that will catch mistakes.

But if you really do want to use the syscall via the untyped syscall(SYS___futex) entry, it has to use the actual NetBSD struct timespec which is

struct timespec {
    time_t  tv_sec;     /* seconds */
    long    tv_nsec;    /* and nanoseconds */
};

In particular, tv_sec is time_t, not long. long may be 32-bit or 64-bit depending on platform, but time_t is always 64-bit.

The struct FutexTimespec used here won't work on LP32 platforms:

https://github.com/actboy168/bee.lua/blob/edd93ca5f2436a9cda3e288a5e6abcfdebaaf82f/bee/thread/atomic_sync.cpp#L42-L45

actboy168 commented 2 months ago

What are your suggestions? You can submit a pull request.