Skip to content

Commit 49ce41c

Browse files
committed
libc: gate aarch64 atomic.h kernel-only includes so ZFS userspace builds
libc/arch/aarch64/atomic.h pulls in OSv kernel-only headers (the FreeBSD-derived machine/atomic.h and the bsd/cddl opensolaris sys/types.h), which are only on the include path for kernel/bsd objects. Userspace translation units that resolve <atomic.h> to this file (the OpenZFS libspl/libzfs sources on aarch64) do not have them and do not need them. Gate those includes on the kernel build and use the compiler atomic builtin in the userspace path. The x86_64 variant has no such includes, so this is aarch64-only and leaves x86_64 byte-identical.
1 parent 73f1e53 commit 49ce41c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

libc/arch/aarch64/atomic.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@
99
#define _INTERNAL_ATOMIC_H
1010

1111
#include <stdint.h>
12+
/*
13+
* These two headers pull in OSv kernel-only machinery (the FreeBSD-derived
14+
* machine/atomic.h and the old bsd/cddl opensolaris sys/types.h). They are only
15+
* on the include path for kernel/bsd objects. Userspace translation units that
16+
* resolve <atomic.h> to this file (e.g. the OpenZFS libspl/libzfs sources on
17+
* aarch64) do not have them available and do not need them, so gate them on the
18+
* kernel build. The x64 variant of this file has no such includes; this change
19+
* is aarch64-only and leaves the x86_64 build byte-identical.
20+
*/
21+
#if defined(_KERNEL) || defined(__OSV_CORE__)
1222
#include <bsd/sys/cddl/compat/opensolaris/sys/types.h>
1323
#include <machine/atomic.h>
24+
#endif
1425

1526
static inline int a_ctz_64(register uint64_t x)
1627
{
@@ -26,7 +37,12 @@ static inline int a_ctz_l(unsigned long x)
2637

2738
static inline int a_fetch_add(volatile int *x, int v)
2839
{
40+
#if defined(_KERNEL) || defined(__OSV_CORE__)
2941
return atomic_fetchadd_int((unsigned int *)x, (unsigned int)v);
42+
#else
43+
/* Userspace: machine/atomic.h is unavailable; use the LSE/LL-SC builtin. */
44+
return __atomic_fetch_add(x, v, __ATOMIC_SEQ_CST);
45+
#endif
3046
}
3147

3248
static inline void a_crash()

0 commit comments

Comments
 (0)