diff -r 0f845b1aee21 .hgignore --- a/.hgignore Thu Nov 01 09:08:04 2012 +0900 +++ b/.hgignore Fri Jan 04 17:45:40 2013 +0900 @@ -4,3 +4,4 @@ ^objdir/ ^poub ^net-next +\.gcno$ diff -r 0f845b1aee21 Makefile --- a/Makefile Thu Nov 01 09:08:04 2012 +0900 +++ b/Makefile Fri Jan 04 17:45:40 2013 +0900 @@ -13,6 +13,11 @@ proc.c seq.c socket.c tasklet-hrtimer.c \ cred.c pid.c modules.c +COV?=no +cov_yes=-fprofile-arcs -ftest-coverage +cov_no= +covl_yes=-fprofile-arcs +covl_no= OPT?=no opt_yes=-O3 -fomit-frame-pointer @@ -32,7 +37,7 @@ -include autoconf.h \ -U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 \ -I$(SRCDIR)sim/include -I$(SRCDIR)$(KERNEL_DIR)/include \ - $(PIC_CFLAGS) -D_DEBUG -I$(PWD) + $(PIC_CFLAGS) -D_DEBUG -I$(PWD) $(cov_$(COV)) include $(SRCDIR)processor.mk @@ -40,7 +45,7 @@ CFLAGS+= -DCONFIG_64BIT endif -LDFLAGS += -shared -nostdlib -g3 -Wl,-O1 -Wl,-Tlinker.lds +LDFLAGS += -shared -nodefaultlibs -g3 -Wl,-O1 -Wl,-Tlinker.lds $(covl_$(COV)) modules:= all-obj-for-clean:= @@ -146,4 +151,4 @@ menuconfig: $(MAKE) -C $(KERNEL_DIR) ARCH=sim menuconfig -.PHONY : clean \ No newline at end of file +.PHONY : clean diff -r 0f845b1aee21 sim/include/sim-init.h --- a/sim/include/sim-init.h Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/include/sim-init.h Fri Jan 04 17:45:40 2013 +0900 @@ -4,6 +4,7 @@ #include #include #include +#include #include "sim-types.h" #ifdef __cplusplus @@ -56,6 +57,20 @@ void (*free) (struct SimKernel *kernel, void *buffer); void *(*memcpy) (struct SimKernel *kernel, void *dst, const void *src, unsigned long size); void *(*memset) (struct SimKernel *kernel, void *dst, char value, unsigned long size); + int (*atexit) (struct SimKernel *kernel, void (*function)(void)); + int (*access) (struct SimKernel *kernel, const char *pathname, int mode); + char *(*getenv) (struct SimKernel *kernel, const char *name); + int (*mkdir)(struct SimKernel *kernel, const char *pathname, mode_t mode); + int (*open)(struct SimKernel *kernel, const char *pathname, int flags); + int (*__fxstat) (struct SimKernel *kernel, int ver, int fd, void *buf); + int (*fseek)(struct SimKernel *kernel, FILE *stream, long offset, int whence); + void (*setbuf)(struct SimKernel *kernel, FILE *stream, char *buf); + FILE *(*fdopen)(struct SimKernel *kernel, int fd, const char *mode); + long (*ftell)(struct SimKernel *kernel, FILE *stream); + int (*fclose)(struct SimKernel *kernel, FILE *fp); + size_t (*fread)(struct SimKernel *kernel, void *ptr, size_t size, size_t nmemb, FILE *stream); + size_t (*fwrite)(struct SimKernel *kernel, const void *ptr, size_t size, size_t nmemb, FILE *stream); + unsigned long (*random) (struct SimKernel *kernel); void *(*event_schedule_ns) (struct SimKernel *kernel, __u64 ns, void (*fn) (void *context), void *context, void (*pre_fn) (void)); diff -r 0f845b1aee21 sim/modules.c --- a/sim/modules.c Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/modules.c Fri Jan 04 17:45:40 2013 +0900 @@ -14,6 +14,6 @@ int __request_module(bool wait, const char *fmt, ...) { // we really should never be trying to load modules that way. - sim_assert (false); + // sim_assert (false); return 0; } diff -r 0f845b1aee21 sim/proc.c --- a/sim/proc.c Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/proc.c Fri Jan 04 17:45:40 2013 +0900 @@ -33,6 +33,10 @@ { // insert new entry at head of subdir list in parent struct proc_dir_entry * child = kzalloc (sizeof(struct proc_dir_entry), GFP_KERNEL); + if (!child) + { + return NULL; + } child->name = kstrdup (name, GFP_KERNEL); child->namelen = strlen (name); child->parent = parent; diff -r 0f845b1aee21 sim/sched.c --- a/sim/sched.c Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/sched.c Fri Jan 04 17:45:40 2013 +0900 @@ -22,12 +22,18 @@ struct SimTask *sim_task_create (void *private, unsigned long pid) { struct SimTask *task = sim_malloc (sizeof (struct SimTask)); + if (!task) return NULL; struct cred *cred = sim_malloc (sizeof (struct cred)); + if (!cred) return NULL; // XXX: we could optimize away this allocation by sharing it for all tasks struct nsproxy *ns = sim_malloc (sizeof (struct nsproxy)); + if (!ns) return NULL; struct user_struct *user = sim_malloc (sizeof (struct user_struct)); + if (!user) return NULL; struct thread_info *info = alloc_thread_info (&task->kernel_task); + if (!info) return NULL; struct pid *kpid = sim_malloc (sizeof (struct pid)); + if (!kpid) return NULL; kpid->numbers[0].nr = pid; user->user_ns = 0; cred->fsuid = 0; diff -r 0f845b1aee21 sim/sim-socket.c --- a/sim/sim-socket.c Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/sim-socket.c Fri Jan 04 17:45:40 2013 +0900 @@ -16,6 +16,8 @@ { int size = sizeof (struct iovec) * len; struct iovec *output = sim_malloc (size); + if (!output) + return NULL; sim_memcpy (output, input, size); return output; } @@ -189,6 +191,8 @@ { struct socket *sock = (struct socket *)socket; wait_queue_t *wait = ( wait_queue_t * ) sim_malloc (sizeof(wait_queue_t)); + if (!wait) + return NULL; wait->func = sim_wake_function; wait->private = context; @@ -298,6 +302,9 @@ ( struct sim_ptable_entry * ) sim_malloc (sizeof(struct sim_ptable_entry)); struct poll_table_ref *fromDCE = (struct poll_table_ref *) pwq->table; + if (!entry) + return; + entry->opaque = fromDCE->opaque; // Copy DCE poll table reference entry->eventMask = fromDCE->ret; // Copy poll mask of wanted events. @@ -333,6 +340,9 @@ if ( ret->opaque ) { ptable = (struct poll_wqueues *)sim_malloc (sizeof(struct poll_wqueues)); + if (!ptable) + return; + dce_poll_initwait(ptable); pwait = &(ptable->pt); diff -r 0f845b1aee21 sim/sim.c --- a/sim/sim.c Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/sim.c Fri Jan 04 17:45:40 2013 +0900 @@ -1,6 +1,7 @@ #include // initcall_t #include // SYSTEM_BOOTING #include // struct task_struct +#include #include "sim-init.h" #include "sim.h" @@ -113,6 +114,10 @@ static struct SimKernel *g_kernel; + +static int num_handler = 0; +void *atexit_list[1024]; + void sim_init (struct SimExported *exported, const struct SimImported *imported, struct SimKernel *kernel) { // make sure we can call the callbacks @@ -172,6 +177,15 @@ // finally, put the system in RUNNING state. system_state = SYSTEM_RUNNING; + + /* XXX handle atexit registration for gcov */ + int i; + for (i = 0; i < 1024; i++) + { + if (atexit_list [i]) + g_imported.atexit (g_kernel, (void (*)(void))atexit_list[i]); + } + } @@ -195,6 +209,74 @@ { return g_imported.memset (g_kernel, dst, value, size); } +int atexit (void (*function)(void)) +{ + if (g_imported.atexit == 0) + { + atexit_list[num_handler++] = function; + return 0; + } + else + { + return g_imported.atexit (g_kernel, function); + } +} +int access (const char *pathname, int mode) +{ + return g_imported.access (g_kernel, pathname, mode); +} +char *getenv (const char *name) +{ + return g_imported.getenv (g_kernel, name); +} +pid_t getpid(void) +{ + return (pid_t)0; +} +int mkdir(const char *pathname, mode_t mode) +{ + return g_imported.mkdir (g_kernel, pathname, mode); +} +int open(const char *pathname, int flags) +{ + return g_imported.open (g_kernel, pathname, flags); +} +int fcntl(int fd, int cmd, ... /* arg */ ) +{ + return 0; +} +int __fxstat (int ver, int fd, void *buf) +{ + return g_imported.__fxstat (g_kernel, ver, fd, buf); +} +int fseek(FILE *stream, long offset, int whence) +{ + return g_imported.fseek (g_kernel, stream, offset, whence); +} +long ftell(FILE *stream) +{ + return g_imported.ftell (g_kernel, stream); +} +void setbuf(FILE *stream, char *buf) +{ + return g_imported.setbuf (g_kernel, stream, buf); +} +FILE *fdopen(int fd, const char *mode) +{ + return g_imported.fdopen (g_kernel, fd, mode); +} +size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + return g_imported.fread (g_kernel, ptr, size, nmemb, stream); +} +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + return g_imported.fwrite (g_kernel, ptr, size, nmemb, stream); +} +int fclose(FILE *fp) +{ + return g_imported.fclose (g_kernel, fp); +} unsigned long sim_random (void) { return g_imported.random (g_kernel); @@ -230,6 +312,10 @@ struct SimTask *sim_task_start (void (*callback) (void *), void *context) { struct SimTaskTrampolineContext *ctx = sim_malloc (sizeof (struct SimTaskTrampolineContext)); + if (!ctx) + { + return NULL; + } ctx->callback = callback; ctx->context = context; return g_imported.task_start (g_kernel, &sim_task_start_trampoline, ctx); diff -r 0f845b1aee21 sim/slab.c --- a/sim/slab.c Thu Nov 01 09:08:04 2012 +0900 +++ b/sim/slab.c Fri Jan 04 17:45:40 2013 +0900 @@ -22,6 +22,10 @@ void *__kmalloc(size_t size, gfp_t flags) { void *p = sim_malloc (size + sizeof (size)); + if (!p) + { + return NULL; + } if (p != 0 && (flags & __GFP_ZERO)) { @@ -54,6 +58,10 @@ unsigned long flags, void (*ctor)(void *)) { struct kmem_cache *cache = kmalloc (sizeof (struct kmem_cache), flags); + if (!cache) + { + return NULL; + } cache->name = name; cache->size = size; cache->align = align;