提交 5ca8b8e0 创建 作者: Austin Clements's avatar Austin Clements

Automatically generate user space syscall prototypes

Any instances of userptr<T> in the kernel syscall prototypes are translated to regular pointers for the user space prototypes. Also, this requires marking sys_exit's magic syscall comment with a new flag to indicate it does not return.
上级 203de796
......@@ -28,7 +28,7 @@ NM = $(TOOLPREFIX)nm
OBJCOPY = $(TOOLPREFIX)objcopy
STRIP = $(TOOLPREFIX)strip
INCLUDES = -iquote include -Istdinc -I$(QEMUSRC) -include param.h -include include/compiler.h
INCLUDES = -iquote include -iquote$(O)/include -Istdinc -I$(QEMUSRC) -include param.h -include include/compiler.h
COMFLAGS = -static -g -MD -m64 -O3 -Wall -Werror -DHW_$(HW) -DXV6 \
-fno-builtin -fno-strict-aliasing -fno-omit-frame-pointer -fms-extensions \
-mno-sse -mcx16 -mno-red-zone $(INCLUDES)
......
......@@ -57,5 +57,7 @@ $(O)/bin/%: $(O)/bin/%.unstripped
$(Q)mkdir -p $(@D)
$(Q)$(STRIP) -o $@ $<
$(addsuffix .o,$(UPROGS)): $(O)/include/sysstubs.h
.PRECIOUS: $(O)/bin/%.o $(O)/bin/%.unstripped
-include $(O)/bin/*.d
......@@ -2,40 +2,9 @@
BEGIN_DECLS
struct stat;
struct ipcmsg;
struct sockaddr;
// system calls
int fork(int);
int exit(void) __attribute__((noreturn));
int wait(void);
int pipe(int*);
ssize_t write(int, const void*, size_t);
ssize_t read(int, void*, size_t);
int close(int);
int kill(int);
int exec(const char*, const char**);
int openat(int dirfd, const char *pathname, int omode);
int mknod(const char*, int, int);
int unlink(const char*);
int fstat(int fd, struct stat*);
int link(const char*, const char*);
int mkdir(const char*);
int mkdirat(int dirfd, const char *pathname);
int chdir(const char*);
int dup(int);
int getpid(void);
char* sbrk(int);
int nsleep(u64);
u64 uptime(void);
int map(void *addr, size_t len);
int unmap(void *addr, size_t len);
int halt(void);
ssize_t pread(int, void*, size_t, off_t);
int async(int, size_t, off_t, int, int);
int script(void *addr, u64 len, u64 chunk);
int setfs(u64 base);
int setaffinity(int cpu);
long futex(const u64* addr, int op, u64 val, u64 timer);
#include "sysstubs.h"
// ulib.c
int stat(char*, struct stat*);
......@@ -48,6 +17,7 @@ char* strchr(const char*, char c);
int strcmp(const char*, const char*);
int strncmp(const char *p, const char *q, size_t n);
int open(const char*, int);
int mkdir(const char*);
char* gets(char*, int max);
unsigned int strlen(const char*);
......
......@@ -20,7 +20,7 @@ sys_fork(int flags)
return fork(flags);
}
//SYSCALL
//SYSCALL NORET
int
sys_exit(void)
{
......
......@@ -10,5 +10,10 @@ $(O)/lib/sysstubs.S: tools/syscalls.py kernel/*.cc
$(Q)mkdir -p $(@D)
$(Q)python $^ --ustubs > $@
$(O)/include/sysstubs.h: tools/syscalls.py kernel/*.cc
@echo " GEN $@"
$(Q)mkdir -p $(@D)
$(Q)python $^ --udecls > $@
.PRECIOUS: $(O)/lib/%.o
-include $(O)/lib/*.d
......@@ -14,8 +14,6 @@ static std::atomic<int> nextid;
static wq *wq_;
extern "C" long wqwait(void);
static void __attribute__((used))
initworker(void)
{
......
......@@ -7,6 +7,8 @@ def main():
help="output kernel syscall vectors")
parser.add_option("--ustubs", action="store_true",
help="output user syscall stubs")
parser.add_option("--udecls", action="store_true",
help="output user syscall declarations")
(options, args) = parser.parse_args()
if len(args) < 1:
......@@ -59,6 +61,14 @@ def main():
print " ret"
print
if options.udecls:
for syscall in syscalls:
extra = ""
if "NORET" in syscall.flags:
extra = " __attribute__((noreturn))"
print "%s %s(%s)%s;" % (syscall.rettype, syscall.uname,
", ".join(syscall.uargs), extra)
class Syscall(object):
def __init__(self, kname, rettype, kargs, flags, num=None):
self.kname, self.rettype, self.kargs, self.flags, self.num = \
......@@ -68,6 +78,17 @@ class Syscall(object):
# Construct user space prototype
self.uname = self.basename
uargs = []
for karg in kargs:
m = re.match("(.*?) *[a-z_]+$", karg)
atype = m.group(1)
while True:
atype2 = re.sub("userptr<(.*)>", r"\1*", atype)
if atype2 == atype:
break
atype = atype2
uargs.append(atype)
self.uargs = uargs
def __repr__(self):
return "Syscall(%r,%r,%r,%r,%r)" % (
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论