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 {...@@ -577,11 +577,12 @@ const PosixThreadImpl = struct {
577 };577 };
578 },578 },
579 .haiku => {579 .haiku => {
580 var count: u32 = undefined;580 var system_info: os.system.system_info = undefined;
581 var system_info: os.system_info = undefined;581 const rc = os.system.get_system_info(&system_info); // always returns B_OK
582 _ = os.system.get_system_info(&system_info); // always returns B_OK582 return switch (os.errno(rc)) {
583 count = system_info.cpu_count;583 .SUCCESS => @intCast(usize, system_info.cpu_count),
584 return @intCast(usize, count);584 else => |err| os.unexpectedErrno(err),
585 };
585 },586 },
586 else => {587 else => {
587 var count: c_int = undefined;588 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;...@@ -14,8 +14,12 @@ pub extern "c" fn find_thread(thread_name: ?*c_void) i32;
1414
15pub extern "c" fn get_system_info(system_info: *system_info) usize;15pub 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
17// TODO revisit if abi changes or better option becomes apparent21// 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
20pub extern "c" fn _kern_read_dir(fd: c_int, buf_ptr: [*]u8, nbytes: usize, maxcount: u32) usize;24pub 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) {...@@ -112,6 +116,12 @@ pub const EAI = enum(c_int) {
112116
113pub const EAI_MAX = 15;117pub const EAI_MAX = 15;
114118
119pub const AI = struct {
120 pub const NUMERICSERV = 0x00000008;
121};
122
123pub const AI_NUMERICSERV = AI.NUMERICSERV;
124
115pub const fd_t = c_int;125pub const fd_t = c_int;
116pub const pid_t = c_int;126pub const pid_t = c_int;
117pub const uid_t = u32;127pub const uid_t = u32;
...@@ -282,15 +292,29 @@ pub const dirent = extern struct {...@@ -282,15 +292,29 @@ pub const dirent = extern struct {
282 }292 }
283};293};
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
285pub const image_info = extern struct {309pub const image_info = extern struct {
286 id: u32,310 id: u32,
287 type: u32,311 image_type: u32,
288 sequence: i32,312 sequence: i32,
289 init_order: i32,313 init_order: i32,
290 init_routine: *c_void,314 init_routine: *c_void,
291 term_routine: *c_void,315 term_routine: *c_void,
292 device: i32,316 device: i32,
293 node: i32,317 node: i64,
294 name: [1024]u8,318 name: [1024]u8,
295 text: *c_void,319 text: *c_void,
296 data: *c_void,320 data: *c_void,
...@@ -328,6 +352,19 @@ pub const system_info = extern struct {...@@ -328,6 +352,19 @@ pub const system_info = extern struct {
328 abi: u32,352 abi: u32,
329};353};
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
331pub const in_port_t = u16;368pub const in_port_t = u16;
332pub const sa_family_t = u8;369pub const sa_family_t = u8;
333370
...@@ -374,8 +411,11 @@ pub const CTL = struct {...@@ -374,8 +411,11 @@ pub const CTL = struct {
374pub const KERN = struct {411pub const KERN = struct {
375 pub const PROC = 14; // struct: process entries412 pub const PROC = 14; // struct: process entries
376 pub const PROC_PATHNAME = 12; // path to executable413 pub const PROC_PATHNAME = 12; // path to executable
414 pub const IOV_MAX = 1024;
377};415};
378416
417pub const IOV_MAX = KERN.IOV_MAX;
418
379pub const PATH_MAX = 1024;419pub const PATH_MAX = 1024;
380420
381pub const STDIN_FILENO = 0;421pub const STDIN_FILENO = 0;
...@@ -400,18 +440,13 @@ pub const MAP = struct {...@@ -400,18 +440,13 @@ pub const MAP = struct {
400 pub const FAILED = @intToPtr(*c_void, maxInt(usize));440 pub const FAILED = @intToPtr(*c_void, maxInt(usize));
401 pub const SHARED = 0x0001;441 pub const SHARED = 0x0001;
402 pub const PRIVATE = 0x0002;442 pub const PRIVATE = 0x0002;
403 pub const FIXED = 0x0010;443 pub const FIXED = 0x0004;
404 pub const STACK = 0x0400;444 pub const STACK = 0x0400;
405 pub const NOSYNC = 0x0800;445 pub const NOSYNC = 0x0800;
406 pub const ANON = 0x1000;446 pub const ANON = 0x0008;
407 pub const ANONYMOUS = ANON;447 pub const ANONYMOUS = ANON;
408 pub const FILE = 0;448 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;
415};450};
416451
417pub const W = struct {452pub const W = struct {
...@@ -535,8 +570,6 @@ pub const O = struct {...@@ -535,8 +570,6 @@ pub const O = struct {
535 pub const RDWR = 0x0002;570 pub const RDWR = 0x0002;
536 pub const ACCMODE = 0x0003;571 pub const ACCMODE = 0x0003;
537572
538 pub const SHLOCK = 0x0010;
539 pub const EXLOCK = 0x0020;
540573
541 pub const CREAT = 0x0200;574 pub const CREAT = 0x0200;
542 pub const EXCL = 0x0800;575 pub const EXCL = 0x0800;
...@@ -549,7 +582,7 @@ pub const O = struct {...@@ -549,7 +582,7 @@ pub const O = struct {
549 pub const RSYNC = 0o4010000;582 pub const RSYNC = 0o4010000;
550 pub const DIRECTORY = 0x20000;583 pub const DIRECTORY = 0x20000;
551 pub const NOFOLLOW = 0x0100;584 pub const NOFOLLOW = 0x0100;
552 pub const CLOEXEC = 0x00100000;585 pub const CLOEXEC = 0x00000040;
553586
554 pub const ASYNC = 0x0040;587 pub const ASYNC = 0x0040;
555 pub const DIRECT = 0x00010000;588 pub const DIRECT = 0x00010000;
...@@ -1405,3 +1438,6 @@ pub const termios = extern struct {...@@ -1405,3 +1438,6 @@ pub const termios = extern struct {
1405 c_ospeed: speed_t,1438 c_ospeed: speed_t,
1406 cc_t: [NCCS]cc_t,1439 cc_t: [NCCS]cc_t,
1407};1440};
1441
1442pub const MSG_NOSIGNAL = 0x0800;
1443
lib/std/fs.zig+11-1
...@@ -527,13 +527,23 @@ pub const Dir = struct {...@@ -527,13 +527,23 @@ pub const Dir = struct {
527 }527 }
528528
529 var stat_info: os.Stat = undefined;529 var stat_info: os.Stat = undefined;
530 _ = os.system._kern_read_stat(530 const rc = os.system._kern_read_stat(
531 self.dir.fd,531 self.dir.fd,
532 &haiku_entry.d_name,532 &haiku_entry.d_name,
533 false,533 false,
534 &stat_info,534 &stat_info,
535 0,535 0,
536 );536 );
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 }
537 const statmode = stat_info.mode & os.S.IFMT;547 const statmode = stat_info.mode & os.S.IFMT;
538548
539 const entry_kind = switch (statmode) {549 const entry_kind = switch (statmode) {