Files
rosetta/sys/ld/main.c

65 lines
1.2 KiB
C

#define MSG_IMPLEMENTATION
#define MSG_NO_MALLOC
#include <errno.h>
#include <heap/heap.h>
#include <mango/log.h>
#include <mango/msg.h>
#include <mango/task.h>
#include <mango/types.h>
#include <mango/vm.h>
#include <rosetta/bootstrap.h>
#include <rosetta/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/remote.h>
#include <unistd.h>
int main(const struct rosetta_bootstrap *bs)
{
kern_handle_t task, address_space;
task_self(&task);
task_get_address_space(task, &address_space);
for (size_t i = 0; i < bs->bs_argc; i++) {
kern_logf("argv[%zu]: %s", i, bs->bs_argv[i]);
}
sys_remote_set(SYS_REMOTE_NSD, 0, 0);
const char *path = "/usr/lib/libc.so";
int flags = 4;
int fd = open(path, flags);
kern_logf("sending msg: open(%s, %d)", path, flags);
if (fd < 0) {
kern_logf(
"open(%s, %d) = %s (%s)",
path,
flags,
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;
}