bootstrap: replace bare string message with fs.open()
This commit is contained in:
@@ -5,7 +5,7 @@ set_property(SOURCE ${arch_sources} PROPERTY LANGUAGE C)
|
|||||||
|
|
||||||
add_executable(bootstrap ${c_sources} ${arch_sources})
|
add_executable(bootstrap ${c_sources} ${arch_sources})
|
||||||
|
|
||||||
target_link_libraries(bootstrap libmango ulibc liblaunch)
|
target_link_libraries(bootstrap libmango ulibc liblaunch libmsg-fs)
|
||||||
|
|
||||||
target_compile_options(bootstrap PRIVATE
|
target_compile_options(bootstrap PRIVATE
|
||||||
-fPIC -pie -fno-stack-protector -nostdlib -ffreestanding)
|
-fPIC -pie -fno-stack-protector -nostdlib -ffreestanding)
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
#include <mango/msg.h>
|
#include <mango/msg.h>
|
||||||
#include <mango/task.h>
|
#include <mango/task.h>
|
||||||
#include <mango/types.h>
|
#include <mango/types.h>
|
||||||
|
#include <rosetta/msg.h>
|
||||||
|
#include <rosetta/msg/fs.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define INIT_PATH "/usr/bin/test"
|
#define INIT_PATH "/usr/bin/test"
|
||||||
|
|
||||||
@@ -98,27 +99,47 @@ int main(
|
|||||||
kern_logf("launch result: %d", status);
|
kern_logf("launch result: %d", status);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
char msg_buf[512];
|
|
||||||
struct iovec vec = {
|
|
||||||
.io_base = (virt_addr_t)msg_buf,
|
|
||||||
.io_len = sizeof msg_buf,
|
|
||||||
};
|
|
||||||
struct msg msg = {.msg_data = &vec, .msg_data_count = 1};
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
msgid_t id = 0;
|
msgid_t id;
|
||||||
kern_status_t kstatus = msg_recv(channel, 0, &id, &msg);
|
struct rosetta_msg msg;
|
||||||
if (kstatus != KERN_OK) {
|
kern_status_t status = rosetta_msg_recv(channel, &id, &msg);
|
||||||
kern_logf("msg_recv failed %d", kstatus);
|
if (status != KERN_OK) {
|
||||||
break;
|
kern_logf("message recv error %d", status);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
kern_logf("received message %zx: %s", id, msg_buf);
|
if (msg.msg_protocol != ROSETTA_MSG_FS) {
|
||||||
|
kern_logf(
|
||||||
|
"unknown message protocol %u",
|
||||||
|
msg.msg_protocol);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
size_t len = snprintf(msg_buf, sizeof msg_buf, "Goodbye!");
|
if (msg.msg_id != ROSETTA_MSG_FS_OPEN) {
|
||||||
vec.io_len = len + 1;
|
kern_logf("unknown message function %u", msg.msg_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
msg_reply(channel, 0, id, &msg);
|
char path[4096];
|
||||||
|
int flags;
|
||||||
|
struct rosetta_msg_string path_str = {
|
||||||
|
.s_buf = path,
|
||||||
|
.s_max = sizeof path,
|
||||||
|
};
|
||||||
|
status = rosetta_msg_fs_open_recv(
|
||||||
|
channel,
|
||||||
|
id,
|
||||||
|
&path_str,
|
||||||
|
&flags);
|
||||||
|
if (status != KERN_OK) {
|
||||||
|
kern_logf("rosetta.fs.open recv error %d", status);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
kern_logf("open(%s, %d)", path, flags);
|
||||||
|
|
||||||
|
rosetta_msg_fs_open_reply(channel, id, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user