Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync from master #6981

Merged
merged 23 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
feed84b
fix rt_kprint 64bit error
zhkag Feb 20, 2023
ff58949
update rtdevice.h add lcd
XYZ-20240101 Feb 18, 2023
aaba21c
[fix]避免字符设备特殊控制指令和通用控制指令冲突
JonasWen Feb 21, 2023
1533b88
[arduino][lpc55s69] : 对接RTduino
Z8MAN8 Feb 22, 2023
b3b8c23
[spi] rt_spi_configure 增加对cs_pin处理
liYony Feb 23, 2023
52cb2f0
[lwIP] apply AF_UNIX feature (#6954)
Guozhanxin Feb 23, 2023
6d4764a
serial_v2 rt_device_write/read return data type as rt_ssize_t
JonasWen Feb 23, 2023
96a636f
[Renesas]Add tft-lcd lvgl support
Rbb666 Feb 22, 2023
08c2a65
[rtduino][lpc55s69] 修正RTduino框架下的引脚错误 (#6963)
kurisaW Feb 23, 2023
382e9bc
[rt-smart] handling kernel from accessing unmapped user stack (#6957)
polarvid Feb 24, 2023
7bf6648
[serial]增加at32的serial_v2驱动
JonasWen Feb 23, 2023
a5c62b9
[bsp/at32] add support usb driver (#6968)
sheltonyu Feb 25, 2023
022760c
[Infineon]Fix scb5 can't use bug
Rbb666 Feb 24, 2023
faddfec
[rtduino][lpc55s69] update (#6972)
Z8MAN8 Feb 25, 2023
7763183
[rtduino][lpc55s69] 纠正uart引脚错误并使能相关依赖项 (#6976)
kurisaW Feb 25, 2023
e50a7e3
🐞 fix(components/drivers/tty/pty.c): fix ptmx not init (#6970)
xqyjlj Feb 25, 2023
4c1c6ef
解决关中断时进行了调度操作
zhkag Feb 24, 2023
d3553e7
fixed fstat/stat/readlink syscall.
geniusgogo Feb 24, 2023
53afeda
fix inet_ioctlsocket set O_LARGEFILE flag by musl.
geniusgogo Feb 24, 2023
a53367a
fixed O_LARGEFILE not defined ci build error.
geniusgogo Feb 25, 2023
fef2607
[lwp] save virtual addr in shm structure
polarvid Feb 25, 2023
12f0df9
[libcpu/aarch64] stop when no page is free
polarvid Feb 25, 2023
e63e33a
[ch32][bsp] fix warning: rt_size_t to rt_ssize_t
linshire Feb 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[rt-smart] handling kernel from accessing unmapped user stack (#6957)
[rt-smart] handling kernel from accessing unmapped user stack
  • Loading branch information
polarvid committed Feb 24, 2023
commit 382e9bcac746b408b5b01ea2f59338428ab203dd
10 changes: 10 additions & 0 deletions components/lwp/arch/risc-v/rv64/lwp_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ arch_signal_quit:
* routine in user stack
*/
user_do_signal:
/* prefetch ustack to avoid corrupted status in RESTORE/STORE pair below */
LOAD t0, FRAME_OFF_SP(sp)
addi t1, t0, -CTX_REG_NR * REGBYTES
LOAD t2, (t0)
li t3, -0x1000
1:
add t0, t0, t3
LOAD t2, (t0)
bgt t0, t1, 1b

/** restore and backup kernel sp carefully to avoid leaking */
addi t0, sp, CTX_REG_NR * REGBYTES
csrw sscratch, t0
Expand Down
11 changes: 7 additions & 4 deletions components/lwp/lwp_user_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,12 @@ int lwp_user_accessable(void *addr, size_t size)
len = size;
}
tmp_addr = lwp_v2p(lwp, addr_start);
if (!tmp_addr)
if (tmp_addr == ARCH_MAP_FAILED)
{
return 0;
if ((rt_ubase_t)addr_start >= USER_STACK_VSTART && (rt_ubase_t)addr_start < USER_STACK_VEND)
tmp_addr = *(void **)addr_start;
else
return 0;
}
addr_start = (void *)((char *)addr_start + len);
size -= len;
Expand Down Expand Up @@ -596,7 +599,7 @@ size_t lwp_data_get(struct rt_lwp *lwp, void *dst, void *src, size_t size)
len = size;
}
tmp_src = lwp_v2p(lwp, addr_start);
if (!tmp_src)
if (tmp_src == ARCH_MAP_FAILED)
{
break;
}
Expand Down Expand Up @@ -636,7 +639,7 @@ size_t lwp_data_put(struct rt_lwp *lwp, void *dst, void *src, size_t size)
len = size;
}
tmp_dst = lwp_v2p(lwp, addr_start);
if (!tmp_dst)
if (tmp_dst == ARCH_MAP_FAILED)
{
break;
}
Expand Down
6 changes: 5 additions & 1 deletion libcpu/risc-v/t-head/c906/stackframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#ifndef __STACKFRAME_H__
#define __STACKFRAME_H__

#define BYTES(idx) ((idx) * REGBYTES)
#define FRAME_OFF_SSTATUS BYTES(2)
#define FRAME_OFF_SP BYTES(32)

#include "cpuport.h"
#include "encoding.h"

Expand Down Expand Up @@ -54,7 +58,7 @@
/**
* The register `tp` always save/restore when context switch,
* we call `lwp_user_setting_save` when syscall enter,
* call `lwp_user_setting_restore` when syscall exit
* call `lwp_user_setting_restore` when syscall exit
* and modify context stack after `lwp_user_setting_restore` called
* so that the `tp` can be the correct thread area value.
*/
Expand Down
5 changes: 4 additions & 1 deletion libcpu/risc-v/t-head/c906/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ static void handle_nested_trap_panic(
rt_hw_cpu_shutdown();
}

#define IN_USER_SPACE (stval >= USER_VADDR_START && stval < USER_VADDR_TOP)
#define PAGE_FAULT (id == EP_LOAD_PAGE_FAULT || id == EP_STORE_PAGE_FAULT)

/* Trap entry */
void handle_trap(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw_stack_frame *sp)
{
Expand Down Expand Up @@ -314,7 +317,7 @@ void handle_trap(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw
else
{
#ifdef RT_USING_SMART
if (!(sp->sstatus & 0x100))
if (!(sp->sstatus & 0x100) || (PAGE_FAULT && IN_USER_SPACE))
{
handle_user(scause, stval, sepc, sp);
// if handle_user() return here, jump to u mode then
Expand Down
7 changes: 4 additions & 3 deletions libcpu/risc-v/virt64/stackframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include "encoding.h"
#include "ext_context.h"

#define BYTES(idx) ((idx) * REGBYTES)
#define FRAME_OFF_SSTATUS BYTES(2)
#define BYTES(idx) ((idx) * REGBYTES)
#define FRAME_OFF_SSTATUS BYTES(2)
#define FRAME_OFF_SP BYTES(32)

#ifdef __ASSEMBLY__

Expand Down Expand Up @@ -140,7 +141,7 @@

/**
* @brief Restore All General Registers, for interrupt handling
*
*
*/
.macro RESTORE_ALL

Expand Down
5 changes: 4 additions & 1 deletion libcpu/risc-v/virt64/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ static void handle_nested_trap_panic(
rt_hw_cpu_shutdown();
}

#define IN_USER_SPACE (stval >= USER_VADDR_START && stval < USER_VADDR_TOP)
#define PAGE_FAULT (id == EP_LOAD_PAGE_FAULT || id == EP_STORE_PAGE_FAULT)

/* Trap entry */
void handle_trap(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw_stack_frame *sp)
{
Expand Down Expand Up @@ -326,7 +329,7 @@ void handle_trap(rt_size_t scause, rt_size_t stval, rt_size_t sepc, struct rt_hw
}
#endif /* ENABLE_VECTOR */
#ifdef RT_USING_SMART
if (!(sp->sstatus & 0x100))
if (!(sp->sstatus & 0x100) || (PAGE_FAULT && IN_USER_SPACE))
{
handle_user(scause, stval, sepc, sp);
// if handle_user() return here, jump to u mode then
Expand Down