authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-20 16:16:08-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-03-20 16:16:08-04:00
log66fec3a3d726733b162761211dee58e896370e95
tree1faabb44b7fd41ab36360d619049b1639da0980b
parent1369fecccfcd7900ce0a78a67db96ed59957720a
parent43cdfa275ad75097d80abf1c4091f0b506fcb1e3
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #851 from zig-lang/zen_stdlib

Zen specific hacks

3 files changed, 34 insertions(+), 10 deletions(-)

std/os/index.zig+8
......@@ -115,6 +115,14 @@ pub fn getRandomBytes(buf: []u8) !void {
115115 };
116116 }
117117 },
118 Os.zen => {
119 const randomness = []u8 {42, 1, 7, 12, 22, 17, 99, 16, 26, 87, 41, 45};
120 var i: usize = 0;
121 while (i < buf.len) : (i += 1) {
122 if (i > randomness.len) return error.Unknown;
123 buf[i] = randomness[i];
124 }
125 },
118126 else => @compileError("Unsupported OS"),
119127 }
120128}
std/os/zen.zig+22-8
......@@ -107,14 +107,17 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {
107107///////////////////////////
108108
109109pub const Syscall = enum(usize) {
110 exit = 0,
111 createPort = 1,
112 send = 2,
113 receive = 3,
114 subscribeIRQ = 4,
115 inb = 5,
116 map = 6,
117 createThread = 7,
110 exit = 0,
111 createPort = 1,
112 send = 2,
113 receive = 3,
114 subscribeIRQ = 4,
115 inb = 5,
116 map = 6,
117 createThread = 7,
118 createProcess = 8,
119 wait = 9,
120 portReady = 10,
118121};
119122
120123
......@@ -158,6 +161,17 @@ pub fn createThread(function: fn()void) u16 {
158161 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
159162}
160163
164pub fn createProcess(elf_addr: usize) u16 {
165 return u16(syscall1(Syscall.createProcess, elf_addr));
166}
167
168pub fn wait(tid: u16) void {
169 _ = syscall1(Syscall.wait, tid);
170}
171
172pub fn portReady(port: u16) bool {
173 return syscall1(Syscall.portReady, port) != 0;
174}
161175
162176/////////////////////////
163177//// Syscall stubs ////
std/special/bootstrap.zig+4-2
......@@ -84,8 +84,10 @@ fn callMain() u8 {
8484 builtin.TypeId.ErrorUnion => {
8585 root.main() catch |err| {
8686 std.debug.warn("error: {}\n", @errorName(err));
87 if (@errorReturnTrace()) |trace| {
88 std.debug.dumpStackTrace(trace);
87 if (builtin.os != builtin.Os.zen) {
88 if (@errorReturnTrace()) |trace| {
89 std.debug.dumpStackTrace(trace);
90 }
8991 }
9092 return 1;
9193 };