Skip to content

Commit

Permalink
修正部分命名
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Dec 30, 2024
1 parent ae9c56d commit 4f5c9db
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 73 deletions.
2 changes: 2 additions & 0 deletions include/define/define/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

#define COUNT_ARGS(...) __ARGN__(__VA_ARGS__)

#define PADDING_DOWN(size, to) ((size_t)(size) / (size_t)(to) * (size_t)(to))
#define PADDING_UP(size, to) PADDING_DOWN((size_t)(size) + (size_t)(to) - (size_t)1, to)

Expand Down
104 changes: 92 additions & 12 deletions include/kernel/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#define PAGE_END (PT_ADDRESS + 0x400000)
#define PAGE_MANNAGER PAGE_END

#define PF_PRESENT MASK(0) // 程序尝试访问的页面是否存在于内存中
#define PF_WRITE MASK(1) // 程序进行的访问类型是否为写入
#define PF_USER MASK(2) // 错误是否在用户态下发生
#define PF_RESERVED MASK(3) // 程序是否尝试访问保留的地址
#define PF_IFETCH MASK(4) // 是否为 cpu 取指时发生的错误

#ifdef __x86_64__

#else
Expand Down Expand Up @@ -86,19 +92,37 @@ finline size_t mk_linear_addr(size_t table, size_t page, size_t off) {
}
#endif

u32 page_get_attr(u32 pde, u32 vaddr);
u32 page_get_phy(u32 pde, u32 vaddr);
void tpo2page(int *page, int t, int p);
u32 page_get_attr(u32 pde, u32 vaddr);

usize page_get_phy2(usize addr, usize pd);
usize page_get_phy1(usize addr);
#define page_get_phy(...) CONCAT(page_get_phy, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)

void tpo2page(int *page, int t, int p);

void *page_malloc_one_count_from_4gb();

void *page_alloc(size_t size);
void page_free(void *p, size_t size);

void page_free(void *p, size_t size);

usize pd_clone(usize addr);
void pd_free(usize addr);

void pd_free(usize addr);

void *page_malloc_one();
void page_link(u32 addr);
void page_link_share(u32 addr);
void page_unlink(u32 addr);
u32 page_get_alloced();

void page_link2(usize addr, usize pd);
void page_link1(usize addr);
#define page_link(...) CONCAT(page_link, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)

void page_link_share2(usize addr, usize pd);
void page_link_share1(usize addr);
#define page_link_share(...) CONCAT(page_link_share, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)

void page_unlink(u32 addr);

u32 page_get_alloced();

/**
*\brief
Expand All @@ -122,10 +146,42 @@ enum {
*\brief 检查用户是否有对指定内存地址的访问权限
*
*\param addr 内存地址
*\param wr 是否写权限 (默认 false)
*\param cr3 分页设置(cr3) (默认 当前 cr3)
*\return 是否有权限
*/
bool check_address_permission3(const void *addr, bool wr, usize cr3);

/**
*\brief 检查用户是否有对指定内存地址的访问权限
*
*\param addr 内存地址
*\param wr 是否写权限 (默认 false)
*\return 是否有权限
*/
bool check_address_permission2(const void *addr, bool wr);

/**
*\brief 检查用户是否有对指定内存地址的访问权限
*
*\param addr 内存地址
*\return 是否有权限
*/
bool check_address_permission1(const void *addr);

#define check_address_permission(...) \
CONCAT(check_address_permission, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)

/**
*\brief 检查用户是否有对指定内存区域的访问权限
*
*\param addr 内存地址
*\param size 内存大小
*\param wr 是否写权限
*\param cr3 分页设置(cr3) (默认 当前 cr3)
*\return 是否有权限
*/
bool check_address_permission(const void *addr, bool wr);
bool check_memory_permission4(const void *addr, size_t size, bool wr, usize cr3);

/**
*\brief 检查用户是否有对指定内存区域的访问权限
Expand All @@ -135,12 +191,36 @@ bool check_address_permission(const void *addr, bool wr);
*\param wr 是否写权限
*\return 是否有权限
*/
bool check_memory_permission(const void *addr, size_t size, bool wr);
bool check_memory_permission3(const void *addr, size_t size, bool wr);

/**
*\brief 检查用户是否有对指定内存区域的访问权限
*
*\param addr 内存地址
*\param size 内存大小
*\return 是否有权限
*/
bool check_memory_permission2(const void *addr, size_t size);

#define check_memory_permission(...) \
CONCAT(check_memory_permission, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)

/**
*\brief 检查用户是否有对指定字符串的读取权限
*
*\param addr 内存地址
*\param cr3 分页设置(cr3) (默认 当前 cr3)
*\return 是否有权限
*/
bool check_string_permission(cstr addr);
bool check_string_permission2(cstr addr, usize cr3);

/**
*\brief 检查用户是否有对指定字符串的读取权限
*
*\param addr 内存地址
*\return 是否有权限
*/
bool check_string_permission1(cstr addr);

#define check_string_permission(...) \
CONCAT(check_string_permission, COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__)
4 changes: 2 additions & 2 deletions src/kernel/cpu/handler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ asm_inthandler: ; DON'T EDIT THE CODE BELOW!
dd 0xfffff91a, 0x13e9fc6a, 0x6afffff9, 0xf90ce9fd, 0xfe6affff, 0xfff905e9, 0xe9ff6aff, 0xfffff8fe
asm_inthandler_end: ; DON'T EDIT THE CODE ABOVE!
extern check_memory_permission, task_abort
extern check_memory_permission3, task_abort
asm_sysenter_handler:
push RING3_DS ; push ss
push ecx ; push esp
Expand All @@ -114,7 +114,7 @@ asm_sysenter_handler:
push 0 ; ==================================================
push 8 ;
push ebx ;
call check_memory_permission ; If ring3 esp is not accessible, we should abort the task.
call check_memory_permission3; If ring3 esp is not accessible, we should abort the task.
cmp eax, 0 ;
je task_abort ;
add esp, 12 ; ==================================================
Expand Down
Loading

0 comments on commit 4f5c9db

Please sign in to comment.