lib: msg: implement generic messave init and receive
This commit is contained in:
@@ -18,4 +18,4 @@ sysroot_add_library(
|
|||||||
HEADER_DIR /usr/include
|
HEADER_DIR /usr/include
|
||||||
LIB_DIR /usr/lib)
|
LIB_DIR /usr/lib)
|
||||||
|
|
||||||
target_link_libraries(libmsg libmango)
|
target_link_libraries(libmsg libmango ulibc)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#define ROSETTA_MSG_MAGIC 0x9AB07D10U
|
#define ROSETTA_MSG_MAGIC 0x9AB07D10U
|
||||||
|
|
||||||
|
#include <mango/msg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct rosetta_msg {
|
struct rosetta_msg {
|
||||||
@@ -12,4 +13,19 @@ struct rosetta_msg {
|
|||||||
uint16_t msg_reserved;
|
uint16_t msg_reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct rosetta_msg_string {
|
||||||
|
char *s_buf;
|
||||||
|
size_t s_len;
|
||||||
|
size_t s_max;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void rosetta_msg_init(
|
||||||
|
struct rosetta_msg *msg,
|
||||||
|
uint32_t protocol_id,
|
||||||
|
uint16_t msg_id);
|
||||||
|
extern kern_status_t rosetta_msg_recv(
|
||||||
|
kern_handle_t channel,
|
||||||
|
msgid_t *out_id,
|
||||||
|
struct rosetta_msg *out_msg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,3 +1,33 @@
|
|||||||
void msg_tmp(void)
|
#include <rosetta/msg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void rosetta_msg_init(
|
||||||
|
struct rosetta_msg *msg,
|
||||||
|
uint32_t protocol_id,
|
||||||
|
uint16_t msg_id)
|
||||||
{
|
{
|
||||||
|
memset(msg, 0x0, sizeof *msg);
|
||||||
|
|
||||||
|
msg->msg_magic = ROSETTA_MSG_MAGIC;
|
||||||
|
msg->msg_protocol = protocol_id;
|
||||||
|
msg->msg_id = msg_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
kern_status_t rosetta_msg_recv(
|
||||||
|
kern_handle_t channel,
|
||||||
|
msgid_t *out_id,
|
||||||
|
struct rosetta_msg *out_msg)
|
||||||
|
{
|
||||||
|
struct iovec iov = IOVEC(out_msg, sizeof *out_msg);
|
||||||
|
struct msg kmsg = MSG(&iov, 1, NULL, 0);
|
||||||
|
kern_status_t status = msg_recv(channel, 0, out_id, &kmsg);
|
||||||
|
if (status != KERN_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_msg->msg_magic != ROSETTA_MSG_MAGIC) {
|
||||||
|
return KERN_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return KERN_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user