fix: Fix stack related errors (#1167)

* fix: Fix stack related errors

Increase kernel stack to 32k.
Add a stack overflow test.
Remove manual placement of guard pages

Signed-off-by: Godones <chenlinfeng25@outlook.com>

* fix: update userstack comments

Signed-off-by: Godones <chenlinfeng25@outlook.com>

---------

Signed-off-by: Godones <chenlinfeng25@outlook.com>
This commit is contained in:
linfeng
2025-05-22 08:52:32 +08:00
committed by GitHub
parent 880720250e
commit ba734c8d6b
6 changed files with 159 additions and 123 deletions

1
user/apps/test_stack/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test_stack

View File

@ -0,0 +1,20 @@
ifeq ($(ARCH), x86_64)
CROSS_COMPILE=x86_64-linux-musl-
else ifeq ($(ARCH), riscv64)
CROSS_COMPILE=riscv64-linux-musl-
endif
CC=$(CROSS_COMPILE)gcc
.PHONY: all
all: main.c
$(CC) -static -o test_stack main.c
.PHONY: install clean
install: all
mv test_stack $(DADK_CURRENT_BUILD_DIR)/test_stack
clean:
rm test_stack *.o
fmt:

View File

@ -0,0 +1,13 @@
#include <stdio.h>
void overflow(int depth) {
char buffer[1024 * 1024]; // 占用一些栈空间
printf("Recursion depth: %d\n", depth);
overflow(depth + 1); // 递归调用
}
int main() {
overflow(1);
printf("This line will not be printed due to stack overflow.\n");
return 0;
}

View File

@ -0,0 +1,32 @@
# 用户程序名称
name = "test_stack"
# 版本号
version = "0.1.0"
# 用户程序描述信息
description = "test_stack"
# 目标架构
target-arch = ["x86_64"]
# 任务源
[task-source]
# 构建类型
type = "build-from-source"
# 构建来源
source = "local"
# 路径或URL
source-path = "user/apps/test_stack"
# 构建相关信息
[build]
# (可选)构建命令
build-command = "make install"
# 安装相关信息
[install]
# 可选安装到DragonOS的路径
in-dragonos-path = "/bin"
# 清除相关信息
[clean]
# (可选)清除命令
clean-command = "make clean"