修复服务端并发错误&内核内存分配错误问题

This commit is contained in:
zhangzheng
2024-01-05 23:08:42 +08:00
parent 1e8d407664
commit a2723c39c8
19 changed files with 197 additions and 101 deletions

View File

@@ -276,7 +276,8 @@
"u_sig.h": "c",
"u_err.h": "c",
"core_cmfunc.h": "c",
"stm32f4xx.h": "c"
"stm32f4xx.h": "c",
"malloc.h": "c"
},
"cortex-debug.showRTOS": false,
"cortex-debug.variableUseNaturalFormat": false,

View File

@@ -9,12 +9,14 @@
#pragma once
#include "printk.h"
#include "mm_wrap.h"
#define assert(cond) \
do \
{ \
if (!(cond)) \
{ \
printk("%s:%d %s", __FILE__, __LINE__, #cond); \
mm_trace(); \
while (1) \
; \
} \

View File

@@ -191,7 +191,7 @@ static void ipc_release_stage2(kobject_t *kobj)
ipc_t *ipc = container_of(kobj, ipc_t, kobj);
mm_limit_free(ipc->lim, kobj);
printk("ipc release 0x%x\n", kobj);
// printk("ipc release 0x%x\n", kobj);
}
static bool_t ipc_put(kobject_t *kobj)
{

View File

@@ -24,29 +24,48 @@ void mem_init(mem_t *_this)
static void mem_merge(mem_t *_this, struct mem_heap *mem)
{
struct mem_heap *prev_mem;
struct mem_heap *t_mem;
struct mem_heap *next_mem;
struct mem_heap *t_mem = mem;
_this->l_heap = mem;
prev_mem = mem->prev;
for (t_mem = mem; t_mem != _this->heap_end; t_mem = t_mem->next)
if (mem->used != 0)
{
if (prev_mem && prev_mem->used == 0)
{
// 如果当前没有使用,并且上一个的下一个位置等于当前,则上一个和当前合并
if (t_mem->used == 0 && ((ptr_t)prev_mem + prev_mem->size + MEM_HEAP_STRUCT_SIZE) == (ptr_t)t_mem)
{
// 上一个和当前合并
prev_mem->size += t_mem->size + MEM_HEAP_STRUCT_SIZE;
prev_mem->next = t_mem->next;
t_mem->next->prev = prev_mem;
return;
}
_this->l_heap = prev_mem;
}
prev_mem = t_mem->prev;
while (prev_mem && prev_mem->used == 0)
{
prev_mem->size += t_mem->size + MEM_HEAP_STRUCT_SIZE;
prev_mem->next = t_mem->next;
t_mem->next->prev = prev_mem;
t_mem = prev_mem;
prev_mem = t_mem->prev;
}
// if (t_mem < _this->l_heap || _this->l_heap->used == 1)
// {
// _this->l_heap = t_mem;
// }
while (t_mem && t_mem != _this->heap_end && t_mem->used == 0)
{
next_mem = t_mem->next;
if (next_mem == _this->heap_end)
{
break;
}
if (next_mem->used == 0)
{
t_mem->size += next_mem->size + MEM_HEAP_STRUCT_SIZE;
t_mem->next = next_mem->next;
next_mem->next->prev = t_mem;
}
else
{
prev_mem = t_mem;
break;
}
t_mem = t_mem->next;
}
}
/**
@@ -104,6 +123,7 @@ void *mem_split(mem_t *_this, void *mem, uint32_t size)
r_mem->next = t_mem->next;
r_mem->prev = t_mem;
r_mem->magic = MAGIC_NUM;
t_mem->next->prev = r_mem;
t_mem->next = r_mem;
t_mem->used = 1;
t_mem->size = size - MEM_HEAP_STRUCT_SIZE;
@@ -207,7 +227,7 @@ void *mem_alloc(mem_t *_this, uint32_t size)
for (mem = _this->l_heap; mem != _this->heap_end; mem = mem->next)
{
assert(mem->magic == MAGIC_NUM);
if (mem->used == 0 && mem->size > size)
if (mem->used == 0 && mem->size >= size)
{
if (mem->size - size > MEM_HEAP_STRUCT_SIZE)
{
@@ -218,10 +238,11 @@ void *mem_alloc(mem_t *_this, uint32_t size)
mem_temp->used = 0;
mem_temp->magic = MAGIC_NUM;
mem_temp->size = mem->size - size - MEM_HEAP_STRUCT_SIZE;
_this->l_heap = mem_temp;
// _this->l_heap = mem_temp;
mem->size = size;
mem->used = 1;
mem->next->prev = mem_temp;
mem->next = mem_temp;
spinlock_set(&_this->lock, status);
@@ -250,6 +271,8 @@ int mem_heap_add(mem_t *_this, void *mem, uint32_t size)
mem = (void *)(ALIGN((ptr_t)mem, 4));
size -= 4;
printk("total mem size:%d.\n", size);
// ((struct mem_heap *)mem)->name[0] = ' ';
// ((struct mem_heap *)mem)->name[1] = ' ';
// ((struct mem_heap *)mem)->name[2] = ' ';
@@ -350,7 +373,7 @@ struct mem_heap *mem_get_free(mem_t *_this, struct mem_heap *next,
void mem_trace(mem_t *_this)
{
struct mem_heap *mem;
size_t total = 0;
printk("================");
printk("start heap:0x%x.\n", _this->heap_start);
printk("l heap:0x%x.\n", _this->l_heap);
@@ -359,6 +382,8 @@ void mem_trace(mem_t *_this)
for (mem = _this->heap_start; mem != _this->heap_end; mem = mem->next)
{
printk("%d [0x%x-] %dB\n", mem->used, mem, mem->size);
total += mem->size + MEM_HEAP_STRUCT_SIZE;
}
printk("mem total size:%d.\n", total);
printk("================");
}

View File

@@ -16,7 +16,7 @@
void mm_space_init(mm_space_t *mm_space, int is_knl)
{
region_info_t *regi_info;
// region_info_t *regi_info;
for (int i = 0; i < CONFIG_REGION_NUM; i++)
{
@@ -24,8 +24,8 @@ void mm_space_init(mm_space_t *mm_space, int is_knl)
}
if (!is_knl)
{
regi_info = mm_space_alloc_pt_region(mm_space);
assert(regi_info);
// regi_info = mm_space_alloc_pt_region(mm_space);
// assert(regi_info);
// mm_pages_init(&mm_space->mm_pages, regi_info);
}
}

View File

@@ -132,8 +132,11 @@ static void thread_release_stage1(kobject_t *kobj)
assert(pos->th->status == THREAD_SUSPEND);
thread_wait_entry_t *next = slist_next_entry(pos, &wait_send_queue, node_timeout);
pos->th->ipc_status = THREAD_IPC_ABORT;
thread_ready(pos->th, TRUE);
if (pos->th != th)
{
pos->th->ipc_status = THREAD_IPC_ABORT;
thread_ready(pos->th, TRUE);
}
slist_del(&pos->node_timeout);
if (slist_in_list(&pos->node))
@@ -149,9 +152,11 @@ static void thread_release_stage1(kobject_t *kobj)
assert(pos2->th->status == THREAD_SUSPEND);
thread_wait_entry_t *next = slist_next_entry(pos2, &wait_recv_queue, node);
pos2->th->ipc_status = THREAD_IPC_ABORT;
thread_ready(pos2->th, TRUE);
if (pos2->th != th)
{
pos2->th->ipc_status = THREAD_IPC_ABORT;
thread_ready(pos2->th, TRUE);
}
slist_del(&pos2->node);
pos2 = next;
}
@@ -162,7 +167,7 @@ static void thread_release_stage2(kobject_t *kobj)
{
thread_t *th = container_of(kobj, thread_t, kobj);
thread_t *cur_th = thread_get_current();
printk("release thread 0x%x\n", kobj);
// printk("release thread 0x%x\n", kobj);
mm_limit_free_align(th->lim, kobj, THREAD_BLOCK_SIZE);
if (cur_th == th)
@@ -170,6 +175,7 @@ static void thread_release_stage2(kobject_t *kobj)
scheduler_reset();
thread_sched();
}
// mm_trace();
}
/**
@@ -297,7 +303,6 @@ void thread_todead(thread_t *th, bool_t is_sche)
thread_sched();
}
}
/**
* @brief 创建线程
*
@@ -314,7 +319,7 @@ thread_t *thread_create(ram_limit_t *ram)
}
memset(th, 0, THREAD_BLOCK_SIZE);
thread_init(th, ram);
printk("create thread 0x%x\n", th);
// printk("create thread 0x%x\n", th);
return th;
}
@@ -368,6 +373,22 @@ void thread_timeout_check(ssize_t tick)
pos2 = next;
}
}
static void thread_timeout_del_recv(thread_t *th)
{
thread_wait_entry_t *pos2;
slist_foreach_not_next(pos2, &wait_recv_queue, node)
{
thread_wait_entry_t *next = slist_next_entry(pos2, &wait_recv_queue, node);
if (pos2->th == th)
{
slist_del(&pos2->node);
break;
}
pos2 = next;
}
}
/**
* @brief ipc传输时的数据拷贝
*
@@ -440,6 +461,16 @@ static int thread_ipc_recv(msg_tag_t *ret_msg, ipc_timeout_t timeout,
lock_status = cpulock_lock();
cur_th->ipc_status = THREAD_RECV; //!< 因为接收挂起
if (ipc_kobj)
{
/*IPC对象的引用计数+1*/
ref_counter_inc(&ipc_kobj->ref);
cur_th->ipc_kobj = &ipc_kobj->kobj;
}
else
{
cur_th->ipc_kobj = NULL;
}
if (!slist_is_empty(&cur_th->wait_send_head))
{
//!< 有发送者
@@ -462,18 +493,6 @@ static int thread_ipc_recv(msg_tag_t *ret_msg, ipc_timeout_t timeout,
slist_add_append(&wait_recv_queue, &wait.node); //!< 放到等待队列中
}
}
if (ipc_kobj)
{
/*IPC对象的引用计数+1*/
ref_counter_inc(&ipc_kobj->ref);
cur_th->ipc_kobj = &ipc_kobj->kobj;
}
else
{
cur_th->ipc_kobj = NULL;
}
thread_suspend(cur_th); //!< 挂起
preemption(); //!< 进行调度
if (cur_th->ipc_status == THREAD_IPC_ABORT)
@@ -548,7 +567,10 @@ static int thread_ipc_reply(msg_tag_t in_tag)
int thread_ipc_call(thread_t *to_th, msg_tag_t in_tag, msg_tag_t *ret_tag,
ipc_timeout_t timout, umword_t *ret_user_id, bool_t is_call)
{
assert(is_call && ret_tag);
if (is_call)
{
assert(is_call && ret_tag);
}
int ret = -EINVAL;
thread_t *cur_th = thread_get_current();
thread_t *recv_kobj = to_th;
@@ -587,6 +609,7 @@ again_check:
}
else if (recv_kobj->status == THREAD_SUSPEND && recv_kobj->ipc_status == THREAD_RECV)
{
thread_timeout_del_recv(recv_kobj);
//!< 开始发送数据
ret = ipc_data_copy(recv_kobj, cur_th, in_tag); //!< 拷贝数据
if (ret < 0)
@@ -594,23 +617,24 @@ again_check:
//!< 拷贝失败
goto end;
}
if (recv_kobj->ipc_kobj)
{
// 绑定回复的ipc到当前的线程
assert(ipc_bind(((ipc_t *)(recv_kobj->ipc_kobj)), -1, 0, cur_th) >= 0);
ref_counter_dec_and_release(&((ipc_t *)(recv_kobj->ipc_kobj))->ref,
recv_kobj->ipc_kobj);
recv_kobj->ipc_kobj = NULL;
recv_kobj->last_send_th = NULL;
}
else
{
recv_kobj->last_send_th = cur_th; //!< 设置接收者的上一次发送者是谁
ref_counter_inc(&cur_th->ref); //!< 作为发送者增加一次引用
}
thread_ready(recv_kobj, TRUE); //!< 直接唤醒接受者
if (is_call)
{
if (recv_kobj->ipc_kobj)
{
// 绑定回复的ipc到当前的线程
assert(ipc_bind(((ipc_t *)(recv_kobj->ipc_kobj)), -1, 0, cur_th) >= 0);
ref_counter_dec_and_release(&((ipc_t *)(recv_kobj->ipc_kobj))->ref,
recv_kobj->ipc_kobj);
recv_kobj->ipc_kobj = NULL;
recv_kobj->last_send_th = NULL;
}
else
{
recv_kobj->last_send_th = cur_th; //!< 设置接收者的上一次发送者是谁
ref_counter_inc(&cur_th->ref); //!< 作为发送者增加一次引用
}
ret = thread_ipc_recv(ret_tag, timout, ret_user_id, NULL); //!< 当前线程进行接收
if (ret < 0)
{
@@ -672,7 +696,7 @@ msg_tag_t thread_do_ipc(kobject_t *kobj, entry_frame_t *f, umword_t user_id)
{
msg_tag_t ret_msg;
ipc_timeout_t ipc_tm_out = ipc_timeout_create(f->r[3]);
kobject_t *ipc_kobj = obj_space_lookup_kobj_cmp_type(&cur_task->obj_space, f->r[4], IPC_PROT);
kobject_t *ipc_kobj = obj_space_lookup_kobj_cmp_type(&cur_task->obj_space, f->r[4], IPC_TYPE);
int ret = thread_ipc_recv(&ret_msg, ipc_tm_out, &f->r[1], (ipc_t *)ipc_kobj);
if (ret < 0)
@@ -685,7 +709,7 @@ msg_tag_t thread_do_ipc(kobject_t *kobj, entry_frame_t *f, umword_t user_id)
{
msg_tag_t in_tag = msg_tag_init(f->r[0]);
msg_tag_t recv_tag;
th_hd = f->r[2];
// th_hd = f->r[2];
ipc_timeout_t ipc_tm_out = ipc_timeout_create(f->r[3]);
to_th->user_id = user_id;
@@ -787,7 +811,7 @@ static void thread_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_t
}
thread_bind(tag_th, task_kobj);
tag = msg_tag_init4(0, 0, 0, 0);
printk("thread bind to %d\n", f->r[1]);
// printk("thread bind to %d\n", f->r[1]);
}
break;
case YIELD:

View File

@@ -56,5 +56,5 @@ void thread_user_pf_set(thread_t *cur_th, void *pc, void *user_sp, void *ram, um
cur_th->sp.user_sp = cur_pf;
cur_th->sp.sp_type = 0xfffffffd;
printk("exc_regs:%x %x %x\n", cur_pf->pf_s.pc, cur_th->sp.user_sp, ram);
// printk("exc_regs:%x %x %x\n", cur_pf->pf_s.pc, cur_th->sp.user_sp, ram);
}

View File

@@ -36,3 +36,4 @@ int meta_reg_svr_obj(rpc_svr_obj_t *svr_obj, umword_t prot);
int meta_reg_svr_obj_raw(meta_t *meta, rpc_svr_obj_t *svr_obj, umword_t prot);
int rpc_creaite_bind_ipc(obj_handler_t th, void *obj, obj_handler_t *ipc_hd);
void rpc_loop(void);
int rpc_mtd_loop(void);

View File

@@ -34,7 +34,7 @@ int u_intr_bind(int irq_no, u_irq_prio_t prio, int th_prio,
return msg_tag_get_val(tag);
}
ret = u_thread_create(&th_hd, stack, stack_size, msg_buf, thread_func);
ret = u_thread_create(&th_hd, (char *)stack + stack_size, msg_buf, thread_func);
if (ret < 0)
{

View File

@@ -182,10 +182,12 @@ void rpc_loop(void)
thread_ipc_reply(tag, ipc_timeout_create2(0, 0));
}
}
#define RPC_MTD_TH_STACK_SIZE 1024
#define RPC_MTD_TH_STACK_SIZE (1024+256)
typedef struct mtd_params
{
rpc_svr_obj_t *obj;
void *stack;
int is_del;
msg_tag_t in_tag;
obj_handler_t ipc_obj;
obj_handler_t th_obj;
@@ -200,32 +202,39 @@ static void rpc_mtc_thread(void *arg)
ipc_msg_t *msg;
mtd_params_t *params = (mtd_params_t *)arg;
thread_msg_buf_get(-1, (umword_t *)(&msg), NULL);
svr_obj = (rpc_svr_obj_t *)params->obj;
if (svr_obj->dispatch)
{
tag = svr_obj->dispatch(svr_obj, params->in_tag, msg);
}
thread_ipc_send(tag, params->ipc_obj, ipc_timeout_create2(0, 0));
handler_free_umap(params->ipc_obj);
params->ipc_obj = HANDLER_INVALID;
u_thread_del(params->th_obj);
params->is_del = 1;
while (1)
;
{
u_sleep_ms(1000);
}
}
static void check_release_stack_mem(void)
{
mtd_params_t *pos;
pthread_spin_lock(&lock);
slist_foreach_not_next(pos, &th_head, node)
{
mtd_params_t *next = slist_next_entry(pos, &th_head, node);
slist_del(&pos->node);
void *stack = (void *)((char *)pos - (RPC_MTD_TH_STACK_SIZE + MSG_BUG_LEN));
free(stack);
if (pos->is_del == 1)
{
slist_del(&pos->node);
// void *stack = (void *)((char *)pos - (RPC_MTD_TH_STACK_SIZE + MSG_BUG_LEN));
handler_del_umap(pos->ipc_obj);
u_thread_del(pos->th_obj);
free(pos->stack);
}
pos = next;
}
pthread_spin_unlock(&lock);
}
extern void __pthread_new_thread_entry__(void);
int rpc_mtd_loop(void)
@@ -234,7 +243,9 @@ int rpc_mtd_loop(void)
msg_tag_t tag;
umword_t buf;
obj_handler_t ipc_hd;
uint8_t *main_msg_buf;
thread_msg_buf_get(-1, (umword_t *)(&main_msg_buf), NULL);
slist_init(&th_head);
while (1)
{
@@ -243,38 +254,43 @@ int rpc_mtd_loop(void)
ipc_hd = handler_alloc();
if (ipc_hd == HANDLER_INVALID)
{
cons_write_str("mtd alloc is fial.\n");
u_sleep_ms(1000);
// cons_write_str("mtd alloc is fial.\n");
// u_sleep_ms(1000);
continue;
}
tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, ipc_hd));
if (msg_tag_get_val(tag) < 0)
{
cons_write_str("mtd factory ipc fail.\n");
// cons_write_str("mtd factory ipc fail.\n");
handler_free(ipc_hd);
u_sleep_ms(1000);
// u_sleep_ms(1000);
continue;
}
tag = thread_ipc_wait(ipc_timeout_create2(0, 0), &obj, ipc_hd);
if (msg_tag_get_val(tag) < 0)
{
handler_free_umap(ipc_hd);
continue;
}
again_create:;
obj_handler_t th_obj;
void *stack = malloc(RPC_MTD_TH_STACK_SIZE + MSG_BUG_LEN + sizeof(mtd_params_t));
void *stack;
stack = memalign(sizeof(void *) * 2,
RPC_MTD_TH_STACK_SIZE + MSG_BUG_LEN + sizeof(mtd_params_t));
if (!stack)
{
cons_write_str("mtd no stack mem.\n");
// cons_write_str("mtd no stack mem.\n");
check_release_stack_mem();
u_sleep_ms(1000);
// u_sleep_ms(1000);
goto again_create;
}
int ret_val;
uint8_t *msg_buf = (uint8_t *)stack + RPC_MTD_TH_STACK_SIZE;
umword_t *stack_tmp = (umword_t *)stack;
int ret_val;
umword_t *stack_tmp = (umword_t *)((uint8_t *)stack + RPC_MTD_TH_STACK_SIZE);
mtd_params_t *params = (mtd_params_t *)((char *)stack + RPC_MTD_TH_STACK_SIZE + MSG_BUG_LEN);
// 设置调用参数等
@@ -282,26 +298,35 @@ int rpc_mtd_loop(void)
*(--stack_tmp) = (umword_t)0; // 保留
*(--stack_tmp) = (umword_t)rpc_mtc_thread;
//
params->in_tag = tag;
params->ipc_obj = ipc_hd;
params->obj = (rpc_svr_obj_t *)obj;
params->stack = stack;
params->is_del = 0;
slist_init(&params->node);
pthread_spin_lock(&lock);
slist_add(&th_head, &params->node);
pthread_spin_unlock(&lock);
again_th_create:
ret_val = u_thread_create(&params->th_obj,
stack,
RPC_MTD_TH_STACK_SIZE,
(char *)stack_tmp,
(char *)stack + RPC_MTD_TH_STACK_SIZE,
(void (*)(void))__pthread_new_thread_entry__);
if (ret_val < 0)
{
cons_write_str("mtd no mem.\n");
// cons_write_str("mtd no mem.\n");
check_release_stack_mem();
u_sleep_ms(1000);
// u_sleep_ms(1000);
goto again_th_create;
}
memcpy(msg_buf, main_msg_buf, MSG_BUG_LEN - IPC_USER_SIZE);
ipc_msg_t *msg = (ipc_msg_t *)msg_buf;
msg->user[2] = thread_get_src_pid();
u_thread_run(params->th_obj, 2);
// thread_ipc_reply(tag, ipc_timeout_create2(0, 0));
}

View File

@@ -71,7 +71,7 @@ void sig_init(void)
{
return;
}
u_thread_create(&sig_th, sig_stack, sizeof(sig_stack), sig_msg_buf, sig_func);
u_thread_create(&sig_th, (char *)sig_stack + sizeof(sig_stack), sig_msg_buf, sig_func);
u_thread_run(sig_th, CONFIG_SIG_THREAD_PRIO);
}
#endif

