Skip to content

Commit 23ae9df

Browse files
committed
Add NetBSD support
1 parent 2fdc19e commit 23ae9df

File tree

4,020 files changed

+9104
-8277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,020 files changed

+9104
-8277
lines changed

README.md

Lines changed: 1 addition & 1 deletion

ape/ape.S

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ ape.phdrs:
518518
.quad 0 # p_memsz
519519
.quad 16 # p_align
520520
.align __SIZEOF_POINTER__
521-
.long PT_NOTE # openbsd note
521+
.long PT_NOTE # notes
522522
.long PF_R
523523
.stub .Lape.note.offset,quad
524524
.stub .Lape.note.vaddr,quad
@@ -530,15 +530,28 @@ ape.phdrs:
530530

531531
.section .note.openbsd.ident,"a",@progbits
532532
.Lopenbsd.ident:
533-
.long 8
534-
.long 4
535-
.long 0x1
536-
.asciz "OpenBSD"
537-
.long 0
538-
.size .Lopenbsd.ident,.-.Lopenbsd.ident
533+
.long 2f-1f
534+
.long 4f-3f
535+
.long 1
536+
1: .asciz "OpenBSD"
537+
2: .align 4
538+
3: .long 0
539+
4: .size .Lopenbsd.ident,.-.Lopenbsd.ident
539540
.type .Lopenbsd.ident,@object
540541
.previous
541542

543+
.section .note.netbsd.ident,"a",@progbits
544+
.Lnetbsd.ident:
545+
.long 2f-1f
546+
.long 4f-3f
547+
.long 1
548+
1: .asciz "NetBSD"
549+
2: .align 4
550+
3: .long 901000000
551+
4: .size .Lnetbsd.ident,.-.Lnetbsd.ident
552+
.type .Lnetbsd.ident,@object
553+
.previous
554+
542555
/* ▄▄███▄
543556
▄▄████████▄
544557
▄█████████████▄

ape/ape.lds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ SECTIONS {
227227
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 1);
228228
HIDDEN(.Lape.note = .);
229229
KEEP(*(.note.openbsd.ident))
230+
KEEP(*(.note.netbsd.ident))
230231
HIDDEN(.Lape.note.end = .);
231232
. += 1;
232233

libc/calls/stat2linux.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ static textstartup void __stat2linux_openbsd(union metastat *ms) {
7070
st_ctim);
7171
}
7272

73+
static textstartup void __stat2linux_netbsd(union metastat *ms) {
74+
SWITCHEROO(ms->netbsd, ms->linux, st_dev, st_ino, st_nlink, st_mode, st_uid,
75+
st_gid, st_rdev, st_size, st_blksize, st_blocks, st_atim, st_mtim,
76+
st_ctim);
77+
}
78+
7379
/**
7480
* Transcodes “The Dismal Data Structure” from BSD→Linux ABI.
7581
* @asyncsignalsafe
@@ -82,6 +88,8 @@ textstartup void __stat2linux(void *ms) {
8288
__stat2linux_freebsd((union metastat *)ms);
8389
} else if (SupportsOpenbsd() && IsOpenbsd()) {
8490
__stat2linux_openbsd((union metastat *)ms);
91+
} else if (SupportsNetbsd() && IsNetbsd()) {
92+
__stat2linux_netbsd((union metastat *)ms);
8593
}
8694
}
8795
}

libc/calls/struct/metastat.internal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,24 @@ struct stat_openbsd {
4747
struct timespec __st_birthtim;
4848
};
4949

50+
struct stat_netbsd {
51+
uint64_t st_dev;
52+
uint32_t st_mode;
53+
uint64_t st_ino;
54+
uint32_t st_nlink, st_uid, st_gid;
55+
uint64_t st_rdev;
56+
struct timespec st_atim, st_mtim, st_ctim, st_birthtim;
57+
int64_t st_size, st_blocks;
58+
int32_t st_blksize;
59+
uint32_t st_flags, st_gen, st_spare[2];
60+
};
61+
5062
union metastat {
5163
struct stat linux;
5264
struct stat_xnu xnu;
5365
struct stat_freebsd freebsd;
5466
struct stat_openbsd openbsd;
67+
struct stat_netbsd netbsd;
5568
};
5669

5770
COSMOPOLITAN_C_END_

libc/calls/struct/sigaction-netbsd.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_NETBSD_H_
2+
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_NETBSD_H_
3+
#if !(__ASSEMBLER__ + __LINKER__ + 0)
4+
COSMOPOLITAN_C_START_
5+
6+
struct sigset_netbsd {
7+
uint32_t sig[4];
8+
};
9+
10+
struct sigaction_netbsd {
11+
intptr_t sa_handler;
12+
struct sigset_netbsd sa_mask;
13+
uint32_t sa_flags;
14+
};
15+
16+
COSMOPOLITAN_C_END_
17+
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
18+
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_NETBSD_H_ */

