【发布时间】:2018-10-04 02:30:12
【问题描述】:
我正在进行 Pintos 项目,以了解有关操作系统的更多信息。我完成了项目 1 并开始了第二个项目。我已经验证了设置堆栈并且可以正常工作(通过 hex_dump)。现在我在获取正确的系统调用参数时遇到问题。
在 user/syscall.c 中有 4 个程序集存根(0 - 4 个存根)由用户系统调用包装。
#define syscall3(NUMBER, ARG0, ARG1, ARG2) \
({ \
int retval; \
asm volatile \
("pushl %[arg2]; pushl %[arg1]; pushl %[arg0]; " \
"pushl %[number]; int $0x30; addl $16, %%esp" \
: "=a" (retval) \
: [number] "i" (NUMBER), \
[arg0] "g" (ARG0), \
[arg1] "g" (ARG1), \
[arg2] "g" (ARG2) \
: "memory"); \
retval; \
}) (this code is given to us)
我的 syscall_handler 中有一些代码可以调用内核中的正确函数。
static void syscall_handler (struct intr_frame *f) {
uint32_t *args = f->esp;
if (args[0] == SYS_WRITE) {
f->eax = write(args);
}
在我的 write 函数中,我打印出 FD 和 Size
int sysCallNumber = (int) args[0];
int fd = (int) args[1];
const char *buffer = (char *) args[2];
unsigned size = (unsigned) args[3];
printf("FD is %d\n", fd);
printf("Size is %d\n", size);
运行“echo hello stack overflow 1 22 333”将产生以下结果。注意我在括号中添加了注释。 ()
FD is 6 (hello)
Size is 6
FD is 6 (stack)
Size is 6
FD is 9 (overflow)
Size is 9
FD is 2 (1)
Size is 2
FD is 3 (22)
Size is 3
FD is 4 (333)
Size is 4
FD is 1 (this is from the printf("\n") in echo.c)
Size is 1
我在 GDB 设置断点和转储帧的情况下运行了此程序,但无法弄清楚。有没有人遇到过类似的事情?如果有,您是如何解决的?
谢谢!
【问题讨论】:
标签: pintos