From 14799e0d58cd4cc2d965725769e251245dda36e9 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 10 Mar 2026 19:16:46 +0000 Subject: [PATCH] ld: use unistd i/o functions to open/read library files --- sys/ld/CMakeLists.txt | 2 +- sys/ld/main.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/sys/ld/CMakeLists.txt b/sys/ld/CMakeLists.txt index 9e0d842..8e178a6 100644 --- a/sys/ld/CMakeLists.txt +++ b/sys/ld/CMakeLists.txt @@ -10,7 +10,7 @@ set_target_properties(ld PROPERTIES SUFFIX ".so") target_link_libraries(ld - libc-core libc-malloc libmango librosetta + libc-core libc-malloc libc-io libmango librosetta libxpc-static interface::fs) target_compile_options(ld PRIVATE diff --git a/sys/ld/main.c b/sys/ld/main.c index 9f9b3d9..feab04d 100644 --- a/sys/ld/main.c +++ b/sys/ld/main.c @@ -1,6 +1,7 @@ #define MSG_IMPLEMENTATION #define MSG_NO_MALLOC +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include int main(const struct rosetta_bootstrap *bs) @@ -24,32 +26,39 @@ int main(const struct rosetta_bootstrap *bs) kern_logf("argv[%zu]: %s", i, bs->bs_argv[i]); } - kern_handle_t port; - kern_status_t status = port_create(&port); - if (status != KERN_OK) { - kern_logf("port creation failed %d", status); - return -1; - } - - port_connect(port, 0, 0); - + sys_remote_set(SYS_REMOTE_NSD, 0, 0); const char *path = "/usr/lib/libc.so"; int flags = 4; - int err = 0; + int fd = open(path, flags); kern_logf("sending msg: open(%s, %d)", path, flags); - status = fs_open(port, path, flags, &err); - if (status != KERN_OK) { - kern_logf("open call failed (status %d)", status); - } else { + if (fd < 0) { kern_logf( "open(%s, %d) = %s (%s)", path, flags, - strerror_code(err), - strerror(err)); + strerror_code(fd), + strerror(fd)); + return -1; } + kern_logf( + "open(%s, %d) = %s (%s)", + path, + flags, + strerror_code(SUCCESS), + strerror(SUCCESS)); + + unsigned char buf[32] = {0}; + int nr = read(fd, buf, sizeof buf); + + if (nr < 0) { + kern_logf("read call failed (%s)", strerror(nr)); + return -1; + } + + kern_logf("data: %x %c %c %c", buf[0], buf[1], buf[2], buf[3]); + return 0; }