libc/dce.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@
88
#ifndef SUPPORT_VECTOR
99
/**
1010
* Supported Platforms Tuning Knob (Runtime & Compile-Time)
11-
*
12-
* Cosmopolitan's design allows us to support eight platforms. We enable
13-
* them all by default, since we're able to do eight so efficiently. We
14-
* can't do more, due to the way the 80x86 instruction set is encoded.
15-
*
16-
* The user may optionally tune this bitmask, which effectively asks the
17-
* compiler to leave out system call polyfills for a platform, which may
18-
* offer marginal improvements in terms of code size and performance, at
19-
* the cost of portability.
11+
* Tuning this bitmask will remove platform polyfills at compile-time.
2012
*/
2113
#define SUPPORT_VECTOR 0b11111111
2214
#endif
15+
2316
#define LINUX 1
2417
#define METAL 2
2518
#define WINDOWS 4
2619
#define XNU 8
2720
#define OPENBSD 16
2821
#define FREEBSD 32
29-
/* #define YOUR_CLOUD_PLATFORM_HERE 64 /\* [email protected] *\/ */
30-
/* #define YOUR_CLOUD_PLATFORM_HERE 128 /\* [email protected] *\/ */
22+
#define NETBSD 64
3123

3224
#ifdef NDEBUG
3325
#define NoDebug() 1
@@ -89,28 +81,31 @@
8981
#define SupportsXnu() ((SUPPORT_VECTOR & XNU) == XNU)
9082
#define SupportsFreebsd() ((SUPPORT_VECTOR & FREEBSD) == FREEBSD)
9183
#define SupportsOpenbsd() ((SUPPORT_VECTOR & OPENBSD) == OPENBSD)
92-
#define SupportsBsd() (!!(SUPPORT_VECTOR & (XNU | FREEBSD | OPENBSD)))
84+
#define SupportsNetbsd() ((SUPPORT_VECTOR & NETBSD) == NETBSD)
85+
#define SupportsBsd() (!!(SUPPORT_VECTOR & (XNU | FREEBSD | OPENBSD | NETBSD)))
9386
#define SupportsSystemv() \
94-
((SUPPORT_VECTOR & (LINUX | METAL | XNU | OPENBSD | FREEBSD)) != 0)
87+
((SUPPORT_VECTOR & (LINUX | METAL | XNU | OPENBSD | FREEBSD | NETBSD)) != 0)
9588

9689
#ifndef __ASSEMBLER__
9790
#define __HOSTOS (__hostos & SUPPORT_VECTOR)
9891
#define IsLinux() ((__HOSTOS & LINUX) == LINUX)
9992
#define IsMetal() ((__HOSTOS & METAL) == METAL)
10093
#define IsWindows() ((__HOSTOS & WINDOWS) == WINDOWS)
101-
#define IsBsd() ((__HOSTOS & (XNU | FREEBSD | OPENBSD)) != 0)
94+
#define IsBsd() ((__HOSTOS & (XNU | FREEBSD | OPENBSD | NETBSD)) != 0)
10295
#define IsXnu() ((__HOSTOS & XNU) == XNU)
10396
#define IsFreebsd() ((__HOSTOS & FREEBSD) == FREEBSD)
10497
#define IsOpenbsd() ((__HOSTOS & OPENBSD) == OPENBSD)
98+
#define IsNetbsd() ((__HOSTOS & NETBSD) == NETBSD)
10599
#else
106100
/* clang-format off */
107101
#define IsLinux() $LINUX,__hostos(%rip)
108102
#define IsMetal() $METAL,__hostos(%rip)
109103
#define IsWindows() $WINDOWS,__hostos(%rip)
110-
#define IsBsd() $XNU|FREEBSD|OPENBSD,__hostos(%rip)
104+
#define IsBsd() $XNU|FREEBSD|OPENBSD|NETBSD,__hostos(%rip)
111105
#define IsXnu() $XNU,__hostos(%rip)
112106
#define IsFreebsd() $FREEBSD,__hostos(%rip)
113107
#define IsOpenbsd() $OPENBSD,__hostos(%rip)
108+
#define IsNetbsd() $NETBSD,__hostos(%rip)
114109
/* clang-format on */
115110
#endif
116111

libc/fmt/pflink.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ static long __pflink(long x) {
8888
x |= kCp437[0];
8989
x |= ntoa(0, 0, 0, 0, 0, 0, 0, 0, 0);
9090
x |= ftoa(0, 0, 0, 0, 0, 0);
91-
x |= strnwidth(0, 0);
92-
x |= strnwidth16(0, 0);
93-
x |= wcsnwidth(0, 0);
91+
x |= strnwidth(0, 0, 0);
92+
x |= strnwidth16(0, 0, 0);
93+
x |= wcsnwidth(0, 0, 0);
9494
x |= malloc(0);
9595
x |= __grow(0, 0, 0, 0);
9696
x |= (intptr_t)strerror(0);

libc/fmt/stoa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ int stoa(int out(long, void *), void *arg, void *data, unsigned long flags,
144144
w = precision;
145145
if (signbit == 63) {
146146
if (weaken(wcsnwidth)) {
147-
w = weaken(wcsnwidth)((const wchar_t *)p, precision);
147+
w = weaken(wcsnwidth)((const wchar_t *)p, precision, 0);
148148
}
149149
} else if (signbit == 15) {
150150
if (weaken(strnwidth16)) {
151-
w = weaken(strnwidth16)((const char16_t *)p, precision);
151+
w = weaken(strnwidth16)((const char16_t *)p, precision, 0);
152152
}
153153
} else if (weaken(strnwidth)) {
154-
w = weaken(strnwidth)(p, precision);
154+
w = weaken(strnwidth)(p, precision, 0);
155155
}
156156
if (w < width) {
157157
pad = width - w;

libc/str/strncat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
1717
│ PERFORMANCE OF THIS SOFTWARE. │
1818
╚─────────────────────────────────────────────────────────────────────────────*/
19-
#include "libc/macros.h"
2019
#include "libc/str/str.h"
2120

2221
/**

0 commit comments

Comments
 (0)