View File

@@ -2,5 +2,5 @@
#include <u_types.h>
void u_thread_del(obj_handler_t th_hd);
int u_thread_create(obj_handler_t *th_hd, void *stack, umword_t stack_size, void *msg_buf, void (*thread_func)(void));
int u_thread_create(obj_handler_t *th_hd, void *stack, void *msg_buf, void (*thread_func)(void));
void u_thread_run(obj_handler_t th_hd, int prio);

View File

@@ -9,9 +9,9 @@
#include <u_thread_util.h>
void u_thread_del(obj_handler_t th_hd)
{
handler_free_umap(th_hd);
handler_del_umap(th_hd);
}
int u_thread_create(obj_handler_t *th_hd, void *stack, umword_t stack_size, void *msg_buf, void (*thread_func)(void))
int u_thread_create(obj_handler_t *th_hd, void *stack, void *msg_buf, void (*thread_func)(void))
{
assert(th_hd);
msg_tag_t tag;
@@ -30,7 +30,7 @@ int u_thread_create(obj_handler_t *th_hd, void *stack, umword_t stack_size, void
return msg_tag_get_prot(tag);
}
tag = thread_exec_regs(th1_hd, (umword_t)thread_func, (umword_t)stack + stack_size - sizeof(void *), RAM_BASE(), 0);
tag = thread_exec_regs(th1_hd, (umword_t)thread_func, (umword_t)stack, RAM_BASE(), 0);
if (msg_tag_get_prot(tag) < 0)
{
handler_free_umap(th1_hd);

View File

@@ -386,7 +386,7 @@ void rt_timer_init(rt_timer_t timer,
assert(timeout);
if (timer_hd == HANDLER_INVALID)
{
int ret = u_thread_create(&timer_hd, timer_stack, STACK_SIZE, timer_thmsg_buf, timer_func);
int ret = u_thread_create(&timer_hd, (char *)timer_stack + STACK_SIZE, timer_thmsg_buf, timer_func);
if (ret < 0)
{

View File

@@ -15,7 +15,6 @@ int main(int argv, char *args[])
{
obj_handler_t hd;
int ret;
printf("args[0]:%s\n", args[0]);
ret = rpc_meta_init(THREAD_MAIN, &hd);

View File

@@ -48,7 +48,7 @@ void console_init(void)
{
cons_svr_obj_init(&cons_obj);
meta_reg_svr_obj(&cons_obj.svr, CONS_PROT);
u_thread_create(&cons_th, cons_stack, sizeof(cons_stack), NULL, console_read_func);
u_thread_create(&cons_th, (char *)cons_stack + sizeof(cons_stack), NULL, console_read_func);
u_thread_run(cons_th, 3);
printf("cons svr init...\n");
}

View File

@@ -1,15 +1,15 @@
/**
* @file heap_stack.c
* @author ATShining (1358745329@qq.com)
* @brief
* @brief
* @version 0.1
* @date 2023-11-28
*
*
* @copyright Copyright (c) 2023
*
*
*/
#define HEAP_SIZE 1024
#define STACK_SIZE 1024 * 2
#define HEAP_SIZE ((1024 + 256) * 3 + 1024)
#define STACK_SIZE (1024 + 256)
#if defined(__CC_ARM)
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))

View File

@@ -1,5 +1,5 @@
#一次读取一行,每行代表启动的应用程序,暂时不支持参数
fatfs
# fatfs
cpiofs
sh

View File

@@ -22,15 +22,25 @@
#include "namespace.h"
#include "u_rpc_svr.h"
#include "file_desc.h"
#include <pthread.h>
#include <malloc.h>
#include <fcntl.h>
#include <sys/types.h>
static ns_t ns;
static fs_t ns_fs;
static pthread_spinlock_t lock;
int ns_reg(const char *path, obj_handler_t hd, enum node_type type);
int ns_node_free(ns_node_t *node);
static int find_path(const char *name);
static void ns_lock(void)
{
pthread_spin_lock(&lock);
}
static void ns_unlock(void)
{
pthread_spin_unlock(&lock);
}
/**
* @brief 查找每一个节点,并进行删除
*
@@ -76,7 +86,9 @@ static void _ns_node_del_by_pid(slist_head_t *head, pid_t pid, int to_del)
*/
void ns_node_del_by_pid(pid_t pid, int to_del)
{
ns_lock();
_ns_node_del_by_pid(&ns.root_node.sub_dir, pid, to_del);
ns_unlock();
}
/**
* @brief 初始化一个节点
@@ -557,7 +569,9 @@ int namespace_register(const char *path, obj_handler_t hd, int type)
handler_free_umap(hd);
return -ECANCELED;
}
ns_lock();
int ret = ns_reg(path, hd, type);
ns_unlock();
printf("register svr, name is %s, hd is %d\n", path, hd);
return ret;
}
@@ -580,27 +594,32 @@ int namespace_query(const char *path, obj_handler_t *hd)
*hd = ns_hd;
return 0;
}
ns_lock();
node = node_lookup(&ns.root_node, path, &ret_inx);
if (!node)
{
ns_unlock();
return -EEXIST;
}
if (node && ret_inx == strlen(path))
{
ns_unlock();
return -EEXIST;
}
if (node->type == DIR_NODE)
{
ns_unlock();
return -ENOENT;
}
*hd = node->node_hd;
ns_unlock();
return ret_inx;
}
void namespace_loop(void)
{
rpc_loop();
// rpc_mtd_loop();
}
int fs_svr_read(int fd, void *buf, size_t len)