| author | |
| committer | |
| log | c17396691ce116a949618cb03d740997c7e80788 |
| tree | a7d9f8fbf9cb4b765609af2ec842b17e6f0e7be5 |
| parent | 6b0372229da4fa4cf32f0ee1eb079f530554b094 |
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku9 files changed, 136 insertions(+), 33 deletions(-)
lib/std/Thread.zig+10| ... | ... | @@ -504,6 +504,13 @@ pub fn cpuCount() CpuCountError!usize { |
| 504 | 504 | }; |
| 505 | 505 | return @intCast(usize, count); |
| 506 | 506 | } |
| 507 | if (std.Target.current.os.tag == .haiku) { | |
| 508 | var count: u32 = undefined; | |
| 509 | var system_info: os.system_info = undefined; | |
| 510 | const rc = os.system.get_system_info(&system_info); | |
| 511 | count = system_info.cpu_count; | |
| 512 | return @intCast(usize, count); | |
| 513 | } | |
| 507 | 514 | var count: c_int = undefined; |
| 508 | 515 | var count_len: usize = @sizeOf(c_int); |
| 509 | 516 | const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu"; |
| ... | ... | @@ -538,6 +545,9 @@ pub fn getCurrentThreadId() u64 { |
| 538 | 545 | .openbsd => { |
| 539 | 546 | return @bitCast(u32, c.getthrid()); |
| 540 | 547 | }, |
| 548 | .haiku => { | |
| 549 | return @bitCast(u32, c.find_thread(null)); | |
| 550 | }, | |
| 541 | 551 | else => { |
| 542 | 552 | @compileError("getCurrentThreadId not implemented for this platform"); |
| 543 | 553 | }, |
lib/std/c/haiku.zig+20-2| ... | ... | @@ -14,10 +14,21 @@ extern "c" fn _errnop() *c_int; |
| 14 | 14 | |
| 15 | 15 | pub const _errno = _errnop; |
| 16 | 16 | |
| 17 | pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize; | |
| 17 | pub extern "c" fn find_directory(which: c_int, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64; | |
| 18 | ||
| 19 | pub extern "c" fn find_thread(thread_name: ?*c_void) i32; | |
| 20 | ||
| 21 | pub extern "c" fn get_system_info(system_info: *system_info) usize; | |
| 18 | 22 | |
| 23 | // TODO revisit if abi changes or better option becomes apparent | |
| 19 | 24 | pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info) usize; |
| 20 | 25 | |
| 26 | pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize; | |
| 27 | ||
| 28 | pub extern "c" fn _kern_read_stat(fd: c_int, path_ptr: [*]u8, traverse_link: bool, libc_stat: *libc_stat, stat_size: i32) usize; | |
| 29 | ||
| 30 | pub extern "c" fn _kern_get_current_team() i32; | |
| 31 | ||
| 21 | 32 | pub const sem_t = extern struct { |
| 22 | 33 | _magic: u32, |
| 23 | 34 | _kern: extern struct { |
| ... | ... | @@ -27,6 +38,14 @@ pub const sem_t = extern struct { |
| 27 | 38 | _padding: u32, |
| 28 | 39 | }; |
| 29 | 40 | |
| 41 | pub const pthread_attr_t = extern struct { | |
| 42 | __detach_state: i32, | |
| 43 | __sched_priority: i32, | |
| 44 | __stack_size: i32, | |
| 45 | __guard_size: i32, | |
| 46 | __stack_address: ?*c_void, | |
| 47 | }; | |
| 48 | ||
| 30 | 49 | pub const pthread_mutex_t = extern struct { |
| 31 | 50 | flags: u32 = 0, |
| 32 | 51 | lock: i32 = 0, |
| ... | ... | @@ -34,7 +53,6 @@ pub const pthread_mutex_t = extern struct { |
| 34 | 53 | owner: i32 = -1, |
| 35 | 54 | owner_count: i32 = 0, |
| 36 | 55 | }; |
| 37 | ||
| 38 | 56 | pub const pthread_cond_t = extern struct { |
| 39 | 57 | flags: u32 = 0, |
| 40 | 58 | unused: i32 = -42, |
lib/std/crypto/tlcsprng.zig+1| ... | ... | @@ -29,6 +29,7 @@ const os_has_fork = switch (std.Target.current.os.tag) { |
| 29 | 29 | .solaris, |
| 30 | 30 | .tvos, |
| 31 | 31 | .watchos, |
| 32 | .haiku, | |
| 32 | 33 | => true, |
| 33 | 34 | |
| 34 | 35 | else => false, |
lib/std/fs.zig+26-3| ... | ... | @@ -472,8 +472,25 @@ pub const Dir = struct { |
| 472 | 472 | continue :start_over; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | // TODO: determine entry kind | |
| 476 | const entry_kind = Entry.Kind.File; | |
| 475 | var stat_info: os.libc_stat = undefined; | |
| 476 | const rc2 = os.system._kern_read_stat( | |
| 477 | self.dir.fd, | |
| 478 | &haiku_entry.d_name, | |
| 479 | false, | |
| 480 | &stat_info, | |
| 481 | 0, | |
| 482 | ); | |
| 483 | const statmode = stat_info.mode & os.S_IFMT; | |
| 484 | ||
| 485 | const entry_kind = switch (statmode) { | |
| 486 | os.S_IFDIR => Entry.Kind.Directory, | |
| 487 | os.S_IFBLK => Entry.Kind.BlockDevice, | |
| 488 | os.S_IFCHR => Entry.Kind.CharacterDevice, | |
| 489 | os.S_IFLNK => Entry.Kind.SymLink, | |
| 490 | os.S_IFREG => Entry.Kind.File, | |
| 491 | os.S_IFIFO => Entry.Kind.NamedPipe, | |
| 492 | else => Entry.Kind.Unknown, | |
| 493 | }; | |
| 477 | 494 | |
| 478 | 495 | return Entry{ |
| 479 | 496 | .name = name, |
| ... | ... | @@ -676,7 +693,13 @@ pub const Dir = struct { |
| 676 | 693 | |
| 677 | 694 | pub fn iterate(self: Dir) Iterator { |
| 678 | 695 | switch (builtin.os.tag) { |
| 679 | .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, => return Iterator{ | |
| 696 | .macos, | |
| 697 | .ios, | |
| 698 | .freebsd, | |
| 699 | .netbsd, | |
| 700 | .dragonfly, | |
| 701 | .openbsd, | |
| 702 | => return Iterator{ | |
| 680 | 703 | .dir = self, |
| 681 | 704 | .seek = 0, |
| 682 | 705 | .index = 0, |
lib/std/fs/get_app_data_dir.zig+10-5| ... | ... | @@ -57,11 +57,16 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 57 | 57 | return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname }); |
| 58 | 58 | }, |
| 59 | 59 | .haiku => { |
| 60 | const home_dir = os.getenv("HOME") orelse { | |
| 61 | // TODO look in /etc/passwd | |
| 62 | return error.AppDataDirUnavailable; | |
| 63 | }; | |
| 64 | return fs.path.join(allocator, &[_][]const u8{ home_dir, "config", "settings", appname }); | |
| 60 | var dir_path_ptr: [*:0]u8 = undefined; | |
| 61 | // TODO look into directory_which | |
| 62 | const be_user_settings = 0xbbe; | |
| 63 | const rc = os.system.find_directory(be_user_settings, -1, true, dir_path_ptr, 1) ; | |
| 64 | const settings_dir = try allocator.dupeZ(u8, mem.spanZ(dir_path_ptr)); | |
| 65 | defer allocator.free(settings_dir); | |
| 66 | switch (rc) { | |
| 67 | 0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }), | |
| 68 | else => return error.AppDataDirUnavailable, | |
| 69 | } | |
| 65 | 70 | }, |
| 66 | 71 | else => @compileError("Unsupported OS"), |
| 67 | 72 | } |
lib/std/os.zig+6| ... | ... | @@ -3941,6 +3941,9 @@ pub fn sysctl( |
| 3941 | 3941 | if (builtin.os.tag == .wasi) { |
| 3942 | 3942 | @panic("unsupported"); |
| 3943 | 3943 | } |
| 3944 | if (builtin.os.tag == .haiku) { | |
| 3945 | @panic("unsupported"); | |
| 3946 | } | |
| 3944 | 3947 | |
| 3945 | 3948 | const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong; |
| 3946 | 3949 | switch (errno(system.sysctl(name.ptr, name_len, oldp, oldlenp, newp, newlen))) { |
| ... | ... | @@ -3965,6 +3968,9 @@ pub fn sysctlbynameZ( |
| 3965 | 3968 | if (builtin.os.tag == .wasi) { |
| 3966 | 3969 | @panic("unsupported"); |
| 3967 | 3970 | } |
| 3971 | if (builtin.os.tag == .haiku) { | |
| 3972 | @panic("unsupported"); | |
| 3973 | } | |
| 3968 | 3974 | |
| 3969 | 3975 | switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) { |
| 3970 | 3976 | 0 => return, |
lib/std/os/bits/haiku.zig+61-21| ... | ... | @@ -6,8 +6,6 @@ |
| 6 | 6 | const std = @import("../../std.zig"); |
| 7 | 7 | const maxInt = std.math.maxInt; |
| 8 | 8 | |
| 9 | // See https://svnweb.freebsd.org/base/head/sys/sys/_types.h?view=co | |
| 10 | // TODO: audit pid_t/mode_t. They should likely be i32 and u16, respectively | |
| 11 | 9 | pub const fd_t = c_int; |
| 12 | 10 | pub const pid_t = c_int; |
| 13 | 11 | pub const uid_t = u32; |
| ... | ... | @@ -30,6 +28,11 @@ pub const Kevent = extern struct { |
| 30 | 28 | // Modes and flags for dlopen() |
| 31 | 29 | // include/dlfcn.h |
| 32 | 30 | |
| 31 | pub const POLLIN = 0x0001; | |
| 32 | pub const POLLERR = 0x0004; | |
| 33 | pub const POLLNVAL = 0x1000; | |
| 34 | pub const POLLHUP = 0x0080; | |
| 35 | ||
| 33 | 36 | /// Bind function calls lazily. |
| 34 | 37 | pub const RTLD_LAZY = 1; |
| 35 | 38 | |
| ... | ... | @@ -119,41 +122,43 @@ pub const msghdr_const = extern struct { |
| 119 | 122 | pub const off_t = i64; |
| 120 | 123 | pub const ino_t = u64; |
| 121 | 124 | |
| 122 | pub const libc_stat = extern struct { | |
| 123 | dev: u64, | |
| 124 | ino: ino_t, | |
| 125 | nlink: usize, | |
| 125 | pub const nfds_t = u32; | |
| 126 | 126 | |
| 127 | mode: u16, | |
| 128 | __pad0: u16, | |
| 129 | uid: uid_t, | |
| 130 | gid: gid_t, | |
| 131 | __pad1: u32, | |
| 132 | rdev: u64, | |
| 127 | pub const pollfd = extern struct { | |
| 128 | fd: i32, | |
| 129 | events: i16, | |
| 130 | revents: i16, | |
| 131 | }; | |
| 133 | 132 | |
| 133 | pub const libc_stat = extern struct { | |
| 134 | dev: i32, | |
| 135 | ino: u64, | |
| 136 | mode: u32, | |
| 137 | nlink: i32, | |
| 138 | uid: i32, | |
| 139 | gid: i32, | |
| 140 | size: i64, | |
| 141 | rdev: i32, | |
| 142 | blksize: i32, | |
| 134 | 143 | atim: timespec, |
| 135 | 144 | mtim: timespec, |
| 136 | 145 | ctim: timespec, |
| 137 | birthtim: timespec, | |
| 138 | ||
| 139 | size: off_t, | |
| 146 | crtim: timespec, | |
| 147 | st_type: u32, | |
| 140 | 148 | blocks: i64, |
| 141 | blksize: isize, | |
| 142 | flags: u32, | |
| 143 | gen: u64, | |
| 144 | __spare: [10]u64, | |
| 145 | 149 | |
| 146 | 150 | pub fn atime(self: @This()) timespec { |
| 147 | 151 | return self.atim; |
| 148 | 152 | } |
| 149 | ||
| 150 | 153 | pub fn mtime(self: @This()) timespec { |
| 151 | 154 | return self.mtim; |
| 152 | 155 | } |
| 153 | ||
| 154 | 156 | pub fn ctime(self: @This()) timespec { |
| 155 | 157 | return self.ctim; |
| 156 | 158 | } |
| 159 | pub fn crtime(self: @This()) timespec { | |
| 160 | return self.crtim; | |
| 161 | } | |
| 157 | 162 | }; |
| 158 | 163 | |
| 159 | 164 | pub const timespec = extern struct { |
| ... | ... | @@ -192,6 +197,34 @@ pub const image_info = extern struct { |
| 192 | 197 | abi: i32, |
| 193 | 198 | }; |
| 194 | 199 | |
| 200 | pub const system_info = extern struct { | |
| 201 | boot_time: i64, | |
| 202 | cpu_count: u32, | |
| 203 | max_pages: u64, | |
| 204 | used_pages: u64, | |
| 205 | cached_pages: u64, | |
| 206 | block_cache_pages: u64, | |
| 207 | ignored_pages: u64, | |
| 208 | needed_memory: u64, | |
| 209 | free_memory: u64, | |
| 210 | max_swap_pages: u64, | |
| 211 | free_swap_pages: u64, | |
| 212 | page_faults: u32, | |
| 213 | max_sems: u32, | |
| 214 | used_sems: u32, | |
| 215 | max_ports: u32, | |
| 216 | used_ports: u32, | |
| 217 | max_threads: u32, | |
| 218 | used_threads: u32, | |
| 219 | max_teams: u32, | |
| 220 | used_teams: u32, | |
| 221 | kernel_name: [256]u8, | |
| 222 | kernel_build_date: [32]u8, | |
| 223 | kernel_build_time: [32]u8, | |
| 224 | kernel_version: i64, | |
| 225 | abi: u32, | |
| 226 | }; | |
| 227 | ||
| 195 | 228 | pub const in_port_t = u16; |
| 196 | 229 | pub const sa_family_t = u8; |
| 197 | 230 | |
| ... | ... | @@ -1408,3 +1441,10 @@ pub const rlimit = extern struct { |
| 1408 | 1441 | pub const SHUT_RD = 0; |
| 1409 | 1442 | pub const SHUT_WR = 1; |
| 1410 | 1443 | pub const SHUT_RDWR = 2; |
| 1444 | ||
| 1445 | // TODO fill out if needed | |
| 1446 | pub const directory_which = extern enum(c_int) { | |
| 1447 | B_USER_SETTINGS_DIRECTORY = 0xbbe, | |
| 1448 | ||
| 1449 | _, | |
| 1450 | }; |
lib/std/target.zig+1-2| ... | ... | @@ -1566,8 +1566,7 @@ pub const Target = struct { |
| 1566 | 1566 | .other, |
| 1567 | 1567 | => return result, |
| 1568 | 1568 | |
| 1569 | // Operating systems in this list have been verified as not having a standard | |
| 1570 | // dynamic linker path. | |
| 1569 | // TODO revisit when multi-arch for Haiku is available | |
| 1571 | 1570 | .haiku => return copy(&result, "/system/runtime_loader"), |
| 1572 | 1571 | |
| 1573 | 1572 | // TODO go over each item in this list and either move it to the above list, or |
src/libc_installation.zig+1| ... | ... | @@ -196,6 +196,7 @@ pub const LibCInstallation = struct { |
| 196 | 196 | switch (Target.current.os.tag) { |
| 197 | 197 | .freebsd, .netbsd, .openbsd => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"), |
| 198 | 198 | .linux, .dragonfly => batch.add(&async self.findNativeCrtDirPosix(args)), |
| 199 | .haiku => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/system/develop/lib"), | |
| 199 | 200 | else => {}, |
| 200 | 201 | } |
| 201 | 202 | break :blk batch.wait(); |