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;
1111usingnamespace std.c;
1212
1313extern "c" fn _errnop() *c_int;
14
1415pub const _errno = _errnop;
1516
16// not supported in haiku
17pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
17pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;
1818
19pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
20//pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
19pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info) usize;
2120
22//
2321pub const sem_t = extern struct {
2422 _magic: u32,
2523 _kern: extern struct {
lib/std/debug.zig+1-13
......@@ -1350,7 +1350,6 @@ pub const DebugInfo = struct {
13501350
13511351 return &di;
13521352 }
1353
13541353};
13551354
13561355const SymbolInfo = struct {
......@@ -1717,17 +1716,6 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
17171716 unreachable;
17181717 }
17191718 },
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 },
17311719 else => DW.DwarfInfo,
17321720};
17331721
......@@ -1746,7 +1734,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
17461734pub const have_segfault_handling_support = switch (builtin.os.tag) {
17471735 .linux, .netbsd => true,
17481736 .windows => true,
1749 .freebsd, .openbsd, .haiku => @hasDecl(os, "ucontext_t"),
1737 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
17501738 else => false,
17511739};
17521740pub 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 {
302302 const IteratorError = error{AccessDenied} || os.UnexpectedError;
303303
304304 pub const Iterator = switch (builtin.os.tag) {
305 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => struct {
305 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => struct {
306306 dir: Dir,
307307 seek: i64,
308308 buf: [8192]u8, // TODO align(@alignOf(os.dirent)),
......@@ -319,7 +319,6 @@ pub const Dir = struct {
319319 switch (builtin.os.tag) {
320320 .macos, .ios => return self.nextDarwin(),
321321 .freebsd, .netbsd, .dragonfly, .openbsd => return self.nextBsd(),
322 .haiku => return self.nextHaiku(),
323322 else => @compileError("unimplemented"),
324323 }
325324 }
......@@ -427,16 +426,61 @@ pub const Dir = struct {
427426 };
428427 }
429428 }
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 {
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 }
436 const Self = @This();
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 }
440484 },
441485 .linux => struct {
442486 dir: Dir,
......@@ -632,14 +676,14 @@ pub const Dir = struct {
632676
633677 pub fn iterate(self: Dir) Iterator {
634678 switch (builtin.os.tag) {
635 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => return Iterator{
679 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, => return Iterator{
636680 .dir = self,
637681 .seek = 0,
638682 .index = 0,
639683 .end_index = 0,
640684 .buf = undefined,
641685 },
642 .linux => return Iterator{
686 .linux, .haiku => return Iterator{
643687 .dir = self,
644688 .index = 0,
645689 .end_index = 0,
lib/std/os.zig+2-1
......@@ -53,6 +53,7 @@ test {
5353 _ = uefi;
5454 _ = wasi;
5555 _ = windows;
56 _ = haiku;
5657
5758 _ = @import("os/test.zig");
5859}
......@@ -601,7 +602,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void {
601602/// On these systems, the read races with concurrent writes to the same file descriptor.
602603pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
603604 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,
605606 else => false,
606607 };
607608 if (have_pread_but_not_preadv) {
lib/std/os/bits/haiku.zig+22-6
......@@ -162,13 +162,11 @@ pub const timespec = extern struct {
162162};
163163
164164pub const dirent = extern struct {
165 d_fileno: usize,
166 d_off: i64,
165 d_dev: i32,
166 d_pdev: i32,
167 d_ino: i64,
168 d_pino: i64,
167169 d_reclen: u16,
168 d_type: u8,
169 d_pad0: u8,
170 d_namlen: u16,
171 d_pad1: u16,
172170 d_name: [256]u8,
173171
174172 pub fn reclen(self: dirent) u16 {
......@@ -176,6 +174,24 @@ pub const dirent = extern struct {
176174 }
177175};
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
179195pub const in_port_t = u16;
180196pub const sa_family_t = u8;
181197
lib/std/process.zig+7-2
......@@ -777,7 +777,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
777777 }
778778 return paths.toOwnedSlice();
779779 },
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)
781781 .haiku => {
782782 var paths = List.init(allocator);
783783 errdefer {
......@@ -787,7 +787,12 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
787787 }
788788 allocator.free(slice);
789789 }
790 //TODO: fill out placeholder
790
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
791796 return paths.toOwnedSlice();
792797 },
793798 else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"),
lib/std/target.zig+6-3
......@@ -379,6 +379,7 @@ pub const Target = struct {
379379 .watchos,
380380 .dragonfly,
381381 .openbsd,
382 .haiku,
382383 => true,
383384
384385 .linux,
......@@ -390,7 +391,6 @@ pub const Target = struct {
390391 .kfreebsd,
391392 .lv2,
392393 .solaris,
393 .haiku,
394394 .minix,
395395 .rtems,
396396 .nacl,
......@@ -468,7 +468,6 @@ pub const Target = struct {
468468 .dragonfly,
469469 .lv2,
470470 .solaris,
471 .haiku,
472471 .minix,
473472 .rtems,
474473 .nacl,
......@@ -495,6 +494,7 @@ pub const Target = struct {
495494 .kfreebsd,
496495 .netbsd,
497496 .hurd,
497 .haiku,
498498 => return .gnu,
499499 .windows,
500500 .uefi,
......@@ -1566,6 +1566,10 @@ pub const Target = struct {
15661566 .other,
15671567 => 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
15691573 // TODO go over each item in this list and either move it to the above list, or
15701574 // implement the standard dynamic linker path code for it.
15711575 .ananas,
......@@ -1574,7 +1578,6 @@ pub const Target = struct {
15741578 .kfreebsd,
15751579 .lv2,
15761580 .solaris,
1577 .haiku,
15781581 .minix,
15791582 .rtems,
15801583 .nacl,