我想实现已经在PintOS ()中定义的系统调用( halt(),create()...etc在pintos/src/lib/user/syscall.c中定义)。pintos/src/userprog/syscall.c中的当前系统调用处理程序不执行任何操作。如何创建一个进行系统调用的进程。此外,我需要自己添加一些系统调用。那我该怎么做呢?但首先,我需要实现现有的系统调用。
发布于 2012-08-28 13:18:16
pintos中的默认实现会终止调用进程。
goto this link.There是关于在哪里修改代码以实现系统调用的解释。
"src/examples“目录包含一些示例用户程序。
这个目录中的"Makefile“编译了所提供的示例,您也可以编辑它来编译您自己的程序。
此程序/进程在运行时将反过来进行系统调用。
使用gdb来跟踪一个这样的程序的执行,一个简单的printf语句最终将调用write system call to STDOUT文件。
给出的链接也有关于如何在gdb上运行pintos的指针,我猜你正在使用bochs或qemu.In,任何情况下只需在pintos上运行一个简单的hello world程序来运行一次gdb即可。
这将使您了解系统调用是如何进行的。
static void
syscall_handler (struct intr_frame *f)// UNUSED)
{
int *p=f->esp;
switch(*p)
case *p=SYS_CREATE // NUMBER # DEFINED
const char *name=*(p+1); //extract the filename
if(name==NULL||*name==NULL)
exit(-1);
off_t size=(int32_t)*(p+2);//extract file size
f->eax=filesys_create(name,size,_FILE); //call filesys_create
//eax will have the return value
}这是sys_create的伪代码。所有与文件系统相关的系统调用都是非常微不足道的,文件系统实现的系统调用,如open、read、write、close,需要您将文件转换为相应的fd (文件描述符)。您需要为每个进程添加一个文件表,以跟踪这一点,这可以是预处理数据或全局数据。
case (*p==SYS_WRITE)
{
// printf("wite syscall\n");
char *buffer=*(p+2);
unsigned size=*(p+3);
int fd=*(p+1);
// getiing the fd of specified file
struct file *fil= thread_current()->fdtable[fd];/ my per thread fdtable
if(fd==1) goto here;
if(is_directory(fil->inode)){
exit(-1);
goto done;
}
here:
if(buffer>=PHYS_BASE)exit(-1);
if(fd<0||fd>=128){exit(-1);}
if(fd==0){exit(-1);} // writing to STDIN
if(fd==1) //writing to STDOUT
{
int a=(int)size;
while(a>=100)
{
putbuf(buffer,100);
buffer=buffer+100;
a-=100;
}
putbuf(buffer,a);
f->eax=(int)size;
}
else
if(thread_current()->fdtable[fd]==NULL)
{f->eax=-1;}
else
{
f->eax=file_write(thread_current()->fdtable[fd],buffer,(off_t)size);
}
done: ;
}//printf("write");} /* Write to a file. */Open -将新条目添加到fdtable并返回给文件的fd号u,
close -从fd表中删除该条目
读-类似于写。
process_create、wait实现起来并不简单...
干杯:)
https://stackoverflow.com/questions/12147956
复制相似问题