内核对象支持权限
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -124,7 +124,8 @@
|
|||||||
"ipc.h": "c",
|
"ipc.h": "c",
|
||||||
"err.h": "c",
|
"err.h": "c",
|
||||||
"diskio.h": "c",
|
"diskio.h": "c",
|
||||||
"ff.h": "c"
|
"ff.h": "c",
|
||||||
|
"u_hd_man.h": "c"
|
||||||
},
|
},
|
||||||
"cortex-debug.showRTOS": false,
|
"cortex-debug.showRTOS": false,
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,10 @@ static inline void kobj_del_list_init(kobj_del_list_t *list)
|
|||||||
}
|
}
|
||||||
static inline void kobj_del_list_add(kobj_del_list_t *list, slist_head_t *node)
|
static inline void kobj_del_list_add(kobj_del_list_t *list, slist_head_t *node)
|
||||||
{
|
{
|
||||||
slist_add(&list->head, node);
|
if (!slist_in_list(node))
|
||||||
|
{
|
||||||
|
slist_add(&list->head, node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static inline void kobj_del_list_clr(kobj_del_list_t *list)
|
static inline void kobj_del_list_clr(kobj_del_list_t *list)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include "kobject.h"
|
#include "kobject.h"
|
||||||
#include "obj_space.h"
|
#include "obj_space.h"
|
||||||
bool_t obj_map_root(kobject_t *kobj, obj_space_t *obj_space, ram_limit_t *ram, obj_addr_t addr);
|
|
||||||
|
bool_t obj_map_root(kobject_t *kobj, obj_space_t *obj_space, ram_limit_t *ram, vpage_t page);
|
||||||
int obj_map_src_dst(obj_space_t *dst_space, obj_space_t *src_space,
|
int obj_map_src_dst(obj_space_t *dst_space, obj_space_t *src_space,
|
||||||
obj_handler_t dst_inx, obj_handler_t src_inx,
|
obj_handler_t dst_inx, obj_handler_t src_inx,
|
||||||
ram_limit_t *ram);
|
ram_limit_t *ram, uint8_t del_attrs);
|
||||||
int obj_map(obj_space_t *obj_space, obj_handler_t inx, kobject_t *kobj, ram_limit_t *ram);
|
int obj_map(obj_space_t *obj_space, obj_handler_t inx, kobject_t *insert_kobj, ram_limit_t *ram, uint8_t attrs);
|
||||||
void obj_unmap(obj_space_t *obj_space, obj_handler_t inx, kobj_del_list_t *del_list);
|
void obj_unmap(obj_space_t *obj_space, vpage_t vpage, kobj_del_list_t *del_list);
|
||||||
void obj_unmap_all(obj_space_t *obj_space, kobj_del_list_t *del_list);
|
void obj_unmap_all(obj_space_t *obj_space, kobj_del_list_t *del_list);
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
#define OBJ_MAP_MAX_ADDR ((OBJ_MAP_ENTRY_SIZE) * (OBJ_MAP_TAB_SIZE))
|
#define OBJ_MAP_MAX_ADDR ((OBJ_MAP_ENTRY_SIZE) * (OBJ_MAP_TAB_SIZE))
|
||||||
|
|
||||||
|
enum obj_attrs
|
||||||
|
{
|
||||||
|
KOBJ_DELETE_RIGHT = 1,
|
||||||
|
KOBJ_ALL_RIGHTS = 3,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct obj_map_entry
|
typedef struct obj_map_entry
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
@@ -26,11 +32,20 @@ typedef struct obj_map_entry
|
|||||||
} obj_map_entry_t;
|
} obj_map_entry_t;
|
||||||
|
|
||||||
#define obj_map_kobj_get(kobj) ((kobject_t *)((((umword_t)(kobj)) >> 2) << 2))
|
#define obj_map_kobj_get(kobj) ((kobject_t *)((((umword_t)(kobj)) >> 2) << 2))
|
||||||
|
#define obj_map_entry_kobj_get(entry) ((kobject_t *)((((umword_t)((entry)->obj)) >> 2) << 2))
|
||||||
|
|
||||||
static inline void obj_map_entry_init(obj_map_entry_t *entry, kobject_t *obj)
|
static inline void obj_map_entry_init(obj_map_entry_t *entry, kobject_t *obj)
|
||||||
{
|
{
|
||||||
slist_init(&entry->node);
|
slist_init(&entry->node);
|
||||||
entry->obj = obj;
|
entry->obj = (void *)((umword_t)obj & (~3UL));
|
||||||
|
}
|
||||||
|
static inline void obj_map_entry_set_attr(obj_map_entry_t *entry, uint8_t attrs)
|
||||||
|
{
|
||||||
|
entry->flags |= attrs & 0x3UL;
|
||||||
|
}
|
||||||
|
static inline uint8_t obj_map_entry_get_attr(obj_map_entry_t *entry)
|
||||||
|
{
|
||||||
|
return entry->flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct obj_map_item
|
typedef struct obj_map_item
|
||||||
@@ -49,6 +64,6 @@ typedef struct obj_space
|
|||||||
} obj_space_t;
|
} obj_space_t;
|
||||||
void obj_space_init(obj_space_t *obj_space, ram_limit_t *ram);
|
void obj_space_init(obj_space_t *obj_space, ram_limit_t *ram);
|
||||||
void obj_space_del(obj_space_t *obj_space, obj_addr_t inx);
|
void obj_space_del(obj_space_t *obj_space, obj_addr_t inx);
|
||||||
obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobject_t *kobj, obj_addr_t inx);
|
obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobject_t *kobj, obj_addr_t inx, uint8_t attrs);
|
||||||
obj_map_entry_t *obj_space_lookup(obj_space_t *obj_space, obj_addr_t inx);
|
obj_map_entry_t *obj_space_lookup(obj_space_t *obj_space, obj_addr_t inx);
|
||||||
kobject_t *obj_space_lookup_kobj(obj_space_t *obj_space, obj_addr_t inx);
|
kobject_t *obj_space_lookup_kobj(obj_space_t *obj_space, obj_addr_t inx);
|
||||||
@@ -67,3 +67,31 @@ static inline syscall_prot_t syscall_prot_create(uint8_t op, uint8_t prot, obj_h
|
|||||||
.obj_inx = obj_inx,
|
.obj_inx = obj_inx,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef union vpage
|
||||||
|
{
|
||||||
|
umword_t raw;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
umword_t attrs : 4; //!< 权限
|
||||||
|
umword_t : 8; //!< 保留
|
||||||
|
umword_t addr : (WORD_BITS - 12); //!< 地址
|
||||||
|
};
|
||||||
|
} vpage_t;
|
||||||
|
|
||||||
|
static inline vpage_t vpage_create_raw(umword_t raw)
|
||||||
|
{
|
||||||
|
return (vpage_t){.raw = raw};
|
||||||
|
}
|
||||||
|
static inline vpage_t vpage_create3(umword_t attrs, umword_t resv, umword_t addr)
|
||||||
|
{
|
||||||
|
return (vpage_t){.attrs = attrs, .addr = addr};
|
||||||
|
}
|
||||||
|
static inline obj_handler_t vpage_get_obj_handler(vpage_t vpage)
|
||||||
|
{
|
||||||
|
return vpage.addr;
|
||||||
|
}
|
||||||
|
static inline uint8_t vpage_get_attrs(vpage_t vpage)
|
||||||
|
{
|
||||||
|
return vpage.attrs;
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,13 +51,16 @@ static kobject_t *factory_manu_kobj(kobject_t *kobj, ram_limit_t *lim, entry_fra
|
|||||||
}
|
}
|
||||||
static msg_tag_t factory_create_map(kobject_t *kobj, task_t *tk, entry_frame_t *f)
|
static msg_tag_t factory_create_map(kobject_t *kobj, task_t *tk, entry_frame_t *f)
|
||||||
{
|
{
|
||||||
|
vpage_t page = vpage_create_raw(f->r[2]);
|
||||||
kobject_t *new_kobj = factory_manu_kobj(kobj, tk->lim, f);
|
kobject_t *new_kobj = factory_manu_kobj(kobj, tk->lim, f);
|
||||||
|
|
||||||
if (!new_kobj)
|
if (!new_kobj)
|
||||||
{
|
{
|
||||||
return msg_tag_init4(0, 0, 0, -ENOMEM);
|
return msg_tag_init4(0, 0, 0, -ENOMEM);
|
||||||
}
|
}
|
||||||
if (obj_map_root(new_kobj, &tk->obj_space, tk->lim, f->r[2]) == FALSE)
|
|
||||||
|
page.attrs |= KOBJ_ALL_RIGHTS;
|
||||||
|
if (obj_map_root(new_kobj, &tk->obj_space, tk->lim, page) == FALSE)
|
||||||
{
|
{
|
||||||
mm_limit_free(tk->lim, new_kobj);
|
mm_limit_free(tk->lim, new_kobj);
|
||||||
return msg_tag_init4(0, 0, 0, -ENOMEM);
|
return msg_tag_init4(0, 0, 0, -ENOMEM);
|
||||||
|
|||||||
@@ -136,8 +136,14 @@ static int ipc_data_copy(thread_t *dst_th, thread_t *src_th, msg_tag_t tag)
|
|||||||
task_t *dst_tk = thread_get_bind_task(dst_th);
|
task_t *dst_tk = thread_get_bind_task(dst_th);
|
||||||
for (int i = 0; i < map_len; i++)
|
for (int i = 0; i < map_len; i++)
|
||||||
{
|
{
|
||||||
|
vpage_t dst_page = vpage_create_raw(dst_ipc->map_buf[i]);
|
||||||
|
vpage_t src_page = vpage_create_raw(src_ipc->map_buf[i]);
|
||||||
|
|
||||||
int ret = obj_map_src_dst(&dst_tk->obj_space, &src_tk->obj_space,
|
int ret = obj_map_src_dst(&dst_tk->obj_space, &src_tk->obj_space,
|
||||||
dst_ipc->map_buf[i], src_ipc->map_buf[i], dst_tk->lim);
|
vpage_get_obj_handler(dst_page),
|
||||||
|
vpage_get_obj_handler(src_page),
|
||||||
|
dst_tk->lim,
|
||||||
|
vpage_get_attrs(src_page));
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include "kobject.h"
|
#include "kobject.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
|
||||||
bool_t obj_map_root(kobject_t *kobj, obj_space_t *obj_space, ram_limit_t *ram, obj_addr_t addr)
|
bool_t obj_map_root(kobject_t *kobj, obj_space_t *obj_space, ram_limit_t *ram, vpage_t page)
|
||||||
{
|
{
|
||||||
obj_map_entry_t *map = obj_space_insert(obj_space, ram, kobj, addr);
|
obj_map_entry_t *map = obj_space_insert(obj_space, ram, kobj, vpage_get_obj_handler(page), vpage_get_attrs(page));
|
||||||
|
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
@@ -18,17 +18,22 @@ bool_t obj_map_root(kobject_t *kobj, obj_space_t *obj_space, ram_limit_t *ram, o
|
|||||||
}
|
}
|
||||||
int obj_map_src_dst(obj_space_t *dst_space, obj_space_t *src_space,
|
int obj_map_src_dst(obj_space_t *dst_space, obj_space_t *src_space,
|
||||||
obj_handler_t dst_inx, obj_handler_t src_inx,
|
obj_handler_t dst_inx, obj_handler_t src_inx,
|
||||||
ram_limit_t *ram)
|
ram_limit_t *ram, uint8_t del_attrs)
|
||||||
{
|
{
|
||||||
kobject_t *source_kobj = obj_space_lookup_kobj(src_space, src_inx);
|
obj_map_entry_t *entry_obj =
|
||||||
|
obj_space_lookup(src_space, src_inx);
|
||||||
if (!source_kobj)
|
if (!entry_obj)
|
||||||
{
|
{
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
return obj_map(dst_space, dst_inx, source_kobj, ram);
|
if (!entry_obj->obj)
|
||||||
|
{
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
return obj_map(dst_space, dst_inx, obj_map_entry_kobj_get(entry_obj),
|
||||||
|
ram, obj_map_entry_get_attr(entry_obj) & (~(del_attrs & 0x3UL)));
|
||||||
}
|
}
|
||||||
int obj_map(obj_space_t *obj_space, obj_handler_t inx, kobject_t *insert_kobj, ram_limit_t *ram)
|
int obj_map(obj_space_t *obj_space, obj_handler_t inx, kobject_t *insert_kobj, ram_limit_t *ram, uint8_t attrs)
|
||||||
{
|
{
|
||||||
obj_map_entry_t *entry = NULL;
|
obj_map_entry_t *entry = NULL;
|
||||||
|
|
||||||
@@ -41,7 +46,7 @@ int obj_map(obj_space_t *obj_space, obj_handler_t inx, kobject_t *insert_kobj, r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj_map_entry_t *map = obj_space_insert(obj_space, ram, insert_kobj, inx);
|
obj_map_entry_t *map = obj_space_insert(obj_space, ram, insert_kobj, inx, attrs);
|
||||||
|
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
@@ -51,28 +56,53 @@ int obj_map(obj_space_t *obj_space, obj_handler_t inx, kobject_t *insert_kobj, r
|
|||||||
slist_add(&insert_kobj->mappable.node, &map->node);
|
slist_add(&insert_kobj->mappable.node, &map->node);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void obj_unmap(obj_space_t *obj_space, obj_handler_t inx, kobj_del_list_t *del_list)
|
void obj_unmap(obj_space_t *obj_space, vpage_t vpage, kobj_del_list_t *del_list)
|
||||||
{
|
{
|
||||||
obj_map_entry_t *entry = NULL;
|
obj_map_entry_t *entry = NULL;
|
||||||
|
|
||||||
entry = obj_space_lookup(obj_space, inx);
|
entry = obj_space_lookup(obj_space, vpage_get_obj_handler(vpage));
|
||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
kobject_t *kobj = obj_map_kobj_get(entry->obj);
|
kobject_t *kobj = obj_map_entry_kobj_get(entry);
|
||||||
if (!kobj)
|
if (!kobj)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
slist_del(&entry->node);
|
if ((vpage.attrs & KOBJ_DELETE_RIGHT) &&
|
||||||
obj_space_del(obj_space, inx);
|
(obj_map_entry_get_attr(entry) & KOBJ_DELETE_RIGHT))
|
||||||
kobj->mappable.map_cnt--;
|
|
||||||
if (kobj->mappable.map_cnt <= 0)
|
|
||||||
{
|
{
|
||||||
if (del_list)
|
//!< 代表删除所有
|
||||||
|
obj_map_entry_t *pos;
|
||||||
|
|
||||||
|
slist_foreach(pos, &kobj->mappable.node, node)
|
||||||
{
|
{
|
||||||
kobj_del_list_add(del_list, &kobj->del_node);
|
slist_del(&entry->node);
|
||||||
|
entry->obj = NULL;
|
||||||
|
// 删除一个
|
||||||
|
kobj->mappable.map_cnt--;
|
||||||
|
if (kobj->mappable.map_cnt <= 0)
|
||||||
|
{
|
||||||
|
if (del_list)
|
||||||
|
{
|
||||||
|
kobj_del_list_add(del_list, &kobj->del_node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slist_del(&entry->node);
|
||||||
|
entry->obj = NULL;
|
||||||
|
// 删除一个
|
||||||
|
kobj->mappable.map_cnt--;
|
||||||
|
if (kobj->mappable.map_cnt <= 0)
|
||||||
|
{
|
||||||
|
if (del_list)
|
||||||
|
{
|
||||||
|
kobj_del_list_add(del_list, &kobj->del_node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +111,6 @@ void obj_unmap_all(obj_space_t *obj_space, kobj_del_list_t *del_list)
|
|||||||
assert(obj_space);
|
assert(obj_space);
|
||||||
for (umword_t i = 0; i < OBJ_MAP_MAX_ADDR; i++)
|
for (umword_t i = 0; i < OBJ_MAP_MAX_ADDR; i++)
|
||||||
{
|
{
|
||||||
obj_unmap(obj_space, i, del_list);
|
obj_unmap(obj_space, vpage_create3(KOBJ_DELETE_RIGHT /*执行删除操作*/, 0, i), del_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void obj_space_del(obj_space_t *obj_space, obj_addr_t inx)
|
|||||||
}
|
}
|
||||||
obj_space->tab.tabs[tab_inx]->items[entry_inx].obj = NULL;
|
obj_space->tab.tabs[tab_inx]->items[entry_inx].obj = NULL;
|
||||||
}
|
}
|
||||||
obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobject_t *kobj, obj_addr_t inx)
|
obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobject_t *kobj, obj_addr_t inx, uint8_t attrs)
|
||||||
{
|
{
|
||||||
assert(obj_space);
|
assert(obj_space);
|
||||||
assert(kobj);
|
assert(kobj);
|
||||||
@@ -51,6 +51,7 @@ obj_map_entry_t *obj_space_insert(obj_space_t *obj_space, ram_limit_t *ram, kobj
|
|||||||
slist_init(&entry->node);
|
slist_init(&entry->node);
|
||||||
}
|
}
|
||||||
entry->obj = kobj;
|
entry->obj = kobj;
|
||||||
|
obj_map_entry_set_attr(entry, attrs);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
obj_map_entry_t *obj_space_lookup(obj_space_t *obj_space, obj_addr_t inx)
|
obj_map_entry_t *obj_space_lookup(obj_space_t *obj_space, obj_addr_t inx)
|
||||||
|
|||||||
@@ -66,15 +66,9 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
|
|||||||
break;
|
break;
|
||||||
case TASK_OBJ_MAP:
|
case TASK_OBJ_MAP:
|
||||||
{
|
{
|
||||||
kobject_t *source_kobj = obj_space_lookup_kobj(&cur_task->obj_space, f->r[1]);
|
int ret = obj_map_src_dst(&tag_task->obj_space, &cur_task->obj_space,
|
||||||
|
f->r[2], f->r[1],
|
||||||
if (!source_kobj)
|
tag_task->lim, f->r[3]);
|
||||||
{
|
|
||||||
tag = msg_tag_init4(0, 0, 0, -ENOENT);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = obj_map(&tag_task->obj_space, f->r[2], source_kobj, tag_task->lim);
|
|
||||||
|
|
||||||
tag = msg_tag_init4(0, 0, 0, ret);
|
tag = msg_tag_init4(0, 0, 0, ret);
|
||||||
}
|
}
|
||||||
@@ -91,7 +85,7 @@ static void task_syscall_func(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t i
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
kobj_del_list_init(&kobj_list);
|
kobj_del_list_init(&kobj_list);
|
||||||
obj_unmap(&tag_task->obj_space, f->r[1], &kobj_list);
|
obj_unmap(&tag_task->obj_space, vpage_create_raw(f->r[1]), &kobj_list);
|
||||||
kobj_del_list_to_do(&kobj_list);
|
kobj_del_list_to_do(&kobj_list);
|
||||||
spinlock_set(&tag_task->kobj.lock, status);
|
spinlock_set(&tag_task->kobj.lock, status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ static void thread_release_stage1(kobject_t *kobj)
|
|||||||
{
|
{
|
||||||
thread_t *th = container_of(kobj, thread_t, kobj);
|
thread_t *th = container_of(kobj, thread_t, kobj);
|
||||||
kobject_invalidate(kobj);
|
kobject_invalidate(kobj);
|
||||||
thread_suspend(th);
|
if (th->status == THREAD_READY)
|
||||||
|
{
|
||||||
|
thread_suspend(th);
|
||||||
|
}
|
||||||
thread_unbind(th);
|
thread_unbind(th);
|
||||||
}
|
}
|
||||||
static void thread_release_stage2(kobject_t *kobj)
|
static void thread_release_stage2(kobject_t *kobj)
|
||||||
@@ -101,10 +104,13 @@ void thread_bind(thread_t *th, kobject_t *tk)
|
|||||||
*/
|
*/
|
||||||
void thread_unbind(thread_t *th)
|
void thread_unbind(thread_t *th)
|
||||||
{
|
{
|
||||||
task_t *tsk = container_of(th->task, task_t, kobj);
|
if (th->task)
|
||||||
|
{
|
||||||
|
task_t *tsk = container_of(th->task, task_t, kobj);
|
||||||
|
|
||||||
ref_counter_dec_and_release(&tsk->ref_cn, &th->kobj);
|
ref_counter_dec_and_release(&tsk->ref_cn, &th->kobj);
|
||||||
th->task = NULL;
|
th->task = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief 挂起一个线程
|
* @brief 挂起一个线程
|
||||||
|
|||||||
@@ -61,14 +61,14 @@ static void knl_init_2(void)
|
|||||||
thread_set_msg_bug(init_thread, (char *)(init_task->mm_space.mm_block) + app->i.ram_size, THREAD_MSG_BUG_LEN);
|
thread_set_msg_bug(init_thread, (char *)(init_task->mm_space.mm_block) + app->i.ram_size, THREAD_MSG_BUG_LEN);
|
||||||
thread_bind(init_thread, &init_task->kobj);
|
thread_bind(init_thread, &init_task->kobj);
|
||||||
thread_user_pf_set(init_thread, (void *)(KNL_TEXT + INIT_OFFSET), sp_addr_top, init_task->mm_space.mm_block);
|
thread_user_pf_set(init_thread, (void *)(KNL_TEXT + INIT_OFFSET), sp_addr_top, init_task->mm_space.mm_block);
|
||||||
assert(obj_map_root(&init_thread->kobj, &init_task->obj_space, &root_factory_get()->limit, THREAD_PROT));
|
assert(obj_map_root(&init_thread->kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, THREAD_PROT)));
|
||||||
assert(obj_map_root(&init_task->kobj, &init_task->obj_space, &root_factory_get()->limit, TASK_PROT));
|
assert(obj_map_root(&init_task->kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, TASK_PROT)));
|
||||||
for (int i = FACTORY_PORT_START; i < FACTORY_PORT_END; i++)
|
for (int i = FACTORY_PORT_START; i < FACTORY_PORT_END; i++)
|
||||||
{
|
{
|
||||||
kobject_t *kobj = global_get_kobj(i);
|
kobject_t *kobj = global_get_kobj(i);
|
||||||
if (kobj)
|
if (kobj)
|
||||||
{
|
{
|
||||||
assert(obj_map_root(kobj, &init_task->obj_space, &root_factory_get()->limit, i));
|
assert(obj_map_root(kobj, &init_task->obj_space, &root_factory_get()->limit, vpage_create3(KOBJ_ALL_RIGHTS, 0, i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread_ready(init_thread, FALSE);
|
thread_ready(init_thread, FALSE);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma
|
#pragma
|
||||||
|
|
||||||
#include "u_types.h"
|
#include "u_types.h"
|
||||||
|
#include "u_prot.h"
|
||||||
|
|
||||||
msg_tag_t factory_create_ipc(obj_handler_t obj, obj_handler_t tgt_obj_handler);
|
msg_tag_t factory_create_ipc(obj_handler_t obj, vpage_t vpage);
|
||||||
msg_tag_t factory_create_thread(obj_handler_t obj, obj_handler_t tgt_obj_handler);
|
msg_tag_t factory_create_thread(obj_handler_t obj, vpage_t vpage);
|
||||||
msg_tag_t factory_create_task(obj_handler_t obj, obj_handler_t tgt_obj_handler);
|
msg_tag_t factory_create_task(obj_handler_t obj, vpage_t vpage);
|
||||||
@@ -55,3 +55,23 @@ static inline syscall_prot_t syscall_prot_create(uint8_t op, uint8_t prot, obj_h
|
|||||||
.obj_inx = obj_inx,
|
.obj_inx = obj_inx,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef union vpage
|
||||||
|
{
|
||||||
|
umword_t raw;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
umword_t attrs : 4; //!< 权限
|
||||||
|
umword_t : 8; //!< 保留
|
||||||
|
umword_t addr : (WORD_BITS - 12); //!< 地址
|
||||||
|
};
|
||||||
|
} vpage_t;
|
||||||
|
|
||||||
|
static inline vpage_t vpage_create_raw(umword_t raw)
|
||||||
|
{
|
||||||
|
return (vpage_t){.raw = raw};
|
||||||
|
}
|
||||||
|
static inline vpage_t vpage_create_raw3(umword_t attrs, umword_t resv, umword_t addr)
|
||||||
|
{
|
||||||
|
return (vpage_t){.attrs = attrs, .addr = addr};
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,13 @@
|
|||||||
#include "u_prot.h"
|
#include "u_prot.h"
|
||||||
#include "u_types.h"
|
#include "u_types.h"
|
||||||
|
|
||||||
|
enum obj_attrs
|
||||||
|
{
|
||||||
|
KOBJ_DELETE_RIGHT = 1,
|
||||||
|
KOBJ_ALL_RIGHTS = 3,
|
||||||
|
};
|
||||||
|
|
||||||
msg_tag_t task_obj_valid(obj_handler_t dst_task, obj_handler_t obj_inx);
|
msg_tag_t task_obj_valid(obj_handler_t dst_task, obj_handler_t obj_inx);
|
||||||
msg_tag_t task_map(obj_handler_t dst_task, obj_handler_t src_obj, obj_handler_t dst_obj);
|
msg_tag_t task_map(obj_handler_t dst_task, obj_handler_t src_obj, obj_handler_t dst_obj, uint8_t attrs);
|
||||||
msg_tag_t task_unmap(obj_handler_t task_han, obj_handler_t obj);
|
msg_tag_t task_unmap(obj_handler_t task_han, vpage_t vpage);
|
||||||
msg_tag_t task_alloc_ram_base(obj_handler_t task_han, umword_t size, addr_t *alloc_addr);
|
msg_tag_t task_alloc_ram_base(obj_handler_t task_han, umword_t size, addr_t *alloc_addr);
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ enum
|
|||||||
FACTORY_CREATE_KOBJ
|
FACTORY_CREATE_KOBJ
|
||||||
};
|
};
|
||||||
|
|
||||||
msg_tag_t factory_create_thread(obj_handler_t obj, obj_handler_t tgt_obj_handler)
|
msg_tag_t factory_create_thread(obj_handler_t obj, vpage_t vpage)
|
||||||
{
|
{
|
||||||
register volatile umword_t r0 asm("r0");
|
register volatile umword_t r0 asm("r0");
|
||||||
|
|
||||||
syscall(syscall_prot_create(FACTORY_CREATE_KOBJ, FACTORY_PROT, obj),
|
syscall(syscall_prot_create(FACTORY_CREATE_KOBJ, FACTORY_PROT, obj),
|
||||||
0,
|
0,
|
||||||
THREAD_PROT,
|
THREAD_PROT,
|
||||||
tgt_obj_handler,
|
vpage.raw,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
@@ -22,14 +22,14 @@ msg_tag_t factory_create_thread(obj_handler_t obj, obj_handler_t tgt_obj_handler
|
|||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
msg_tag_t factory_create_task(obj_handler_t obj, obj_handler_t tgt_obj_handler)
|
msg_tag_t factory_create_task(obj_handler_t obj, vpage_t vpage)
|
||||||
{
|
{
|
||||||
register volatile umword_t r0 asm("r0");
|
register volatile umword_t r0 asm("r0");
|
||||||
|
|
||||||
syscall(syscall_prot_create(FACTORY_CREATE_KOBJ, FACTORY_PROT, obj),
|
syscall(syscall_prot_create(FACTORY_CREATE_KOBJ, FACTORY_PROT, obj),
|
||||||
0,
|
0,
|
||||||
TASK_PROT,
|
TASK_PROT,
|
||||||
tgt_obj_handler,
|
vpage.raw,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
@@ -37,14 +37,14 @@ msg_tag_t factory_create_task(obj_handler_t obj, obj_handler_t tgt_obj_handler)
|
|||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
msg_tag_t factory_create_ipc(obj_handler_t obj, obj_handler_t tgt_obj_handler)
|
msg_tag_t factory_create_ipc(obj_handler_t obj, vpage_t vpage)
|
||||||
{
|
{
|
||||||
register volatile umword_t r0 asm("r0");
|
register volatile umword_t r0 asm("r0");
|
||||||
|
|
||||||
syscall(syscall_prot_create(FACTORY_CREATE_KOBJ, FACTORY_PROT, obj),
|
syscall(syscall_prot_create(FACTORY_CREATE_KOBJ, FACTORY_PROT, obj),
|
||||||
0,
|
0,
|
||||||
IPC_PROT,
|
IPC_PROT,
|
||||||
tgt_obj_handler,
|
vpage.raw,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
|
|||||||
@@ -46,6 +46,6 @@ void handler_free(obj_handler_t hd_inx)
|
|||||||
*/
|
*/
|
||||||
void handler_free_umap(obj_handler_t hd_inx)
|
void handler_free_umap(obj_handler_t hd_inx)
|
||||||
{
|
{
|
||||||
task_unmap(TASK_THIS, hd_inx);
|
task_unmap(TASK_THIS, vpage_create_raw3(0, 0, hd_inx));
|
||||||
handler_free(hd_inx);
|
handler_free(hd_inx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ msg_tag_t task_obj_valid(obj_handler_t dst_task, obj_handler_t obj_inx)
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_tag_t task_map(obj_handler_t dst_task, obj_handler_t src_obj, obj_handler_t dst_obj)
|
msg_tag_t task_map(obj_handler_t dst_task, obj_handler_t src_obj, obj_handler_t dst_obj, uint8_t attrs)
|
||||||
{
|
{
|
||||||
register volatile umword_t r0 asm("r0");
|
register volatile umword_t r0 asm("r0");
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ msg_tag_t task_map(obj_handler_t dst_task, obj_handler_t src_obj, obj_handler_t
|
|||||||
0,
|
0,
|
||||||
src_obj,
|
src_obj,
|
||||||
dst_obj,
|
dst_obj,
|
||||||
0,
|
attrs,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
msg_tag_t tag = msg_tag_init(r0);
|
msg_tag_t tag = msg_tag_init(r0);
|
||||||
@@ -40,13 +40,13 @@ msg_tag_t task_map(obj_handler_t dst_task, obj_handler_t src_obj, obj_handler_t
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_tag_t task_unmap(obj_handler_t task_han, obj_handler_t obj)
|
msg_tag_t task_unmap(obj_handler_t task_han, vpage_t vpage)
|
||||||
{
|
{
|
||||||
register volatile umword_t r0 asm("r0");
|
register volatile umword_t r0 asm("r0");
|
||||||
|
|
||||||
syscall(syscall_prot_create(TASK_OBJ_UNMAP, TASK_PROT, task_han),
|
syscall(syscall_prot_create(TASK_OBJ_UNMAP, TASK_PROT, task_han),
|
||||||
0,
|
0,
|
||||||
obj,
|
vpage.raw,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ int main(int argc, char *args[])
|
|||||||
printf_test();
|
printf_test();
|
||||||
thread_test();
|
thread_test();
|
||||||
thread_exit_test();
|
thread_exit_test();
|
||||||
map_test();
|
|
||||||
ipc_test();
|
ipc_test();
|
||||||
|
map_test();
|
||||||
#endif
|
#endif
|
||||||
ipc_timeout_test();
|
// ipc_timeout_test();
|
||||||
app_test();
|
app_test();
|
||||||
while (1)
|
// while (1)
|
||||||
;
|
// ;
|
||||||
task_unmap(TASK_THIS, TASK_THIS);
|
// factory_create_ipc(FACTORY_PROT, vpage_create_raw3(0, 0, 10));
|
||||||
|
// factory_create_thread(FACTORY_PROT, vpage_create_raw3(0, 0, 11));
|
||||||
|
// factory_create_task(FACTORY_PROT, vpage_create_raw3(0, 0, 12));
|
||||||
|
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); // 删除当前task,以及申请得所有对象
|
||||||
printf("exit init.\n");
|
printf("exit init.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
void app_test(void)
|
void app_test(void)
|
||||||
{
|
{
|
||||||
msg_tag_t tag;
|
msg_tag_t tag;
|
||||||
umword_t addr = cpio_find_file((umword_t)0x8020000, (umword_t)0x8040000, "fatfs");
|
umword_t addr = cpio_find_file((umword_t)0x8020000, (umword_t)0x8040000, "shell");
|
||||||
assert(addr);
|
assert(addr);
|
||||||
|
|
||||||
app_info_t *app = (app_info_t *)addr;
|
app_info_t *app = (app_info_t *)addr;
|
||||||
@@ -30,21 +30,23 @@ void app_test(void)
|
|||||||
assert(hd_task != HANDLER_INVALID);
|
assert(hd_task != HANDLER_INVALID);
|
||||||
assert(hd_thread != HANDLER_INVALID);
|
assert(hd_thread != HANDLER_INVALID);
|
||||||
|
|
||||||
tag = factory_create_task(FACTORY_PROT, hd_task);
|
tag = factory_create_task(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd_task));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, hd_thread);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd_thread));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_ipc(FACTORY_PROT, hd_ipc);
|
tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd_ipc));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
printf("ipc hd is %d\n", hd_ipc);
|
printf("ipc hd is %d\n", hd_ipc);
|
||||||
|
|
||||||
tag = task_alloc_ram_base(hd_task, app->i.ram_size, &ram_base);
|
tag = task_alloc_ram_base(hd_task, app->i.ram_size, &ram_base);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = task_map(hd_task, LOG_PROT, LOG_PROT);
|
tag = task_map(hd_task, hd_task, TASK_PROT, 0);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = task_map(hd_task, hd_ipc, hd_ipc);
|
tag = task_map(hd_task, LOG_PROT, LOG_PROT, 0);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = task_map(hd_task, hd_thread, THREAD_MAIN);
|
tag = task_map(hd_task, hd_ipc, hd_ipc, 0);
|
||||||
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
|
tag = task_map(hd_task, hd_thread, THREAD_MAIN, 0);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
void *sp_addr = (char *)ram_base + app->i.stack_offset - app->i.data_offset;
|
void *sp_addr = (char *)ram_base + app->i.stack_offset - app->i.data_offset;
|
||||||
void *sp_addr_top = (char *)sp_addr + app->i.stack_size;
|
void *sp_addr_top = (char *)sp_addr + app->i.stack_size;
|
||||||
|
|||||||
@@ -2,13 +2,17 @@
|
|||||||
#include "u_prot.h"
|
#include "u_prot.h"
|
||||||
#include "u_factory.h"
|
#include "u_factory.h"
|
||||||
#include "u_task.h"
|
#include "u_task.h"
|
||||||
|
#include "u_hd_man.h"
|
||||||
|
#include <assert.h>
|
||||||
void factory_test(void)
|
void factory_test(void)
|
||||||
{
|
{
|
||||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, 12);
|
obj_handler_t hd = handler_alloc();
|
||||||
|
assert(hd != HANDLER_INVALID);
|
||||||
|
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd));
|
||||||
if (msg_tag_get_prot(tag) < 0)
|
if (msg_tag_get_prot(tag) < 0)
|
||||||
{
|
{
|
||||||
printf("factory_create_ipc no memory\n");
|
printf("factory_create_ipc no memory\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
task_unmap(TASK_PROT, 12);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, hd));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ static void thread_test_func(void)
|
|||||||
ipc_reply(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0));
|
ipc_reply(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0));
|
||||||
}
|
}
|
||||||
printf("thread_test_func.\n");
|
printf("thread_test_func.\n");
|
||||||
task_unmap(TASK_PROT, th1_hd);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th1_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
static void thread_test_func2(void)
|
static void thread_test_func2(void)
|
||||||
@@ -100,7 +100,7 @@ static void thread_test_func2(void)
|
|||||||
printf("th2:%s", buf);
|
printf("th2:%s", buf);
|
||||||
}
|
}
|
||||||
printf("thread_test_func2.\n");
|
printf("thread_test_func2.\n");
|
||||||
task_unmap(TASK_PROT, th2_hd);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th2_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ static void thread_test_func3(void)
|
|||||||
printf("th3:%s", buf);
|
printf("th3:%s", buf);
|
||||||
}
|
}
|
||||||
printf("thread_test_func2.\n");
|
printf("thread_test_func2.\n");
|
||||||
task_unmap(TASK_PROT, th3_hd);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th3_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -135,9 +135,9 @@ void ipc_test(void)
|
|||||||
ipc_hd = handler_alloc();
|
ipc_hd = handler_alloc();
|
||||||
assert(ipc_hd != HANDLER_INVALID);
|
assert(ipc_hd != HANDLER_INVALID);
|
||||||
|
|
||||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, ipc_hd);
|
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, ipc_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th1_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th1_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
ipc_bind(ipc_hd, th1_hd, 0);
|
ipc_bind(ipc_hd, th1_hd, 0);
|
||||||
tag = thread_msg_buf_set(th1_hd, msg_buf0);
|
tag = thread_msg_buf_set(th1_hd, msg_buf0);
|
||||||
@@ -149,7 +149,7 @@ void ipc_test(void)
|
|||||||
tag = thread_run(th1_hd);
|
tag = thread_run(th1_hd);
|
||||||
|
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th2_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th2_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = thread_msg_buf_set(th2_hd, msg_buf1);
|
tag = thread_msg_buf_set(th2_hd, msg_buf1);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
@@ -161,7 +161,7 @@ void ipc_test(void)
|
|||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
|
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th3_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th3_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = thread_msg_buf_set(th3_hd, msg_buf2);
|
tag = thread_msg_buf_set(th3_hd, msg_buf2);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
@@ -176,7 +176,7 @@ void ipc_test(void)
|
|||||||
void ipc_timeout_test(void)
|
void ipc_timeout_test(void)
|
||||||
{
|
{
|
||||||
obj_handler_t hd = handler_alloc();
|
obj_handler_t hd = handler_alloc();
|
||||||
factory_create_ipc(FACTORY_PROT, hd);
|
factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, hd));
|
||||||
printf("sleep.\n");
|
printf("sleep.\n");
|
||||||
ipc_call(hd, msg_tag_init4(0, 0, 0, 0), ipc_timeout_create2(100, 100));
|
ipc_call(hd, msg_tag_init4(0, 0, 0, 0), ipc_timeout_create2(100, 100));
|
||||||
printf("sleep.\n");
|
printf("sleep.\n");
|
||||||
|
|||||||
@@ -34,17 +34,18 @@ static void thread_test_func(void)
|
|||||||
char *buf;
|
char *buf;
|
||||||
umword_t len;
|
umword_t len;
|
||||||
ipc_msg_t *ipc_msg;
|
ipc_msg_t *ipc_msg;
|
||||||
|
obj_handler_t log_hd = handler_alloc();
|
||||||
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
|
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
|
||||||
ipc_msg = (ipc_msg_t *)buf;
|
ipc_msg = (ipc_msg_t *)buf;
|
||||||
ipc_msg->map_buf[0] = handler_alloc();
|
ipc_msg->map_buf[0] = vpage_create_raw3(0, 0, log_hd).raw;
|
||||||
ipc_wait(ipc_hd, 0);
|
ipc_wait(ipc_hd, 0);
|
||||||
printf("srv recv:%s", buf);
|
printf("srv recv:%s", buf);
|
||||||
ulog_write_str(ipc_msg->map_buf[0], "map test success.\n");
|
ulog_write_str(log_hd, "map test success.\n");
|
||||||
hard_sleep();
|
hard_sleep();
|
||||||
ipc_reply(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0));
|
ipc_reply(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(buf), WORD_BYTES), 0, 0));
|
||||||
printf("thread_test_func.\n");
|
printf("thread_test_func.\n");
|
||||||
task_unmap(TASK_PROT, th1_hd);
|
handler_free(log_hd);
|
||||||
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th1_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
static void thread_test_func2(void)
|
static void thread_test_func2(void)
|
||||||
@@ -56,11 +57,11 @@ static void thread_test_func2(void)
|
|||||||
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
|
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
|
||||||
ipc_msg = (ipc_msg_t *)buf;
|
ipc_msg = (ipc_msg_t *)buf;
|
||||||
strcpy(ipc_msg->msg_buf, "I am th2.\n");
|
strcpy(ipc_msg->msg_buf, "I am th2.\n");
|
||||||
ipc_msg->map_buf[0] = LOG_PROT;
|
ipc_msg->map_buf[0] = vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, LOG_PROT).raw;
|
||||||
ipc_call(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(ipc_msg->msg_buf), WORD_BYTES), 1, 0), ipc_timeout_create2(0, 0));
|
ipc_call(ipc_hd, msg_tag_init4(0, ROUND_UP(strlen(ipc_msg->msg_buf), WORD_BYTES), 1, 0), ipc_timeout_create2(0, 0));
|
||||||
printf("th2:%s", buf);
|
printf("th2:%s", buf);
|
||||||
printf("thread_test_func2.\n");
|
printf("thread_test_func2.\n");
|
||||||
task_unmap(TASK_PROT, th2_hd);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th2_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -74,9 +75,9 @@ void map_test(void)
|
|||||||
th2_hd = handler_alloc();
|
th2_hd = handler_alloc();
|
||||||
assert(th2_hd != HANDLER_INVALID);
|
assert(th2_hd != HANDLER_INVALID);
|
||||||
|
|
||||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, ipc_hd);
|
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, ipc_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th1_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th1_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
ipc_bind(ipc_hd, th1_hd, 0);
|
ipc_bind(ipc_hd, th1_hd, 0);
|
||||||
tag = thread_msg_buf_set(th1_hd, msg_buf0);
|
tag = thread_msg_buf_set(th1_hd, msg_buf0);
|
||||||
@@ -88,7 +89,7 @@ void map_test(void)
|
|||||||
tag = thread_run(th1_hd);
|
tag = thread_run(th1_hd);
|
||||||
|
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th2_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th2_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = thread_msg_buf_set(th2_hd, msg_buf1);
|
tag = thread_msg_buf_set(th2_hd, msg_buf1);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
static umword_t th1_hd = 0;
|
static umword_t th1_hd = 0;
|
||||||
static umword_t th2_hd = 0;
|
static umword_t th2_hd = 0;
|
||||||
static umword_t ipc_hd = 0;
|
static umword_t ipc_hd = 0;
|
||||||
@@ -22,7 +21,7 @@ static __attribute__((aligned(8))) uint8_t stack1[STACK_SIZE];
|
|||||||
|
|
||||||
static void hard_sleep(void)
|
static void hard_sleep(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (volatile int i; i < 10000000; i++)
|
for (volatile int i; i < 10000000; i++)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@@ -32,7 +31,7 @@ static void thread_test_func(void)
|
|||||||
umword_t len;
|
umword_t len;
|
||||||
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
|
thread_msg_buf_get(th1_hd, (umword_t *)(&buf), NULL);
|
||||||
printf("thread_test_func.\n");
|
printf("thread_test_func.\n");
|
||||||
task_unmap(TASK_PROT, th1_hd);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th1_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
static void thread_test_func2(void)
|
static void thread_test_func2(void)
|
||||||
@@ -41,11 +40,10 @@ static void thread_test_func2(void)
|
|||||||
umword_t len;
|
umword_t len;
|
||||||
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
|
thread_msg_buf_get(th2_hd, (umword_t *)(&buf), NULL);
|
||||||
printf("thread_test_func2.\n");
|
printf("thread_test_func2.\n");
|
||||||
task_unmap(TASK_PROT, th2_hd);
|
task_unmap(TASK_PROT, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th2_hd));
|
||||||
printf("Error\n");
|
printf("Error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 启动两个线程并进行ipc测试
|
* @brief 启动两个线程并进行ipc测试
|
||||||
*
|
*
|
||||||
@@ -59,9 +57,9 @@ void thread_exit_test(void)
|
|||||||
ipc_hd = handler_alloc();
|
ipc_hd = handler_alloc();
|
||||||
assert(ipc_hd != HANDLER_INVALID);
|
assert(ipc_hd != HANDLER_INVALID);
|
||||||
|
|
||||||
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, ipc_hd);
|
msg_tag_t tag = factory_create_ipc(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, ipc_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th1_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th1_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = thread_msg_buf_set(th1_hd, msg_buf0);
|
tag = thread_msg_buf_set(th1_hd, msg_buf0);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
@@ -72,7 +70,7 @@ void thread_exit_test(void)
|
|||||||
tag = thread_run(th1_hd);
|
tag = thread_run(th1_hd);
|
||||||
|
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = factory_create_thread(FACTORY_PROT, th2_hd);
|
tag = factory_create_thread(FACTORY_PROT, vpage_create_raw3(KOBJ_ALL_RIGHTS, 0, th2_hd));
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = thread_msg_buf_set(th2_hd, msg_buf1);
|
tag = thread_msg_buf_set(th2_hd, msg_buf1);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
@@ -82,5 +80,4 @@ void thread_exit_test(void)
|
|||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
tag = thread_run(th2_hd);
|
tag = thread_run(th2_hd);
|
||||||
assert(msg_tag_get_prot(tag) >= 0);
|
assert(msg_tag_get_prot(tag) >= 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ int main(int argc, char *args[])
|
|||||||
umword_t len;
|
umword_t len;
|
||||||
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
thread_msg_buf_get(THREAD_MAIN, (umword_t *)(&buf), NULL);
|
||||||
printf(buf);
|
printf(buf);
|
||||||
task_unmap(TASK_THIS, TASK_THIS);
|
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS));
|
||||||
ulog_write_str(LOG_PROT, "Error.\n");
|
ulog_write_str(LOG_PROT, "Error.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user