修复一些bug
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -270,7 +270,8 @@
|
||||
"shell_passthrough.h": "c",
|
||||
"u_slist.h": "c",
|
||||
"atomic": "c",
|
||||
"futex.h": "c"
|
||||
"futex.h": "c",
|
||||
"u_rpc_buf.h": "c"
|
||||
},
|
||||
"cortex-debug.showRTOS": false,
|
||||
"cortex-debug.variableUseNaturalFormat": false,
|
||||
|
||||
@@ -195,7 +195,7 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
|
||||
if (!source_kobj)
|
||||
{
|
||||
spinlock_set(&tag_task->kobj.lock, status);
|
||||
tag = msg_tag_init4(0, 0, 0, -ENOENT);
|
||||
tag = msg_tag_init4(0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
spinlock_set(&tag_task->kobj.lock, status);
|
||||
|
||||
@@ -512,8 +512,9 @@ static int thread_ipc_reply(msg_tag_t in_tag)
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
cpulock_set(status);
|
||||
return ret;
|
||||
// cpulock_set(status);
|
||||
// return ret;
|
||||
in_tag.prot = ret;
|
||||
}
|
||||
cur_th->last_send_th->msg.tag = in_tag;
|
||||
thread_ready(cur_th->last_send_th, TRUE); //!< 直接唤醒接受者
|
||||
|
||||
@@ -72,3 +72,4 @@ msg_tag_t thread_ipc_call(msg_tag_t in_tag, obj_handler_t target_th_obj, ipc_tim
|
||||
})
|
||||
|
||||
#define thread_get_src_pid() thread_get_cur_ipc_msg()->user[2]
|
||||
#define thread_set_src_pid(pid) thread_get_cur_ipc_msg()->user[2] = pid
|
||||
|
||||
@@ -10,7 +10,7 @@ typedef unsigned short uhmword_t;
|
||||
typedef umword_t ptr_t;
|
||||
typedef char bool_t;
|
||||
typedef unsigned long obj_addr_t;
|
||||
typedef unsigned long obj_handler_t;
|
||||
typedef long obj_handler_t;
|
||||
typedef umword_t addr_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,5 +33,4 @@ typedef struct ns
|
||||
{
|
||||
rpc_svr_obj_t svr;
|
||||
ns_node_t root_node;
|
||||
obj_handler_t hd; //!< 存储临时用于映射的hd
|
||||
} ns_t;
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "u_rpc.h"
|
||||
#include "u_rpc_svr.h"
|
||||
#include "u_arch.h"
|
||||
#include "u_rpc_buf.h"
|
||||
#include "u_hd_man.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -14,7 +15,7 @@ RPC_GENERATION_OP3(ns_t, NS_PROT, NS_REGISTER_OP, register,
|
||||
{
|
||||
path->data[path->len - 1] = 0;
|
||||
|
||||
int ret = namespace_register((char *)(path->data), obj->hd, type->data);
|
||||
int ret = namespace_register((char *)(path->data), rpc_hd_get(0), type->data);
|
||||
if (ret >= 0)
|
||||
{
|
||||
printf("register [%s] success.\n", (char *)(path->data));
|
||||
@@ -39,7 +40,7 @@ RPC_GENERATION_OP2(ns_t, NS_PROT, NS_QUERY_OP, query,
|
||||
int ret = namespace_query((char *)(path->data), &cli_hd->data);
|
||||
if (ret >= 0)
|
||||
{
|
||||
printf("The request service [%s] was successful.\n", (char *)(path->data));
|
||||
printf("The request service [%s] was successful, hd is %d.\n", (char *)(path->data), cli_hd->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -56,5 +57,4 @@ RPC_DISPATCH2(ns_t, NS_PROT, typeof(NS_REGISTER_OP), NS_REGISTER_OP, register, N
|
||||
void ns_init(ns_t *ns)
|
||||
{
|
||||
rpc_svr_obj_init(&ns->svr, rpc_ns_t_dispatch, NS_PROT);
|
||||
ns->hd = HANDLER_INVALID;
|
||||
}
|
||||
|
||||
@@ -7,3 +7,4 @@ obj_handler_t handler_alloc(void);
|
||||
void handler_free(obj_handler_t hd_inx);
|
||||
void handler_free_umap(obj_handler_t hd_inx);
|
||||
void hanlder_pre_alloc(obj_handler_t inx);
|
||||
bool_t handler_is_used(obj_handler_t hd_inx);
|
||||
|
||||
4
mkrtos_user/lib/sys_util/inc/u_rpc_buf.h
Normal file
4
mkrtos_user/lib/sys_util/inc/u_rpc_buf.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
obj_handler_t rpc_hd_get(int inx);
|
||||
int rpc_hd_alloc(void);
|
||||
@@ -184,7 +184,8 @@ int app_load(const char *name, uenv_t *cur_env, pid_t *pid, char *argv[], int ar
|
||||
uenv->rev2 = HANDLER_INVALID;
|
||||
printf("stack env:%p, env:%p\n", (void *)((umword_t)usp_top + ARG_WORD_NR * 4 + 16 + 16), uenv);
|
||||
|
||||
tag = thread_exec_regs(hd_thread, (umword_t)addr, (umword_t)sp_addr_top - sizeof(void *), ram_base, 1);
|
||||
tag = thread_exec_regs(hd_thread, (umword_t)addr, ((umword_t)((umword_t)sp_addr_top - 8) & ~0x7UL),
|
||||
ram_base, 1);
|
||||
assert(msg_tag_get_prot(tag) >= 0);
|
||||
|
||||
/*启动线程运行*/
|
||||
|
||||
@@ -52,6 +52,26 @@ obj_handler_t handler_alloc(void)
|
||||
|
||||
return HANDLER_INVALID;
|
||||
}
|
||||
bool_t handler_is_used(obj_handler_t hd_inx)
|
||||
{
|
||||
hd_inx -= HANDLER_START_INX;
|
||||
if (hd_inx < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
umword_t word_offset = hd_inx / WORD_BITS;
|
||||
umword_t bits_offset = hd_inx % WORD_BITS;
|
||||
|
||||
if (word_offset >= (HANDLER_MAX_NR / WORD_BITS))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pthread_spin_lock(&lock);
|
||||
bool_t is_use = !!MK_GET_BIT(bitmap_handler_alloc[word_offset], bits_offset);
|
||||
pthread_spin_unlock(&lock);
|
||||
|
||||
return is_use;
|
||||
}
|
||||
void handler_free(obj_handler_t hd_inx)
|
||||
{
|
||||
hd_inx -= HANDLER_START_INX;
|
||||
|
||||
43
mkrtos_user/lib/sys_util/src/u_rpc_buf.c
Normal file
43
mkrtos_user/lib/sys_util/src/u_rpc_buf.c
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "u_hd_man.h"
|
||||
#include "u_ipc.h"
|
||||
#include "u_prot.h"
|
||||
#include "u_task.h"
|
||||
#include "u_thread.h"
|
||||
static obj_handler_t buf_hd = HANDLER_INVALID;
|
||||
obj_handler_t rpc_hd_get(int inx)
|
||||
{
|
||||
/*TODO:*/
|
||||
return buf_hd;
|
||||
}
|
||||
int rpc_hd_alloc(void)
|
||||
{
|
||||
ipc_msg_t *msg;
|
||||
msg_tag_t tag;
|
||||
obj_handler_t hd;
|
||||
bool_t alloc_new = TRUE;
|
||||
|
||||
if (handler_is_used(buf_hd))
|
||||
{
|
||||
if (task_obj_valid(TASK_THIS, buf_hd).prot == 0)
|
||||
{
|
||||
alloc_new = FALSE;
|
||||
}
|
||||
}
|
||||
if (alloc_new)
|
||||
{
|
||||
hd = handler_alloc();
|
||||
if (hd == HANDLER_INVALID)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hd = buf_hd;
|
||||
}
|
||||
thread_msg_buf_get(-1, (umword_t *)(&msg), NULL);
|
||||
msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
|
||||
buf_hd = hd;
|
||||
return 0;
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "u_rpc_svr.h"
|
||||
#include "rpc_prot.h"
|
||||
#include "u_err.h"
|
||||
#include "u_rpc_buf.h"
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
@@ -159,6 +160,7 @@ void rpc_loop(void)
|
||||
msg = (ipc_msg_t *)buf;
|
||||
while (1)
|
||||
{
|
||||
rpc_hd_alloc();
|
||||
tag = thread_ipc_wait(ipc_timeout_create2(0, 0), &obj);
|
||||
if (msg_tag_get_val(tag) < 0)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ int main(int argv, char *args[])
|
||||
fs_svr_init();
|
||||
ns_register("/cpio", hd, MOUNT_NODE);
|
||||
cons_write_str("cpiofs mount success\n");
|
||||
*((char *)0) = 0;
|
||||
// *((char *)0) = 0;
|
||||
|
||||
fs_svr_loop();
|
||||
return 0;
|
||||
|
||||
@@ -71,7 +71,6 @@ int main(int argc, char *args[])
|
||||
|
||||
ret = parse_cfg(DEFAULT_INIT_CFG, env);
|
||||
printf("run app num is %d.\n", ret);
|
||||
namespace_pre_alloc_map_fd();
|
||||
namespace_loop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -417,6 +417,7 @@ void namespace_init(obj_handler_t ipc_hd)
|
||||
fs_init(&ns_fs);
|
||||
meta_reg_svr_obj(&ns.svr, NS_PROT);
|
||||
meta_reg_svr_obj(&ns_fs.svr, FS_PROT);
|
||||
thread_set_src_pid(0);
|
||||
node_init(&ns.root_node, NULL, "", 0, DIR_NODE);
|
||||
ns_hd = ipc_hd;
|
||||
printf("ns svr init...\n");
|
||||
@@ -434,12 +435,10 @@ int namespace_register(const char *path, obj_handler_t hd, int type)
|
||||
if (type == DIR_NODE)
|
||||
{
|
||||
handler_free_umap(hd);
|
||||
namespace_pre_alloc_map_fd();
|
||||
return -ECANCELED;
|
||||
}
|
||||
int ret = ns_reg(path, hd, type); // TODO:增加类型支持
|
||||
printf("register svr, name is %s, hd is %d\n", path, hd);
|
||||
namespace_pre_alloc_map_fd();
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
@@ -474,20 +473,7 @@ int namespace_query(const char *path, obj_handler_t *hd)
|
||||
*hd = node->node_hd;
|
||||
return ret_inx;
|
||||
}
|
||||
int namespace_pre_alloc_map_fd(void)
|
||||
{
|
||||
ipc_msg_t *msg;
|
||||
obj_handler_t hd = handler_alloc();
|
||||
|
||||
if (hd == HANDLER_INVALID)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
thread_msg_buf_get(-1, (umword_t *)(&msg), NULL);
|
||||
msg->map_buf[0] = vpage_create_raw3(0, 0, hd).raw;
|
||||
ns.hd = hd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void namespace_loop(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user