authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-29 02:52:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-29 02:52:04-04:00
logb21bcbd7755d236a313c06e6ff167f5395ab8ed4
tree23fef3cf665a6d396347ee3b88c6142aad92b8fa
parent6376d96824c5205ecc02b2c621bcef5dc78f1a81

fix std threads for macos


4 files changed, 14 insertions(+), 12 deletions(-)

std/heap.zig+3-3
......@@ -91,7 +91,7 @@ pub const DirectAllocator = struct {
9191 const unused_start = addr;
9292 const unused_len = aligned_addr - 1 - unused_start;
9393
94 var err = p.munmap(@intToPtr(&u8, unused_start), unused_len);
94 var err = p.munmap(unused_start, unused_len);
9595 debug.assert(p.getErrno(err) == 0);
9696
9797 //It is impossible that there is an unoccupied page at the top of our
......@@ -132,7 +132,7 @@ pub const DirectAllocator = struct {
132132 const rem = @rem(new_addr_end, os.page_size);
133133 const new_addr_end_rounded = new_addr_end + if (rem == 0) 0 else (os.page_size - rem);
134134 if (old_addr_end > new_addr_end_rounded) {
135 _ = os.posix.munmap(@intToPtr(&u8, new_addr_end_rounded), old_addr_end - new_addr_end_rounded);
135 _ = os.posix.munmap(new_addr_end_rounded, old_addr_end - new_addr_end_rounded);
136136 }
137137 return old_mem[0..new_size];
138138 }
......@@ -170,7 +170,7 @@ pub const DirectAllocator = struct {
170170
171171 switch (builtin.os) {
172172 Os.linux, Os.macosx, Os.ios => {
173 _ = os.posix.munmap(bytes.ptr, bytes.len);
173 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
174174 },
175175 Os.windows => {
176176 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
std/os/darwin.zig+4-4
......@@ -184,7 +184,7 @@ pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
184184 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
185185}
186186
187pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
187pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32,
188188 offset: isize) usize
189189{
190190 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,
193193 return errnoWrap(isize_result);
194194}
195195
196pub fn munmap(address: &u8, length: usize) usize {
197 return errnoWrap(c.munmap(@ptrCast(&c_void, address), length));
196pub fn munmap(address: usize, length: usize) usize {
197 return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));
198198}
199199
200200pub fn unlink(path: &const u8) usize {
......@@ -341,4 +341,4 @@ pub const timeval = c.timeval;
341341pub const mach_timebase_info_data = c.mach_timebase_info_data;
342342
343343pub const mach_absolute_time = c.mach_absolute_time;
344pub const mach_timebase_info = c.mach_timebase_info;
\ No newline at end of file
344pub const mach_timebase_info = c.mach_timebase_info;
std/os/index.zig+4-2
......@@ -2497,11 +2497,13 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
24972497 }
24982498 };
24992499
2500 const MAP_GROWSDOWN = if (builtin.os == builtin.Os.linux) linux.MAP_GROWSDOWN else 0;
2501
25002502 const stack_len = default_stack_size;
25012503 const stack_addr = posix.mmap(null, stack_len, posix.PROT_READ|posix.PROT_WRITE,
2502 posix.MAP_PRIVATE|posix.MAP_ANONYMOUS|posix.MAP_GROWSDOWN, -1, 0);
2504 posix.MAP_PRIVATE|posix.MAP_ANONYMOUS|MAP_GROWSDOWN, -1, 0);
25032505 if (stack_addr == posix.MAP_FAILED) return error.OutOfMemory;
2504 errdefer _ = posix.munmap(stack_addr, stack_len);
2506 errdefer assert(posix.munmap(stack_addr, stack_len) == 0);
25052507
25062508 var stack_end: usize = stack_addr + stack_len;
25072509 var arg: usize = undefined;
std/os/linux/index.zig+3-3
......@@ -706,13 +706,13 @@ pub fn umount2(special: &const u8, flags: u32) usize {
706706 return syscall2(SYS_umount2, @ptrToInt(special), flags);
707707}
708708
709pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
709pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
710710 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
711711 @bitCast(usize, offset));
712712}
713713
714pub fn munmap(address: &u8, length: usize) usize {
715 return syscall2(SYS_munmap, @ptrToInt(address), length);
714pub fn munmap(address: usize, length: usize) usize {
715 return syscall2(SYS_munmap, address, length);
716716}
717717
718718pub fn read(fd: i32, buf: &u8, count: usize) usize {