修复objspace数组访问越界的bug

This commit is contained in:
zhangzheng
2023-09-30 14:50:48 +08:00
parent 2fc002f2e1
commit 4827093da7
8 changed files with 30 additions and 7 deletions

View File

@@ -7,7 +7,7 @@
#include "mm_wrap.h"
#define OBJ_MAP_TAB_SIZE 2
#define OBJ_MAP_ENTRY_SIZE 16
#define OBJ_MAP_ENTRY_SIZE 32
#define OBJ_MAP_MAX_ADDR ((OBJ_MAP_ENTRY_SIZE) * (OBJ_MAP_TAB_SIZE))

View File

@@ -29,7 +29,7 @@ void obj_space_release(obj_space_t *obj_space, ram_limit_t *ram)
void obj_space_del(obj_space_t *obj_space, obj_addr_t inx)
{
assert(obj_space);
if (inx > OBJ_MAP_MAX_ADDR)
if (inx >= OBJ_MAP_MAX_ADDR)
{
return;
}
@@ -46,7 +46,7 @@ obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobj
{
assert(obj_space);
assert(kobj);
if (inx > OBJ_MAP_MAX_ADDR)
if (inx >= OBJ_MAP_MAX_ADDR)
{
return NULL;
}
@@ -74,7 +74,7 @@ obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobj
obj_map_entry_t *obj_space_lookup(obj_space_t *obj_space, obj_addr_t inx)
{
assert(obj_space);
if (inx > OBJ_MAP_MAX_ADDR)
if (inx >= OBJ_MAP_MAX_ADDR)
{
return NULL;
}

View File

@@ -61,6 +61,7 @@ static inline syscall_prot_t syscall_prot_create(uint8_t op, uint8_t prot, obj_h
.op = op,
.prot = prot,
.obj_inx = obj_inx,
.self = 0,
};
}
static inline syscall_prot_t syscall_prot_create4(uint8_t op, uint8_t prot, obj_handler_t obj_inx, uint8_t self)

View File

@@ -7,7 +7,7 @@
#include <pthread.h>
#define HANDLER_START_INX 10 //!< fd开始的值前10个内核保留
#define HANDLER_MAX_NR 64 //!< 单个task最大支持的hd数量
#define HANDLER_MAX_NR 64 //!< 单个task最大支持的hd数量
static umword_t bitmap_handler_alloc[HANDLER_MAX_NR / WORD_BYTES];
static pthread_spinlock_t lock;

View File

@@ -34,8 +34,9 @@ int main(int argc, char *args[])
app_test();
mpu_test();
ipc_test();
thread_press_test();
#endif
// thread_press_test();
kobj_create_press_test();
uenv_t env = *u_get_global_env();
obj_handler_t ipc_hd;
int ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);

View File

@@ -0,0 +1,20 @@
#include "u_log.h"
#include "u_prot.h"
#include "u_mm.h"
#include "u_factory.h"
#include "u_thread.h"
#include "u_task.h"
#include "u_ipc.h"
#include "u_hd_man.h"
#include <assert.h>
#include <stdio.h>
#include "test.h"
void kobj_create_press_test(void)
{
while (1)
{
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, handler_alloc()));
assert(msg_tag_get_prot(tag) >= 0);
}
}

View File

@@ -14,4 +14,5 @@ void map_test(void);
void ipc_timeout_test(void);
void irq_test(void);
void thread_press_test(void);
void kobj_create_press_test(void);
void sleep_tick(int tick);

View File

@@ -20,7 +20,7 @@ set(CMAKE_SIZE "${CROSS_COMPILE}size" CACHE PATH "" FORCE)
# -mfloat-abi=soft -u _printf_float
set(CMAKE_C_FLAGS "-mcpu=cortex-m3 -mthumb -Os -g -lc -lrdimon -mfloat-abi=soft \
set(CMAKE_C_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g -lc -lrdimon -mfloat-abi=soft \
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
--gc-sections -fno-stack-protector \