authorgravatar for 3811822-hoanga@users.noreply.gitlab.comAl Hoang <3811822-hoanga@users.noreply.gitlab.com> 2021-10-31 21:27:04-05:00
committergravatar for 3811822-hoanga@users.noreply.gitlab.comAl Hoang <3811822-hoanga@users.noreply.gitlab.com> 2021-11-15 00:29:26-06:00
log426f54026bed049cfd40839a8b432c2892fc8212
tree3ffd079e7fbed9099db68753afe6182e9a1e488b
parentb875f79dd8807fee1aec8bf443b43ec4f3b53fa9

updates for haiku stdc

* add team_info, area_info * update signature for get_next_image_info * add error checks for haiku system calls * update and cleanup of haiku constants

3 files changed, 66 insertions(+), 19 deletions(-)

lib/std/Thread.zig+6-5
......@@ -577,11 +577,12 @@ const PosixThreadImpl = struct {
577577 };
578578 },
579579 .haiku => {
580 var count: u32 = undefined;
581 var system_info: os.system_info = undefined;
582 _ = os.system.get_system_info(&system_info); // always returns B_OK
583 count = system_info.cpu_count;
584 return @intCast(usize, count);
580 var system_info: os.system.system_info = undefined;
581 const rc = os.system.get_system_info(&system_info); // always returns B_OK
582 return switch (os.errno(rc)) {
583 .SUCCESS => @intCast(usize, system_info.cpu_count),
584 else => |err| os.unexpectedErrno(err),
585 };
585586 },
586587 else => {
587588 var count: c_int = undefined;
lib/std/c/haiku.zig+49-13
......@@ -14,8 +14,12 @@ pub extern "c" fn find_thread(thread_name: ?*c_void) i32;
1414
1515pub extern "c" fn get_system_info(system_info: *system_info) usize;
1616
17pub extern "c" fn _get_team_info(team: c_int, team_info: *team_info, size: usize) i32;
18
19pub extern "c" fn _get_next_area_info(team: c_int, cookie: *i64, area_info: *area_info, size: usize) i32;
20
1721// TODO revisit if abi changes or better option becomes apparent
18pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info) usize;
22pub extern "c" fn _get_next_image_info(team: c_int, cookie: *i32, image_info: *image_info, size: usize) i32;
1923
2024pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;
2125
......@@ -112,6 +116,12 @@ pub const EAI = enum(c_int) {
112116
113117pub const EAI_MAX = 15;
114118
119pub const AI = struct {
120 pub const NUMERICSERV = 0x00000008;
121};
122
123pub const AI_NUMERICSERV = AI.NUMERICSERV;
124
115125pub const fd_t = c_int;
116126pub const pid_t = c_int;
117127pub const uid_t = u32;
......@@ -282,15 +292,29 @@ pub const dirent = extern struct {
282292 }
283293};
284294
295pub const area_info = extern struct {
296 area: u32,
297 name: [32]u8,
298 size: usize,
299 lock: u32,
300 protection: u32,
301 team_id: i32,
302 ram_size: u32,
303 copy_count: u32,
304 in_count: u32,
305 out_count: u32,
306 address: *c_void,
307};
308
285309pub const image_info = extern struct {
286310 id: u32,
287 type: u32,
311 image_type: u32,
288312 sequence: i32,
289313 init_order: i32,
290314 init_routine: *c_void,
291315 term_routine: *c_void,
292316 device: i32,
293 node: i32,
317 node: i64,
294318 name: [1024]u8,
295319 text: *c_void,
296320 data: *c_void,
......@@ -328,6 +352,19 @@ pub const system_info = extern struct {
328352 abi: u32,
329353};
330354
355pub const team_info = extern struct {
356 team_id: i32,
357 thread_count: i32,
358 image_count: i32,
359 area_count: i32,
360 debugger_nub_thread: i32,
361 debugger_nub_port: i32,
362 argc: i32,
363 args: [64]u8,
364 uid: uid_t,
365 gid: gid_t,
366};
367
331368pub const in_port_t = u16;
332369pub const sa_family_t = u8;
333370
......@@ -374,8 +411,11 @@ pub const CTL = struct {
374411pub const KERN = struct {
375412 pub const PROC = 14; // struct: process entries
376413 pub const PROC_PATHNAME = 12; // path to executable
414 pub const IOV_MAX = 1024;
377415};
378416
417pub const IOV_MAX = KERN.IOV_MAX;
418
379419pub const PATH_MAX = 1024;
380420
381421pub const STDIN_FILENO = 0;
......@@ -400,18 +440,13 @@ pub const MAP = struct {
400440 pub const FAILED = @intToPtr(*c_void, maxInt(usize));
401441 pub const SHARED = 0x0001;
402442 pub const PRIVATE = 0x0002;
403 pub const FIXED = 0x0010;
443 pub const FIXED = 0x0004;
404444 pub const STACK = 0x0400;
405445 pub const NOSYNC = 0x0800;
406 pub const ANON = 0x1000;
446 pub const ANON = 0x0008;
407447 pub const ANONYMOUS = ANON;
408448 pub const FILE = 0;
409449
410 pub const GUARD = 0x00002000;
411 pub const EXCL = 0x00004000;
412 pub const NOCORE = 0x00020000;
413 pub const PREFAULT_READ = 0x00040000;
414 pub const @"32BIT" = 0x00080000;
415450};
416451
417452pub const W = struct {
......@@ -535,8 +570,6 @@ pub const O = struct {
535570 pub const RDWR = 0x0002;
536571 pub const ACCMODE = 0x0003;
537572
538 pub const SHLOCK = 0x0010;
539 pub const EXLOCK = 0x0020;
540573
541574 pub const CREAT = 0x0200;
542575 pub const EXCL = 0x0800;
......@@ -549,7 +582,7 @@ pub const O = struct {
549582 pub const RSYNC = 0o4010000;
550583 pub const DIRECTORY = 0x20000;
551584 pub const NOFOLLOW = 0x0100;
552 pub const CLOEXEC = 0x00100000;
585 pub const CLOEXEC = 0x00000040;
553586
554587 pub const ASYNC = 0x0040;
555588 pub const DIRECT = 0x00010000;
......@@ -1405,3 +1438,6 @@ pub const termios = extern struct {
14051438 c_ospeed: speed_t,
14061439 cc_t: [NCCS]cc_t,
14071440};
1441
1442pub const MSG_NOSIGNAL = 0x0800;
1443
lib/std/fs.zig+11-1
......@@ -527,13 +527,23 @@ pub const Dir = struct {
527527 }
528528
529529 var stat_info: os.Stat = undefined;
530 _ = os.system._kern_read_stat(
530 const rc = os.system._kern_read_stat(
531531 self.dir.fd,
532532 &haiku_entry.d_name,
533533 false,
534534 &stat_info,
535535 0,
536536 );
537 if (rc != 0) {
538 switch (os.errno(rc)) {
539 .SUCCESS => {},
540 .BADF => unreachable, // Dir is invalid or was opened without iteration ability
541 .FAULT => unreachable,
542 .NOTDIR => unreachable,
543 .INVAL => unreachable,
544 else => |err| return os.unexpectedErrno(err),
545 }
546 }
537547 const statmode = stat_info.mode & os.S.IFMT;
538548
539549 const entry_kind = switch (statmode) {