authorgravatar for 3811822-hoanga@users.noreply.gitlab.comAl Hoang <3811822-hoanga@users.noreply.gitlab.com> 2020-12-28 23:00:31-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-25 16:41:42-07:00
log6b0372229da4fa4cf32f0ee1eb079f530554b094
treedf08afc15bbe6626a20c4ffd0609a51df6ef3425
parent025635c3f80912f0f967b57e6d22fe42e94b64f0

initial support for haiku continue clean up

* remove unused definitions * setup os specific blocks

7 files changed, 97 insertions(+), 42 deletions(-)

lib/std/c/haiku.zig+3-5
...@@ -11,15 +11,13 @@ const builtin = std.builtin;...@@ -11,15 +11,13 @@ const builtin = std.builtin;
11usingnamespace std.c;11usingnamespace std.c;
1212
13extern "c" fn _errnop() *c_int;13extern "c" fn _errnop() *c_int;
14
14pub const _errno = _errnop;15pub const _errno = _errnop;
1516
16// not supported in haiku17pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;
17pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
1818
19pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;19pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info) usize;
20//pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
2120
22//
23pub const sem_t = extern struct {21pub const sem_t = extern struct {
24 _magic: u32,22 _magic: u32,
25 _kern: extern struct {23 _kern: extern struct {
lib/std/debug.zig+1-13
...@@ -1350,7 +1350,6 @@ pub const DebugInfo = struct {...@@ -1350,7 +1350,6 @@ pub const DebugInfo = struct {
13501350
1351 return &di;1351 return &di;
1352 }1352 }
1353
1354};1353};
13551354
1356const SymbolInfo = struct {1355const SymbolInfo = struct {
...@@ -1717,17 +1716,6 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {...@@ -1717,17 +1716,6 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
1717 unreachable;1716 unreachable;
1718 }1717 }
1719 },1718 },
1720 .haiku => struct {
1721 // Haiku should implement dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743)
1722 base_address: usize,
1723 dwarf: DW.DwarfInfo,
1724 mapped_memory: []const u8,
1725
1726 pub fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo {
1727 // TODO: implement me
1728 return SymbolInfo{};
1729 }
1730 },
1731 else => DW.DwarfInfo,1719 else => DW.DwarfInfo,
1732};1720};
17331721
...@@ -1746,7 +1734,7 @@ fn getDebugInfoAllocator() *mem.Allocator {...@@ -1746,7 +1734,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
1746pub const have_segfault_handling_support = switch (builtin.os.tag) {1734pub const have_segfault_handling_support = switch (builtin.os.tag) {
1747 .linux, .netbsd => true,1735 .linux, .netbsd => true,
1748 .windows => true,1736 .windows => true,
1749 .freebsd, .openbsd, .haiku => @hasDecl(os, "ucontext_t"),1737 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
1750 else => false,1738 else => false,
1751};1739};
1752pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))1740pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))
lib/std/fs.zig+56-12
...@@ -302,7 +302,7 @@ pub const Dir = struct {...@@ -302,7 +302,7 @@ pub const Dir = struct {
302 const IteratorError = error{AccessDenied} || os.UnexpectedError;302 const IteratorError = error{AccessDenied} || os.UnexpectedError;
303303
304 pub const Iterator = switch (builtin.os.tag) {304 pub const Iterator = switch (builtin.os.tag) {
305 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => struct {305 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => struct {
306 dir: Dir,306 dir: Dir,
307 seek: i64,307 seek: i64,
308 buf: [8192]u8, // TODO align(@alignOf(os.dirent)),308 buf: [8192]u8, // TODO align(@alignOf(os.dirent)),
...@@ -319,7 +319,6 @@ pub const Dir = struct {...@@ -319,7 +319,6 @@ pub const Dir = struct {
319 switch (builtin.os.tag) {319 switch (builtin.os.tag) {
320 .macos, .ios => return self.nextDarwin(),320 .macos, .ios => return self.nextDarwin(),
321 .freebsd, .netbsd, .dragonfly, .openbsd => return self.nextBsd(),321 .freebsd, .netbsd, .dragonfly, .openbsd => return self.nextBsd(),
322 .haiku => return self.nextHaiku(),
323 else => @compileError("unimplemented"),322 else => @compileError("unimplemented"),
324 }323 }
325 }324 }
...@@ -427,16 +426,61 @@ pub const Dir = struct {...@@ -427,16 +426,61 @@ pub const Dir = struct {
427 };426 };
428 }427 }
429 }428 }
429 },
430 .haiku => struct {
431 dir: Dir,
432 buf: [8192]u8, // TODO align(@alignOf(os.dirent64)),
433 index: usize,
434 end_index: usize,
430435
431 fn nextHaiku(self: *Self) !?Entry {436 const Self = @This();
432 //const name = @ptrCast([*]u8, "placeholder-please-implement-me");
433 //const name = "placeholder-please-implement-me";
434 return Entry{
435 .name = base64_alphabet,
436 .kind = Entry.Kind.File,
437 };
438 }
439437
438 pub const Error = IteratorError;
439
440 /// Memory such as file names referenced in this returned entry becomes invalid
441 /// with subsequent calls to `next`, as well as when this `Dir` is deinitialized.
442 pub fn next(self: *Self) Error!?Entry {
443 start_over: while (true) {
444 // TODO: find a better max
445 const HAIKU_MAX_COUNT = 10000;
446 if (self.index >= self.end_index) {
447 const rc = os.system._kern_read_dir(
448 self.dir.fd,
449 &self.buf,
450 self.buf.len,
451 HAIKU_MAX_COUNT,
452 );
453 if (rc == 0) return null;
454 if (rc < 0) {
455 switch (os.errno(rc)) {
456 os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
457 os.EFAULT => unreachable,
458 os.ENOTDIR => unreachable,
459 os.EINVAL => unreachable,
460 else => |err| return os.unexpectedErrno(err),
461 }
462 }
463 self.index = 0;
464 self.end_index = @intCast(usize, rc);
465 }
466 const haiku_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]);
467 const next_index = self.index + haiku_entry.reclen();
468 self.index = next_index;
469 const name = mem.spanZ(@ptrCast([*:0]u8, &haiku_entry.d_name));
470
471 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (haiku_entry.d_ino == 0)) {
472 continue :start_over;
473 }
474
475 // TODO: determine entry kind
476 const entry_kind = Entry.Kind.File;
477
478 return Entry{
479 .name = name,
480 .kind = entry_kind,
481 };
482 }
483 }
440 },484 },
441 .linux => struct {485 .linux => struct {
442 dir: Dir,486 dir: Dir,
...@@ -632,14 +676,14 @@ pub const Dir = struct {...@@ -632,14 +676,14 @@ pub const Dir = struct {
632676
633 pub fn iterate(self: Dir) Iterator {677 pub fn iterate(self: Dir) Iterator {
634 switch (builtin.os.tag) {678 switch (builtin.os.tag) {
635 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => return Iterator{679 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, => return Iterator{
636 .dir = self,680 .dir = self,
637 .seek = 0,681 .seek = 0,
638 .index = 0,682 .index = 0,
639 .end_index = 0,683 .end_index = 0,
640 .buf = undefined,684 .buf = undefined,
641 },685 },
642 .linux => return Iterator{686 .linux, .haiku => return Iterator{
643 .dir = self,687 .dir = self,
644 .index = 0,688 .index = 0,
645 .end_index = 0,689 .end_index = 0,
lib/std/os.zig+2-1
...@@ -53,6 +53,7 @@ test {...@@ -53,6 +53,7 @@ test {
53 _ = uefi;53 _ = uefi;
54 _ = wasi;54 _ = wasi;
55 _ = windows;55 _ = windows;
56 _ = haiku;
5657
57 _ = @import("os/test.zig");58 _ = @import("os/test.zig");
58}59}
...@@ -601,7 +602,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {...@@ -601,7 +602,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
601/// On these systems, the read races with concurrent writes to the same file descriptor.602/// On these systems, the read races with concurrent writes to the same file descriptor.
602pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {603pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
603 const have_pread_but_not_preadv = switch (std.Target.current.os.tag) {604 const have_pread_but_not_preadv = switch (std.Target.current.os.tag) {
604 .windows, .macos, .ios, .watchos, .tvos => true,605 .windows, .macos, .ios, .watchos, .tvos, .haiku => true,
605 else => false,606 else => false,
606 };607 };
607 if (have_pread_but_not_preadv) {608 if (have_pread_but_not_preadv) {
lib/std/os/bits/haiku.zig+22-6
...@@ -162,13 +162,11 @@ pub const timespec = extern struct {...@@ -162,13 +162,11 @@ pub const timespec = extern struct {
162};162};
163163
164pub const dirent = extern struct {164pub const dirent = extern struct {
165 d_fileno: usize,165 d_dev: i32,
166 d_off: i64,166 d_pdev: i32,
167 d_ino: i64,
168 d_pino: i64,
167 d_reclen: u16,169 d_reclen: u16,
168 d_type: u8,
169 d_pad0: u8,
170 d_namlen: u16,
171 d_pad1: u16,
172 d_name: [256]u8,170 d_name: [256]u8,
173171
174 pub fn reclen(self: dirent) u16 {172 pub fn reclen(self: dirent) u16 {
...@@ -176,6 +174,24 @@ pub const dirent = extern struct {...@@ -176,6 +174,24 @@ pub const dirent = extern struct {
176 }174 }
177};175};
178176
177pub const image_info = extern struct {
178 id: u32, //image_id
179 type: u32, // image_type
180 sequence: i32,
181 init_order: i32,
182 init_routine: *c_void,
183 term_routine: *c_void,
184 device: i32,
185 node: i32,
186 name: [1024]u8,
187 text: *c_void,
188 data: *c_void,
189 text_size: i32,
190 data_size: i32,
191 api_version: i32,
192 abi: i32,
193};
194
179pub const in_port_t = u16;195pub const in_port_t = u16;
180pub const sa_family_t = u8;196pub const sa_family_t = u8;
181197
lib/std/process.zig+7-2
...@@ -777,7 +777,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]...@@ -777,7 +777,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
777 }777 }
778 return paths.toOwnedSlice();778 return paths.toOwnedSlice();
779 },779 },
780 // Haiku should implement dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743)780 // revisit if Haiku implements dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743)
781 .haiku => {781 .haiku => {
782 var paths = List.init(allocator);782 var paths = List.init(allocator);
783 errdefer {783 errdefer {
...@@ -787,7 +787,12 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]...@@ -787,7 +787,12 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
787 }787 }
788 allocator.free(slice);788 allocator.free(slice);
789 }789 }
790 //TODO: fill out placeholder790
791 var b = "/boot/system/runtime_loader";
792 const item = try allocator.dupeZ(u8, mem.spanZ(b));
793 errdefer allocator.free(item);
794 try paths.append(item);
795
791 return paths.toOwnedSlice();796 return paths.toOwnedSlice();
792 },797 },
793 else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"),798 else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"),
lib/std/target.zig+6-3
...@@ -379,6 +379,7 @@ pub const Target = struct {...@@ -379,6 +379,7 @@ pub const Target = struct {
379 .watchos,379 .watchos,
380 .dragonfly,380 .dragonfly,
381 .openbsd,381 .openbsd,
382 .haiku,
382 => true,383 => true,
383384
384 .linux,385 .linux,
...@@ -390,7 +391,6 @@ pub const Target = struct {...@@ -390,7 +391,6 @@ pub const Target = struct {
390 .kfreebsd,391 .kfreebsd,
391 .lv2,392 .lv2,
392 .solaris,393 .solaris,
393 .haiku,
394 .minix,394 .minix,
395 .rtems,395 .rtems,
396 .nacl,396 .nacl,
...@@ -468,7 +468,6 @@ pub const Target = struct {...@@ -468,7 +468,6 @@ pub const Target = struct {
468 .dragonfly,468 .dragonfly,
469 .lv2,469 .lv2,
470 .solaris,470 .solaris,
471 .haiku,
472 .minix,471 .minix,
473 .rtems,472 .rtems,
474 .nacl,473 .nacl,
...@@ -495,6 +494,7 @@ pub const Target = struct {...@@ -495,6 +494,7 @@ pub const Target = struct {
495 .kfreebsd,494 .kfreebsd,
496 .netbsd,495 .netbsd,
497 .hurd,496 .hurd,
497 .haiku,
498 => return .gnu,498 => return .gnu,
499 .windows,499 .windows,
500 .uefi,500 .uefi,
...@@ -1566,6 +1566,10 @@ pub const Target = struct {...@@ -1566,6 +1566,10 @@ pub const Target = struct {
1566 .other,1566 .other,
1567 => return result,1567 => return result,
15681568
1569 // Operating systems in this list have been verified as not having a standard
1570 // dynamic linker path.
1571 .haiku => return copy(&result, "/system/runtime_loader"),
1572
1569 // TODO go over each item in this list and either move it to the above list, or1573 // TODO go over each item in this list and either move it to the above list, or
1570 // implement the standard dynamic linker path code for it.1574 // implement the standard dynamic linker path code for it.
1571 .ananas,1575 .ananas,
...@@ -1574,7 +1578,6 @@ pub const Target = struct {...@@ -1574,7 +1578,6 @@ pub const Target = struct {
1574 .kfreebsd,1578 .kfreebsd,
1575 .lv2,1579 .lv2,
1576 .solaris,1580 .solaris,
1577 .haiku,
1578 .minix,1581 .minix,
1579 .rtems,1582 .rtems,
1580 .nacl,1583 .nacl,