def print_head(syscall, p, name): formal_args = ", ".join([ "struct thread *td", "struct {name}_args *uap".format(**locals()) ] + (["int lfd"] if find_file_descriptor_argument(syscall) is not None else [])) print_caution(p) p("""\ #include <sys/param.h> #include <sys/errno.h> #include <sys/fcntl.h> #include <sys/libkern.h> #include <sys/proc.h> #include <sys/stat.h> #include <sys/syslog.h> #include <sys/sysproto.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <fsyscall/private.h> #include <fsyscall/private/command.h> #include <fsyscall/private/encode.h> #include <fsyscall/private/fmaster.h> #include <sys/fmaster/fmaster_pre_post.h> #include <sys/fmaster/fmaster_proto.h> static int execute_call({formal_args}) {{ """.format(**locals()))
def print_fslave_head(p, syscall): args = ["struct slave_thread *slave_thread", "int *retval", "int *errnum"] for a in syscall.output_args: args.append(make_formal_arguments_of_execute_call(syscall, a)) name = drop_prefix(syscall.name) print_caution(p) p("""\ #include <sys/types.h> #include <sys/event.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/uio.h> #include <sys/wait.h> #include <errno.h> #include <fcntl.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> #include <fsyscall/private.h> #include <fsyscall/private/command.h> #include <fsyscall/private/encode.h> #include <fsyscall/private/fslave.h> #include <fsyscall/private/io.h> #include <fsyscall/private/io_or_die.h> static void execute_call({args}) {{ """.format(args=", ".join(args)))
def write_proto(dirpath, syscalls): try: mkdir(dirpath) except OSError: pass with open(join(dirpath, "proto.h"), "w") as fp: p, print_newline = partial_print(fp) print_caution(p) p("""\ #if !defined(FSYSCALL_PRIVATE_FSLAVE_PROTO_H_INCLUDED) #define FSYSCALL_PRIVATE_FSLAVE_PROTO_H_INCLUDED """) print_newline() for syscall in syscalls: if syscall.name not in FSLAVE_SYSCALLS: continue p("""\ void process_{name}(struct slave_thread *); """.format(name=drop_prefix(syscall.name))) print_newline() p("""\ #endif """)
def write_pre_post_h(dirpath, syscalls): with open(join(dirpath, "fmaster_pre_post.h"), "w") as fp: p = fp.write print_newline = partial(p, "\n") print_caution(p) p("""\ #include <sys/proc.h> #include <sys/fmaster/fmaster_proto.h> """) print_newline() protos = [] for syscall in [syscall for syscall in syscalls if syscall.pre_execute]: fmt = "enum fmaster_pre_execute_result {name}_pre_execute(struct thread *, struct {name}_args *, int *);\n" protos.append(fmt.format(name=syscall.name)) for syscall in [syscall for syscall in syscalls if syscall.post_execute]: fmt = "int {name}_post_execute(struct thread *, struct {name}_args *);\n" protos.append(fmt.format(name=syscall.name)) for syscall in [syscall for syscall in syscalls if syscall.post_common]: fmt = "int {name}_post_common(struct thread *, struct {name}_args *);\n" protos.append(fmt.format(name=syscall.name)) p("".join(sorted(protos)))