Commit b21bcbd775

Andrew Kelley <superjoe30@gmail.com>
2018-04-29 08:52:04
fix std threads for macos
1 parent 6376d96
Changed files (4)
std/os/linux/index.zig
@@ -706,13 +706,13 @@ pub fn umount2(special: &const u8, flags: u32) usize {
     return syscall2(SYS_umount2, @ptrToInt(special), flags);
 }
 
-pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
+pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
     return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
         @bitCast(usize, offset));
 }
 
-pub fn munmap(address: &u8, length: usize) usize {
-    return syscall2(SYS_munmap, @ptrToInt(address), length);
+pub fn munmap(address: usize, length: usize) usize {
+    return syscall2(SYS_munmap, address, length);
 }
 
 pub fn read(fd: i32, buf: &u8, count: usize) usize {
std/os/darwin.zig
@@ -184,7 +184,7 @@ pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
     return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
 }
 
-pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
+pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32,
     offset: isize) usize
 {
     const ptr_result = c.mmap(@ptrCast(&c_void, address), length,
@@ -193,8 +193,8 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
     return errnoWrap(isize_result);
 }
 
-pub fn munmap(address: &u8, length: usize) usize {
-    return errnoWrap(c.munmap(@ptrCast(&c_void, address), length));
+pub fn munmap(address: usize, length: usize) usize {
+    return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));
 }
 
 pub fn unlink(path: &const u8) usize {
@@ -341,4 +341,4 @@ pub const timeval = c.timeval;
 pub const mach_timebase_info_data = c.mach_timebase_info_data;
 
 pub const mach_absolute_time = c.mach_absolute_time;
-pub const mach_timebase_info = c.mach_timebase_info;
\ No newline at end of file
+pub const mach_timebase_info = c.mach_timebase_info;
std/os/index.zig
@@ -2497,11 +2497,13 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
         }
     };
 
+    const MAP_GROWSDOWN = if (builtin.os == builtin.Os.linux) linux.MAP_GROWSDOWN else 0;
+
     const stack_len = default_stack_size;
     const stack_addr = posix.mmap(null, stack_len, posix.PROT_READ|posix.PROT_WRITE, 
-            posix.MAP_PRIVATE|posix.MAP_ANONYMOUS|posix.MAP_GROWSDOWN, -1, 0);
+            posix.MAP_PRIVATE|posix.MAP_ANONYMOUS|MAP_GROWSDOWN, -1, 0);
     if (stack_addr == posix.MAP_FAILED) return error.OutOfMemory;
-    errdefer _ = posix.munmap(stack_addr, stack_len);
+    errdefer assert(posix.munmap(stack_addr, stack_len) == 0);
 
     var stack_end: usize = stack_addr + stack_len;
     var arg: usize = undefined;
std/heap.zig
@@ -91,7 +91,7 @@ pub const DirectAllocator = struct {
                 const unused_start = addr;
                 const unused_len = aligned_addr - 1 - unused_start;
 
-                var err = p.munmap(@intToPtr(&u8, unused_start), unused_len);
+                var err = p.munmap(unused_start, unused_len);
                 debug.assert(p.getErrno(err) == 0);
                 
                 //It is impossible that there is an unoccupied page at the top of our
@@ -132,7 +132,7 @@ pub const DirectAllocator = struct {
                     const rem = @rem(new_addr_end, os.page_size);
                     const new_addr_end_rounded = new_addr_end + if (rem == 0) 0 else (os.page_size - rem);
                     if (old_addr_end > new_addr_end_rounded) {
-                        _ = os.posix.munmap(@intToPtr(&u8, new_addr_end_rounded), old_addr_end - new_addr_end_rounded);
+                        _ = os.posix.munmap(new_addr_end_rounded, old_addr_end - new_addr_end_rounded);
                     }
                     return old_mem[0..new_size];
                 }
@@ -170,7 +170,7 @@ pub const DirectAllocator = struct {
 
         switch (builtin.os) {
             Os.linux, Os.macosx, Os.ios => {
-                _ = os.posix.munmap(bytes.ptr, bytes.len);
+                _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
             },
             Os.windows => {
                 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;