支持mac m1编译,ns功能测试
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
.syntax unified
|
||||
.section .first, #execinstr
|
||||
.section .first
|
||||
|
||||
.globl reloc
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.syntax unified
|
||||
.section .first, #execinstr
|
||||
.section .first
|
||||
|
||||
.globl reloc
|
||||
.globl data_offset
|
||||
|
||||
6
mkrtos_user/lib/sys_util/inc/u_ns.h
Normal file
6
mkrtos_user/lib/sys_util/inc/u_ns.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "u_types.h"
|
||||
|
||||
int cli_ns_register(const char *name, obj_handler_t hd);
|
||||
int cli_ns_query(const char *name, obj_handler_t *ret_hd);
|
||||
93
mkrtos_user/lib/sys_util/src/u_ns.c
Normal file
93
mkrtos_user/lib/sys_util/src/u_ns.c
Normal file
@@ -0,0 +1,93 @@
|
||||
|
||||
|
||||
#include "u_types.h"
|
||||
#include "u_ipc.h"
|
||||
#include "u_thread.h"
|
||||
#include "u_prot.h"
|
||||
#include "u_env.h"
|
||||
#include "u_arch.h"
|
||||
#include "u_util.h"
|
||||
#include "u_hd_man.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
enum ns_op
|
||||
{
|
||||
OP_REGISTER,
|
||||
OP_QUERY,
|
||||
};
|
||||
/**
|
||||
* @brief 暂时手动填充数据,后期改为RPC。TODO:
|
||||
*
|
||||
* @param buf
|
||||
* @param len
|
||||
* @return int
|
||||
*/
|
||||
int cli_ns_register(const char *name, obj_handler_t hd)
|
||||
{
|
||||
ipc_msg_t *ipc_msg;
|
||||
msg_tag_t tag;
|
||||
void *buf;
|
||||
|
||||
int len = strlen(name);
|
||||
|
||||
len = MIN(len, IPC_MSG_SIZE - WORD_BYTES * 2 - 1);
|
||||
// 获取发送数据的buf
|
||||
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||
ipc_msg = (ipc_msg_t *)buf;
|
||||
// 发送的正常数据
|
||||
ipc_msg->msg_buf[0] = OP_REGISTER;
|
||||
ipc_msg->msg_buf[1] = len + 1;
|
||||
// 映射数据
|
||||
ipc_msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
|
||||
|
||||
strncpy((char *)(&ipc_msg->msg_buf[2]), name, IPC_MSG_SIZE - WORD_BYTES * 2);
|
||||
((char *)(&ipc_msg->msg_buf[2]))[IPC_MSG_SIZE - WORD_BYTES * 2 - 1] = 0;
|
||||
|
||||
// 发送ipc
|
||||
tag = ipc_call(u_get_global_env()->ns_hd,
|
||||
msg_tag_init4(0, 2 + ROUND_UP(len, WORD_BYTES), 1, 0),
|
||||
ipc_timeout_create2(0, 0));
|
||||
return msg_tag_get_val(tag);
|
||||
}
|
||||
int cli_ns_query(const char *name, obj_handler_t *ret_hd)
|
||||
{
|
||||
ipc_msg_t *ipc_msg;
|
||||
msg_tag_t tag;
|
||||
void *buf;
|
||||
obj_handler_t new_fd;
|
||||
assert(ret_hd);
|
||||
|
||||
new_fd = handler_alloc();
|
||||
|
||||
if (new_fd == HANDLER_INVALID)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
int len = strlen(name);
|
||||
|
||||
len = MIN(len, IPC_MSG_SIZE - WORD_BYTES * 2 - 1);
|
||||
// 获取发送数据的buf
|
||||
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||
ipc_msg = (ipc_msg_t *)buf;
|
||||
// 发送的正常数据
|
||||
ipc_msg->msg_buf[0] = OP_QUERY;
|
||||
ipc_msg->msg_buf[1] = len + 1;
|
||||
// 映射数据
|
||||
ipc_msg->map_buf[0] = vpage_create_raw3(0, 0, new_fd).raw;
|
||||
|
||||
strncpy((char *)(&ipc_msg->msg_buf[2]), name, IPC_MSG_SIZE - WORD_BYTES * 2);
|
||||
((char *)(&ipc_msg->msg_buf[2]))[IPC_MSG_SIZE - WORD_BYTES * 2 - 1] = 0;
|
||||
|
||||
// 发送ipc
|
||||
tag = ipc_call(u_get_global_env()->ns_hd,
|
||||
msg_tag_init4(0, 2 + ROUND_UP(len, WORD_BYTES), 0, 0),
|
||||
ipc_timeout_create2(0, 0));
|
||||
|
||||
if (msg_tag_get_val(tag) < 0)
|
||||
{
|
||||
handler_free_umap(new_fd);
|
||||
}
|
||||
|
||||
return msg_tag_get_val(tag);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ add_dependencies(
|
||||
)
|
||||
set_target_properties(
|
||||
fatfs.elf PROPERTIES LINK_FLAGS
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section "
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section -no-dynamic-linker --no-warn-rwx-segments"
|
||||
)
|
||||
add_custom_target(
|
||||
fatfs_dump ALL
|
||||
|
||||
@@ -33,7 +33,7 @@ add_dependencies(init.elf
|
||||
muslc
|
||||
)
|
||||
set_target_properties(init.elf PROPERTIES LINK_FLAGS
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section "
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section -no-dynamic-linker --no-warn-rwx-segments"
|
||||
)
|
||||
#-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds
|
||||
add_custom_target(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
ENTRY(_start_)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
typedef struct namespace_entry
|
||||
{
|
||||
char path[NAMESPACE_PATH_LEN];
|
||||
obj_handler_t hd;
|
||||
char path[NAMESPACE_PATH_LEN]; //!< 服务的路径名
|
||||
obj_handler_t hd; //!< 服务的fd
|
||||
} namespace_entry_t;
|
||||
|
||||
typedef struct namespace
|
||||
{
|
||||
namespace_entry_t ne_list[NAMESAPCE_NR];
|
||||
namespace_entry_t ne_list[NAMESAPCE_NR]; //!< 服务列表
|
||||
}
|
||||
namespace_t;
|
||||
|
||||
@@ -79,7 +79,7 @@ int ns_query(const char *path, obj_handler_t *hd)
|
||||
{
|
||||
for (int i = 0; i < NAMESAPCE_NR; i++)
|
||||
{
|
||||
if (ns.ne_list[i].hd == HANDLER_INVALID)
|
||||
if (ns.ne_list[i].hd != HANDLER_INVALID)
|
||||
{
|
||||
if (strncmp(ns.ne_list[i].path, path, NAMESPACE_PATH_LEN) == 0)
|
||||
{
|
||||
@@ -90,7 +90,7 @@ int ns_query(const char *path, obj_handler_t *hd)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
obj_handler_t pre_alloc_hd = HANDLER_INVALID;
|
||||
obj_handler_t pre_alloc_hd = HANDLER_INVALID; //!< 预备一个可用的fd
|
||||
int ns_pre_alloc_map_fd(ipc_msg_t *msg)
|
||||
{
|
||||
obj_handler_t hd = handler_alloc();
|
||||
@@ -110,7 +110,7 @@ msg_tag_t ns_dispatch(ipc_msg_t *msg)
|
||||
|
||||
switch (msg->msg_buf[0])
|
||||
{
|
||||
case OP_REGISTER:
|
||||
case OP_REGISTER: //!< 服务注册
|
||||
{
|
||||
size_t len = msg->msg_buf[1];
|
||||
if (len > NAMESPACE_PATH_LEN)
|
||||
@@ -124,9 +124,24 @@ msg_tag_t ns_dispatch(ipc_msg_t *msg)
|
||||
tag = msg_tag_init4(0, 0, 0, ret);
|
||||
}
|
||||
break;
|
||||
case OP_QUERY:
|
||||
tag = msg_tag_init4(0, 0, 0, 0);
|
||||
break;
|
||||
case OP_QUERY: //!< 服务申请
|
||||
{
|
||||
obj_handler_t hd;
|
||||
int ret = ns_query(((char *)&(msg->msg_buf[2])), &hd);
|
||||
if (ret < 0)
|
||||
{
|
||||
tag = msg_tag_init4(0, 0, 0, ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t len = msg->msg_buf[1];
|
||||
|
||||
msg->map_buf[0] = hd;
|
||||
printf("query..\n");
|
||||
tag = msg_tag_init4(0, 0, 1, ret);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
tag = msg_tag_init4(0, 0, 0, -ENOSYS);
|
||||
break;
|
||||
|
||||
@@ -38,7 +38,7 @@ add_dependencies(shell.elf
|
||||
muslc
|
||||
)
|
||||
set_target_properties(shell.elf PROPERTIES LINK_FLAGS
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section "
|
||||
"-T ${CMAKE_CURRENT_SOURCE_DIR}/link.lds -pie --gc-section -no-dynamic-linker --no-warn-rwx-segments"
|
||||
)
|
||||
add_custom_target(
|
||||
shell_dump ALL
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
ENTRY(_start_)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include "u_ipc.h"
|
||||
#include "u_env.h"
|
||||
#include "u_hd_man.h"
|
||||
#include "u_ns.h"
|
||||
#include "test.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
void malloc_test(void)
|
||||
{
|
||||
void *mem = malloc(1024);
|
||||
@@ -30,24 +32,18 @@ void malloc_test(void)
|
||||
}
|
||||
void ns_test(void)
|
||||
{
|
||||
char *buf;
|
||||
ipc_msg_t *ipc_msg;
|
||||
int ret;
|
||||
obj_handler_t tmp_ipc_hd;
|
||||
|
||||
tmp_ipc_hd = handler_alloc();
|
||||
assert(tmp_ipc_hd != HANDLER_INVALID);
|
||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, tmp_ipc_hd));
|
||||
assert(msg_tag_get_val(tag) >= 0);
|
||||
|
||||
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||
ipc_msg = (ipc_msg_t *)buf;
|
||||
ipc_msg->msg_buf[0] = 0;
|
||||
ipc_msg->msg_buf[1] = strlen("shell") + 1;
|
||||
ipc_msg->map_buf[0] = vpage_create_raw3(0, 0, tmp_ipc_hd).raw;
|
||||
strcpy((char *)(&ipc_msg->msg_buf[2]), "shell");
|
||||
tag = ipc_call(u_get_global_env()->ns_hd, msg_tag_init4(0, 2 + ROUND_UP(strlen("shell"), WORD_BYTES), 1, 0), ipc_timeout_create2(0, 0));
|
||||
printf("msg %d\n", tag.msg_buf_len);
|
||||
handler_free_umap(tmp_ipc_hd);
|
||||
ret = cli_ns_register("shell", tmp_ipc_hd);
|
||||
assert(ret >= 0);
|
||||
ret = cli_ns_query("shell", &tmp_ipc_hd);
|
||||
assert(ret >= 0);
|
||||
|
||||
}
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user