ld: use unistd i/o functions to open/read library files
This commit is contained in:
@@ -10,7 +10,7 @@ set_target_properties(ld PROPERTIES
|
|||||||
SUFFIX ".so")
|
SUFFIX ".so")
|
||||||
|
|
||||||
target_link_libraries(ld
|
target_link_libraries(ld
|
||||||
libc-core libc-malloc libmango librosetta
|
libc-core libc-malloc libc-io libmango librosetta libxpc-static
|
||||||
interface::fs)
|
interface::fs)
|
||||||
|
|
||||||
target_compile_options(ld PRIVATE
|
target_compile_options(ld PRIVATE
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#define MSG_IMPLEMENTATION
|
#define MSG_IMPLEMENTATION
|
||||||
#define MSG_NO_MALLOC
|
#define MSG_NO_MALLOC
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <heap/heap.h>
|
#include <heap/heap.h>
|
||||||
#include <mango/log.h>
|
#include <mango/log.h>
|
||||||
#include <mango/msg.h>
|
#include <mango/msg.h>
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/remote.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(const struct rosetta_bootstrap *bs)
|
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_logf("argv[%zu]: %s", i, bs->bs_argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
kern_handle_t port;
|
sys_remote_set(SYS_REMOTE_NSD, 0, 0);
|
||||||
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);
|
|
||||||
|
|
||||||
const char *path = "/usr/lib/libc.so";
|
const char *path = "/usr/lib/libc.so";
|
||||||
int flags = 4;
|
int flags = 4;
|
||||||
int err = 0;
|
int fd = open(path, flags);
|
||||||
|
|
||||||
kern_logf("sending msg: open(%s, %d)", path, flags);
|
kern_logf("sending msg: open(%s, %d)", path, flags);
|
||||||
status = fs_open(port, path, flags, &err);
|
|
||||||
|
|
||||||
if (status != KERN_OK) {
|
if (fd < 0) {
|
||||||
kern_logf("open call failed (status %d)", status);
|
|
||||||
} else {
|
|
||||||
kern_logf(
|
kern_logf(
|
||||||
"open(%s, %d) = %s (%s)",
|
"open(%s, %d) = %s (%s)",
|
||||||
path,
|
path,
|
||||||
flags,
|
flags,
|
||||||
strerror_code(err),
|
strerror_code(fd),
|
||||||
strerror(err));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user