mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
check overflow for VM stack
This commit is contained in:
parent
b49c7d5c7c
commit
2fa39bb973
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=pikaMain.list_iter"
|
||||
"--gtest_filter=pikaMain.big_bytes"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -1891,3 +1891,16 @@ TEST(pikaMain, int_from_bytes) {
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
// TEST(pikaMain, big_bytes) {
|
||||
// /* init */
|
||||
// pikaMemInfo.heapUsedMax = 0;
|
||||
// /* run */
|
||||
// PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
||||
// __platform_printf("BEGIN\r\n");
|
||||
// obj_run(self, "b = bytes(8192)\n");
|
||||
// /* assert */
|
||||
// /* deinit */
|
||||
// obj_deinit(self);
|
||||
// EXPECT_EQ(pikaMemNow(), 0);
|
||||
// }
|
||||
|
@ -40,6 +40,7 @@ int32_t stack_init(Stack* stack) {
|
||||
stack->stack_size_array =
|
||||
arg_setContent(NULL, NULL, PIKA_STACK_BUFF_SIZE / 4);
|
||||
stack_reset(stack);
|
||||
stack->stack_totle_size = PIKA_STACK_BUFF_SIZE;
|
||||
return 0;
|
||||
};
|
||||
|
||||
@ -60,6 +61,19 @@ int32_t stack_deinit(Stack* stack) {
|
||||
}
|
||||
|
||||
void stack_pushPyload(Stack* stack, Arg* content, size_t size) {
|
||||
size_t stack_size_after_push =
|
||||
size + (stack->sp - arg_getContent(stack->stack_pyload));
|
||||
if (stack_size_after_push > stack->stack_totle_size) {
|
||||
__platform_printf(
|
||||
"OverflowError: pika VM stack overflow, please use bigger "
|
||||
"PIKA_STACK_BUFF_SIZE\r\n");
|
||||
__platform_printf("Info: stack size request: %d\r\n",
|
||||
stack_size_after_push);
|
||||
__platform_printf("Info: stack size now: %d\r\n",
|
||||
stack->stack_totle_size);
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
__platform_memcpy(stack->sp, content, size);
|
||||
stack->sp += size;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ typedef struct Stack_t {
|
||||
uint8_t* sp;
|
||||
int16_t* sp_size;
|
||||
int16_t top;
|
||||
size_t stack_totle_size;
|
||||
} Stack;
|
||||
|
||||
int32_t stack_deinit(Stack* stack);
|
||||
|
Loading…
x
Reference in New Issue
Block a user