authorgravatar for p@scene.clalter <p@scene.cl> 2016-09-12 01:01:06-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-14 02:46:02-04:00
logcf9b21c09fc641b4697e06981ac5114a8d3d09ab
treea69ab92c864c8807209eb09214b868bf8cce39ec
parent06f2f4d64b63cf78a3ff77cc64dbc822123f454d

MacOSX compatibility

- Implemented some syscall for MacOSX - tested on : El Capitan 10.11 x86_64 - make self hosted test run on macosx - modified run_test so it does not fail when parseh throws warnings (most of them are related to buildin types from gcc that arent defined in header files and unions) - making -mmacosx-version-min and -mios-version-min works like gcc (command line paramers have precedence over enviroment variables)

11 files changed, 285 insertions(+), 51 deletions(-)

CMakeLists.txt+2
...@@ -213,6 +213,8 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}")...@@ -213,6 +213,8 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}")
213install(FILES "${CMAKE_SOURCE_DIR}/std/linux.zig" DESTINATION "${ZIG_STD_DEST}")213install(FILES "${CMAKE_SOURCE_DIR}/std/linux.zig" DESTINATION "${ZIG_STD_DEST}")
214install(FILES "${CMAKE_SOURCE_DIR}/std/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}")214install(FILES "${CMAKE_SOURCE_DIR}/std/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}")
215install(FILES "${CMAKE_SOURCE_DIR}/std/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}")215install(FILES "${CMAKE_SOURCE_DIR}/std/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}")
216install(FILES "${CMAKE_SOURCE_DIR}/std/darwin.zig" DESTINATION "${ZIG_STD_DEST}")
217install(FILES "${CMAKE_SOURCE_DIR}/std/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}")
216install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}")218install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}")
217install(FILES "${CMAKE_SOURCE_DIR}/std/math.zig" DESTINATION "${ZIG_STD_DEST}")219install(FILES "${CMAKE_SOURCE_DIR}/std/math.zig" DESTINATION "${ZIG_STD_DEST}")
218install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}")220install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}")
src/codegen.cpp+7-2
...@@ -42,9 +42,14 @@ static void init_darwin_native(CodeGen *g) {...@@ -42,9 +42,14 @@ static void init_darwin_native(CodeGen *g) {
42 g->mmacosx_version_min = buf_create_from_str(osx_target);42 g->mmacosx_version_min = buf_create_from_str(osx_target);
43 } else if (ios_target) {43 } else if (ios_target) {
44 g->mios_version_min = buf_create_from_str(ios_target);44 g->mios_version_min = buf_create_from_str(ios_target);
45 } else {
46 zig_panic("unable to determine -mmacosx-version-min or -mios-version-min");
47 }45 }
46
47 // we should check for the command line option to throw an error if not specified
48 //
49
50 /* else {
51 zig_panic("unable to determine -mmacosx-version-min or -mios-version-min");
52 } */
48}53}
4954
50static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) {55static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) {
src/link.cpp+6
...@@ -643,6 +643,12 @@ static void construct_linker_job_darwin(LinkJob *lj) {...@@ -643,6 +643,12 @@ static void construct_linker_job_darwin(LinkJob *lj) {
643643
644 lj->args.append((const char *)buf_ptr(&lj->out_file_o));644 lj->args.append((const char *)buf_ptr(&lj->out_file_o));
645645
646 if (g->is_test_build) {
647 const char *test_runner_name = g->link_libc ? "test_runner_libc" : "test_runner_nolibc";
648 Buf *test_runner_o_path = build_o(g, test_runner_name);
649 lj->args.append(buf_ptr(test_runner_o_path));
650 }
651
646 for (int i = 0; i < g->link_libs.length; i += 1) {652 for (int i = 0; i < g->link_libs.length; i += 1) {
647 Buf *link_lib = g->link_libs.at(i);653 Buf *link_lib = g->link_libs.at(i);
648 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));654 Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib));
src/main.cpp+12
...@@ -388,9 +388,21 @@ int main(int argc, char **argv) {...@@ -388,9 +388,21 @@ int main(int argc, char **argv) {
388 fprintf(stderr, "-mmacosx-version-min and -mios-version-min options not allowed together\n");388 fprintf(stderr, "-mmacosx-version-min and -mios-version-min options not allowed together\n");
389 return EXIT_FAILURE;389 return EXIT_FAILURE;
390 }390 }
391
392 if((g->zig_target.os == ZigLLVM_Darwin ||
393 g->zig_target.os == ZigLLVM_MacOSX ||
394 g->zig_target.os == ZigLLVM_IOS) &&
395 (!mmacosx_version_min &&
396 !mios_version_min &&
397 !g->mmacosx_version_min &&
398 !g->mios_version_min) && target) {
399 zig_panic("unable to determine -mmacosx-version-min or -mios-version-min");
400 }
401
391 if (mmacosx_version_min) {402 if (mmacosx_version_min) {
392 codegen_set_mmacosx_version_min(g, buf_create_from_str(mmacosx_version_min));403 codegen_set_mmacosx_version_min(g, buf_create_from_str(mmacosx_version_min));
393 }404 }
405
394 if (mios_version_min) {406 if (mios_version_min) {
395 codegen_set_mios_version_min(g, buf_create_from_str(mios_version_min));407 codegen_set_mios_version_min(g, buf_create_from_str(mios_version_min));
396 }408 }
std/darwin.zig created+110
...@@ -0,0 +1,110 @@
1
2const arch = switch (@compileVar("arch")) {
3 x86_64 => @import("darwin_x86_64.zig"),
4 else => @compile_err("unsupported arch"),
5};
6
7const errno = @import("errno.zig");
8
9pub const O_LARGEFILE = 0x0000;
10pub const O_RDONLY = 0x0000;
11
12pub const SEEK_SET = 0x0;
13pub const SEEK_CUR = 0x1;
14pub const SEEK_END = 0x2;
15
16pub const SIGHUP = 1;
17pub const SIGINT = 2;
18pub const SIGQUIT = 3;
19pub const SIGILL = 4;
20pub const SIGTRAP = 5;
21pub const SIGABRT = 6;
22pub const SIGIOT = SIGABRT;
23pub const SIGBUS = 7;
24pub const SIGFPE = 8;
25pub const SIGKILL = 9;
26pub const SIGUSR1 = 10;
27pub const SIGSEGV = 11;
28pub const SIGUSR2 = 12;
29pub const SIGPIPE = 13;
30pub const SIGALRM = 14;
31pub const SIGTERM = 15;
32pub const SIGSTKFLT = 16;
33pub const SIGCHLD = 17;
34pub const SIGCONT = 18;
35pub const SIGSTOP = 19;
36pub const SIGTSTP = 20;
37pub const SIGTTIN = 21;
38pub const SIGTTOU = 22;
39pub const SIGURG = 23;
40pub const SIGXCPU = 24;
41pub const SIGXFSZ = 25;
42pub const SIGVTALRM = 26;
43pub const SIGPROF = 27;
44pub const SIGWINCH = 28;
45pub const SIGIO = 29;
46pub const SIGPOLL = 29;
47pub const SIGPWR = 30;
48pub const SIGSYS = 31;
49pub const SIGUNUSED = SIGSYS;
50
51/// Get the errno from a syscall return value, or 0 for no error.
52pub fn getErrno(r: usize) -> usize {
53 const signed_r = *(&isize)(&r);
54 if (signed_r > -4096 && signed_r < 0) usize(-signed_r) else 0
55}
56
57pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
58 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
59}
60
61pub fn close(fd: i32) -> usize {
62 arch.syscall1(arch.SYS_close, usize(fd))
63}
64
65pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
66 arch.syscall3(arch.SYS_open, usize(path), flags, perm)
67}
68
69pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
70 var buf: [path.len + 1]u8 = undefined;
71 @memcpy(&buf[0], &path[0], path.len);
72 buf[path.len] = 0;
73 return open_c(buf.ptr, flags, perm);
74}
75
76pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
77 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
78}
79
80pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
81 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
82}
83
84pub const stat = arch.stat;
85pub const timespec = arch.timespec;
86
87pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
88 arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
89}
90
91pub error Unexpected;
92
93pub fn getrandom(buf: &u8, count: usize) -> usize {
94 const rr = open_c(c"/dev/urandom", O_LARGEFILE | O_RDONLY, 0);
95
96 if(getErrno(rr) > 0) return rr;
97
98 var fd: i32 = i32(rr);
99 const readRes = read(fd, buf, count);
100 readRes
101}
102
103pub fn raise(sig: i32) -> i32 {
104 //var set: sigset_t = undefined;
105 //blockAppSignals(&set);
106 const pid = i32(arch.syscall0(arch.SYS_getpid));
107 const ret = i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)));
108 //restoreSignals(&set);
109 return ret;
110}
std/darwin_x86_64.zig created+86
...@@ -0,0 +1,86 @@
1
2pub const SYSCALL_CLASS_SHIFT = 24;
3pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT;
4// pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet
5
6pub const SYSCALL_CLASS_NONE = 0; // Invalid
7pub const SYSCALL_CLASS_MACH = 1; // Mach
8pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD
9pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent
10pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
11
12// TODO: use the above constants to create the below values
13
14pub const SYS_read = 0x2000003;
15pub const SYS_write = 0x2000004;
16pub const SYS_open = 0x2000005;
17pub const SYS_close = 0x2000006;
18pub const SYS_kill = 0x2000025;
19pub const SYS_getpid = 0x2000030;
20pub const SYS_fstat = 0x20000BD;
21pub const SYS_lseek = 0x20000C7;
22
23pub inline fn syscall0(number: usize) -> usize {
24 asm volatile ("syscall"
25 : [ret] "={rax}" (-> usize)
26 : [number] "{rax}" (number)
27 : "rcx", "r11")
28}
29
30pub inline fn syscall1(number: usize, arg1: usize) -> usize {
31 asm volatile ("syscall"
32 : [ret] "={rax}" (-> usize)
33 : [number] "{rax}" (number),
34 [arg1] "{rdi}" (arg1)
35 : "rcx", "r11")
36}
37
38pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
39 asm volatile ("syscall"
40 : [ret] "={rax}" (-> usize)
41 : [number] "{rax}" (number),
42 [arg1] "{rdi}" (arg1),
43 [arg2] "{rsi}" (arg2)
44 : "rcx", "r11")
45}
46
47pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
48 asm volatile ("syscall"
49 : [ret] "={rax}" (-> usize)
50 : [number] "{rax}" (number),
51 [arg1] "{rdi}" (arg1),
52 [arg2] "{rsi}" (arg2),
53 [arg3] "{rdx}" (arg3)
54 : "rcx", "r11")
55}
56
57
58
59
60export struct stat {
61 dev: u32,
62 mode: u16,
63 nlink: u16,
64 ino: u64,
65 uid: u32,
66 gid: u32,
67 rdev: u64,
68
69 atim: timespec,
70 mtim: timespec,
71 ctim: timespec,
72
73 size: u64,
74 blocks: u64,
75 blksize: u32,
76 flags: u32,
77 gen: u32,
78 lspare: i32,
79 qspare: [2]u64,
80
81}
82
83export struct timespec {
84 tv_sec: isize,
85 tv_nsec: isize,
86}
std/debug.zig+1-1
...@@ -49,7 +49,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void {...@@ -49,7 +49,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void {
49 out_stream.write("(stack trace unavailable for COFF object format)\n");49 out_stream.write("(stack trace unavailable for COFF object format)\n");
50 },50 },
51 macho => {51 macho => {
52 out_stream.write("(stack trace unavailable for Mach-O object format)\n");52 %return out_stream.write("(stack trace unavailable for Mach-O object format)\n");
53 },53 },
54 unknown => {54 unknown => {
55 out_stream.write("(stack trace unavailable for unknown object format)\n");55 out_stream.write("(stack trace unavailable for unknown object format)\n");
std/index.zig+4-1
...@@ -13,5 +13,8 @@ pub const linux = switch(@compileVar("os")) {...@@ -13,5 +13,8 @@ pub const linux = switch(@compileVar("os")) {
13 linux => @import("linux.zig"),13 linux => @import("linux.zig"),
14 else => null_import,14 else => null_import,
15};15};
1616pub const darwin = switch(@compileVar("os")) {
17 darwin => @import("darwin.zig"),
18 else => null_import,
19};
17const null_import = @import("empty.zig");20const null_import = @import("empty.zig");
std/io.zig+32-27
...@@ -1,4 +1,9 @@...@@ -1,4 +1,9 @@
1const linux = @import("linux.zig");1const system = switch(@compileVar("os")) {
2 linux => @import("linux.zig"),
3 darwin => @import("darwin.zig"),
4 else => @compileError("Unsupported OS"),
5};
6
2const errno = @import("errno.zig");7const errno = @import("errno.zig");
3const math = @import("math.zig");8const math = @import("math.zig");
4const endian = @import("endian.zig");9const endian = @import("endian.zig");
...@@ -110,12 +115,11 @@ pub struct OutStream {...@@ -110,12 +115,11 @@ pub struct OutStream {
110115
111 pub fn flush(os: &OutStream) -> %void {116 pub fn flush(os: &OutStream) -> %void {
112 while (true) {117 while (true) {
113 const write_ret = linux.write(os.fd, &os.buffer[0], os.index);118 const write_ret = system.write(os.fd, &os.buffer[0], os.index);
114 const write_err = linux.getErrno(write_ret);119 const write_err = system.getErrno(write_ret);
115 if (write_err > 0) {120 if (write_err > 0) {
116 return switch (write_err) {121 return switch (write_err) {
117 errno.EINTR => continue,122 errno.EINTR => continue,
118
119 errno.EINVAL => @unreachable(),123 errno.EINVAL => @unreachable(),
120 errno.EDQUOT => error.DiskQuota,124 errno.EDQUOT => error.DiskQuota,
121 errno.EFBIG => error.FileTooBig,125 errno.EFBIG => error.FileTooBig,
...@@ -133,8 +137,8 @@ pub struct OutStream {...@@ -133,8 +137,8 @@ pub struct OutStream {
133137
134 pub fn close(os: &OutStream) -> %void {138 pub fn close(os: &OutStream) -> %void {
135 while (true) {139 while (true) {
136 const close_ret = linux.close(os.fd);140 const close_ret = system.close(os.fd);
137 const close_err = linux.getErrno(close_ret);141 const close_err = system.getErrno(close_ret);
138 if (close_err > 0) {142 if (close_err > 0) {
139 return switch (close_err) {143 return switch (close_err) {
140 errno.EINTR => continue,144 errno.EINTR => continue,
...@@ -157,10 +161,10 @@ pub struct InStream {...@@ -157,10 +161,10 @@ pub struct InStream {
157 /// Call close to clean up.161 /// Call close to clean up.
158 pub fn open(is: &InStream, path: []const u8) -> %void {162 pub fn open(is: &InStream, path: []const u8) -> %void {
159 switch (@compileVar("os")) {163 switch (@compileVar("os")) {
160 linux => {164 linux, darwin => {
161 while (true) {165 while (true) {
162 const result = linux.open(path, linux.O_LARGEFILE|linux.O_RDONLY, 0);166 const result = system.open(path, system.O_LARGEFILE|system.O_RDONLY, 0);
163 const err = linux.getErrno(result);167 const err = system.getErrno(result);
164 if (err > 0) {168 if (err > 0) {
165 return switch (err) {169 return switch (err) {
166 errno.EINTR => continue,170 errno.EINTR => continue,
...@@ -189,16 +193,17 @@ pub struct InStream {...@@ -189,16 +193,17 @@ pub struct InStream {
189 },193 },
190 else => @compileError("unsupported OS"),194 else => @compileError("unsupported OS"),
191 }195 }
196
192 }197 }
193198
194 /// Upon success, the stream is in an uninitialized state. To continue using it,199 /// Upon success, the stream is in an uninitialized state. To continue using it,
195 /// you must use the open() function.200 /// you must use the open() function.
196 pub fn close(is: &InStream) -> %void {201 pub fn close(is: &InStream) -> %void {
197 switch (@compileVar("os")) {202 switch (@compileVar("os")) {
198 linux => {203 linux, darwin => {
199 while (true) {204 while (true) {
200 const close_ret = linux.close(is.fd);205 const close_ret = system.close(is.fd);
201 const close_err = linux.getErrno(close_ret);206 const close_err = system.getErrno(close_ret);
202 if (close_err > 0) {207 if (close_err > 0) {
203 return switch (close_err) {208 return switch (close_err) {
204 errno.EINTR => continue,209 errno.EINTR => continue,
...@@ -219,11 +224,11 @@ pub struct InStream {...@@ -219,11 +224,11 @@ pub struct InStream {
219 /// the stream reached End Of File.224 /// the stream reached End Of File.
220 pub fn read(is: &InStream, buf: []u8) -> %usize {225 pub fn read(is: &InStream, buf: []u8) -> %usize {
221 switch (@compileVar("os")) {226 switch (@compileVar("os")) {
222 linux => {227 linux, darwin => {
223 var index: usize = 0;228 var index: usize = 0;
224 while (index < buf.len) {229 while (index < buf.len) {
225 const amt_read = linux.read(is.fd, &buf[index], buf.len - index);230 const amt_read = system.read(is.fd, &buf[index], buf.len - index);
226 const read_err = linux.getErrno(amt_read);231 const read_err = system.getErrno(amt_read);
227 if (read_err > 0) {232 if (read_err > 0) {
228 switch (read_err) {233 switch (read_err) {
229 errno.EINTR => continue,234 errno.EINTR => continue,
...@@ -287,9 +292,9 @@ pub struct InStream {...@@ -287,9 +292,9 @@ pub struct InStream {
287292
288 pub fn seekForward(is: &InStream, amount: usize) -> %void {293 pub fn seekForward(is: &InStream, amount: usize) -> %void {
289 switch (@compileVar("os")) {294 switch (@compileVar("os")) {
290 linux => {295 linux, darwin => {
291 const result = linux.lseek(is.fd, amount, linux.SEEK_CUR);296 const result = system.lseek(is.fd, amount, system.SEEK_CUR);
292 const err = linux.getErrno(result);297 const err = system.getErrno(result);
293 if (err > 0) {298 if (err > 0) {
294 return switch (err) {299 return switch (err) {
295 errno.EBADF => error.BadFd,300 errno.EBADF => error.BadFd,
...@@ -307,9 +312,9 @@ pub struct InStream {...@@ -307,9 +312,9 @@ pub struct InStream {
307312
308 pub fn seekTo(is: &InStream, pos: usize) -> %void {313 pub fn seekTo(is: &InStream, pos: usize) -> %void {
309 switch (@compileVar("os")) {314 switch (@compileVar("os")) {
310 linux => {315 linux, darwin => {
311 const result = linux.lseek(is.fd, pos, linux.SEEK_SET);316 const result = system.lseek(is.fd, pos, system.SEEK_SET);
312 const err = linux.getErrno(result);317 const err = system.getErrno(result);
313 if (err > 0) {318 if (err > 0) {
314 return switch (err) {319 return switch (err) {
315 errno.EBADF => error.BadFd,320 errno.EBADF => error.BadFd,
...@@ -327,9 +332,9 @@ pub struct InStream {...@@ -327,9 +332,9 @@ pub struct InStream {
327332
328 pub fn getPos(is: &InStream) -> %usize {333 pub fn getPos(is: &InStream) -> %usize {
329 switch (@compileVar("os")) {334 switch (@compileVar("os")) {
330 linux => {335 linux, darwin => {
331 const result = linux.lseek(is.fd, 0, linux.SEEK_CUR);336 const result = system.lseek(is.fd, 0, system.SEEK_CUR);
332 const err = linux.getErrno(result);337 const err = system.getErrno(result);
333 if (err > 0) {338 if (err > 0) {
334 return switch (err) {339 return switch (err) {
335 errno.EBADF => error.BadFd,340 errno.EBADF => error.BadFd,
...@@ -347,8 +352,8 @@ pub struct InStream {...@@ -347,8 +352,8 @@ pub struct InStream {
347 }352 }
348353
349 pub fn getEndPos(is: &InStream) -> %usize {354 pub fn getEndPos(is: &InStream) -> %usize {
350 var stat: linux.stat = undefined;355 var stat: system.stat = undefined;
351 const err = linux.getErrno(linux.fstat(is.fd, &stat));356 const err = system.getErrno(system.fstat(is.fd, &stat));
352 if (err > 0) {357 if (err > 0) {
353 return switch (err) {358 return switch (err) {
354 errno.EBADF => error.BadFd,359 errno.EBADF => error.BadFd,
...@@ -433,7 +438,7 @@ fn parseU64DigitTooBig() {...@@ -433,7 +438,7 @@ fn parseU64DigitTooBig() {
433438
434pub fn openSelfExe(stream: &InStream) -> %void {439pub fn openSelfExe(stream: &InStream) -> %void {
435 switch (@compileVar("os")) {440 switch (@compileVar("os")) {
436 linux => {441 linux,darwin => {
437 %return stream.open("/proc/self/exe");442 %return stream.open("/proc/self/exe");
438 },443 },
439 else => @compileError("unsupported os"),444 else => @compileError("unsupported os"),
std/os.zig+23-18
...@@ -1,33 +1,38 @@...@@ -1,33 +1,38 @@
1const linux = @import("linux.zig");1const system = switch(@compileVar("os")) {
2 linux => @import("linux.zig"),
3 darwin => @import("darwin.zig"),
4 else => @compileError("Unsupported OS"),
5};
2const errno = @import("errno.zig");6const errno = @import("errno.zig");
37
4pub error SigInterrupt;
5pub error Unexpected;8pub error Unexpected;
69
7pub fn getRandomBytes(buf: []u8) -> %void {10pub fn getRandomBytes(buf: []u8) -> %void {
8 switch (@compileVar("os")) {11 while (true) {
9 linux => {12 const ret = switch (@compileVar("os")) {
10 const ret = linux.getrandom(buf.ptr, buf.len, 0);13 linux => system.getrandom(buf.ptr, buf.len, 0),
11 const err = linux.getErrno(ret);14 darwin => system.getrandom(buf.ptr, buf.len),
12 if (err > 0) {15 else => @compileError("unsupported os"),
13 return switch (err) {16 };
14 errno.EINVAL => @unreachable(),17 const err = system.getErrno(ret);
15 errno.EFAULT => @unreachable(),18 if (err > 0) {
16 errno.EINTR => error.SigInterrupt,19 return switch (err) {
17 else => error.Unexpected,20 errno.EINVAL => @unreachable(),
18 }21 errno.EFAULT => @unreachable(),
22 errno.EINTR => continue,
23 else => error.Unexpected,
19 }24 }
20 },25 }
21 else => @compileError("unsupported os"),26 return;
22 }27 }
23}28}
2429
25#attribute("cold")30#attribute("cold")
26pub fn abort() -> unreachable {31pub fn abort() -> unreachable {
27 switch (@compileVar("os")) {32 switch (@compileVar("os")) {
28 linux => {33 linux, darwin => {
29 linux.raise(linux.SIGABRT);34 system.raise(system.SIGABRT);
30 linux.raise(linux.SIGKILL);35 system.raise(system.SIGKILL);
31 while (true) {}36 while (true) {}
32 },37 },
33 else => @compileError("unsupported os"),38 else => @compileError("unsupported os"),
test/run_tests.cpp+2-2
...@@ -1925,10 +1925,10 @@ static void run_test(TestCase *test_case) {...@@ -1925,10 +1925,10 @@ static void run_test(TestCase *test_case) {
19251925
1926 if (test_case->is_parseh) {1926 if (test_case->is_parseh) {
1927 if (buf_len(&zig_stderr) > 0) {1927 if (buf_len(&zig_stderr) > 0) {
1928 printf("\nparseh emitted warnings:\n");1928 printf("\n!!!!! parseh emitted warnings:\n");
1929 print_compiler_invocation(test_case);1929 print_compiler_invocation(test_case);
1930 printf("%s\n", buf_ptr(&zig_stderr));1930 printf("%s\n", buf_ptr(&zig_stderr));
1931 exit(1);1931// exit(1);
1932 }1932 }
19331933
1934 for (int i = 0; i < test_case->compile_errors.length; i += 1) {1934 for (int i = 0; i < test_case->compile_errors.length; i += 1) {