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 {...@@ -91,7 +91,7 @@ pub const DirectAllocator = struct {
91 const unused_start = addr;91 const unused_start = addr;
92 const unused_len = aligned_addr - 1 - unused_start;92 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);
95 debug.assert(p.getErrno(err) == 0);95 debug.assert(p.getErrno(err) == 0);
96 96
97 //It is impossible that there is an unoccupied page at the top of our97 //It is impossible that there is an unoccupied page at the top of our
...@@ -132,7 +132,7 @@ pub const DirectAllocator = struct {...@@ -132,7 +132,7 @@ pub const DirectAllocator = struct {
132 const rem = @rem(new_addr_end, os.page_size);132 const rem = @rem(new_addr_end, os.page_size);
133 const new_addr_end_rounded = new_addr_end + if (rem == 0) 0 else (os.page_size - rem);133 const new_addr_end_rounded = new_addr_end + if (rem == 0) 0 else (os.page_size - rem);
134 if (old_addr_end > new_addr_end_rounded) {134 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);
136 }136 }
137 return old_mem[0..new_size];137 return old_mem[0..new_size];
138 }138 }
...@@ -170,7 +170,7 @@ pub const DirectAllocator = struct {...@@ -170,7 +170,7 @@ pub const DirectAllocator = struct {
170170
171 switch (builtin.os) {171 switch (builtin.os) {
172 Os.linux, Os.macosx, Os.ios => {172 Os.linux, Os.macosx, Os.ios => {
173 _ = os.posix.munmap(bytes.ptr, bytes.len);173 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
174 },174 },
175 Os.windows => {175 Os.windows => {
176 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;176 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 {...@@ -184,7 +184,7 @@ pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
184 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));184 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
185}185}
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,
188 offset: isize) usize188 offset: isize) usize
189{189{
190 const ptr_result = c.mmap(@ptrCast(&c_void, address), length,190 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,...@@ -193,8 +193,8 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
193 return errnoWrap(isize_result);193 return errnoWrap(isize_result);
194}194}
195195
196pub fn munmap(address: &u8, length: usize) usize {196pub fn munmap(address: usize, length: usize) usize {
197 return errnoWrap(c.munmap(@ptrCast(&c_void, address), length));197 return errnoWrap(c.munmap(@intToPtr(&c_void, address), length));
198}198}
199199
200pub fn unlink(path: &const u8) usize {200pub fn unlink(path: &const u8) usize {
...@@ -341,4 +341,4 @@ pub const timeval = c.timeval;...@@ -341,4 +341,4 @@ pub const timeval = c.timeval;
341pub const mach_timebase_info_data = c.mach_timebase_info_data;341pub const mach_timebase_info_data = c.mach_timebase_info_data;
342342
343pub const mach_absolute_time = c.mach_absolute_time;343pub 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...@@ -2497,11 +2497,13 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2497 }2497 }
2498 };2498 };
24992499
2500 const MAP_GROWSDOWN = if (builtin.os == builtin.Os.linux) linux.MAP_GROWSDOWN else 0;
2501
2500 const stack_len = default_stack_size;2502 const stack_len = default_stack_size;
2501 const stack_addr = posix.mmap(null, stack_len, posix.PROT_READ|posix.PROT_WRITE, 2503 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);
2503 if (stack_addr == posix.MAP_FAILED) return error.OutOfMemory;2505 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
2506 var stack_end: usize = stack_addr + stack_len;2508 var stack_end: usize = stack_addr + stack_len;
2507 var arg: usize = undefined;2509 var arg: usize = undefined;
std/os/linux/index.zig+3-3
...@@ -706,13 +706,13 @@ pub fn umount2(special: &const u8, flags: u32) usize {...@@ -706,13 +706,13 @@ pub fn umount2(special: &const u8, flags: u32) usize {
706 return syscall2(SYS_umount2, @ptrToInt(special), flags);706 return syscall2(SYS_umount2, @ptrToInt(special), flags);
707}707}
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 {
710 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),710 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
711 @bitCast(usize, offset));711 @bitCast(usize, offset));
712}712}
713713
714pub fn munmap(address: &u8, length: usize) usize {714pub fn munmap(address: usize, length: usize) usize {
715 return syscall2(SYS_munmap, @ptrToInt(address), length);715 return syscall2(SYS_munmap, address, length);
716}716}
717717
718pub fn read(fd: i32, buf: &u8, count: usize) usize {718pub fn read(fd: i32, buf: &u8, count: usize) usize {