View | Details | Raw Unified | Return to bug 1594
Collapse All | Expand All

(-)a/.hgignore (+1 lines)
 Lines 4-6    Link Here 
4
^objdir/
4
^objdir/
5
^poub
5
^poub
6
^net-next
6
^net-next
7
\.gcno$
(-)a/Makefile (-3 / +8 lines)
 Lines 13-18    Link Here 
13
proc.c seq.c socket.c tasklet-hrtimer.c \
13
proc.c seq.c socket.c tasklet-hrtimer.c \
14
cred.c pid.c modules.c
14
cred.c pid.c modules.c
15
15
16
COV?=no
17
cov_yes=-fprofile-arcs -ftest-coverage
18
cov_no=
19
covl_yes=-fprofile-arcs
20
covl_no=
16
21
17
OPT?=no
22
OPT?=no
18
opt_yes=-O3 -fomit-frame-pointer 
23
opt_yes=-O3 -fomit-frame-pointer 
 Lines 32-38    Link Here 
32
 -include autoconf.h \
37
 -include autoconf.h \
33
 -U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 \
38
 -U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 \
34
 -I$(SRCDIR)sim/include -I$(SRCDIR)$(KERNEL_DIR)/include \
39
 -I$(SRCDIR)sim/include -I$(SRCDIR)$(KERNEL_DIR)/include \
35
 $(PIC_CFLAGS) -D_DEBUG -I$(PWD)
40
 $(PIC_CFLAGS) -D_DEBUG -I$(PWD) $(cov_$(COV))
36
41
37
include $(SRCDIR)processor.mk
42
include $(SRCDIR)processor.mk
38
43
 Lines 40-46    Link Here 
40
CFLAGS+= -DCONFIG_64BIT
45
CFLAGS+= -DCONFIG_64BIT
41
endif
46
endif
42
47
43
LDFLAGS += -shared -nostdlib -g3 -Wl,-O1 -Wl,-Tlinker.lds 
48
LDFLAGS += -shared -nodefaultlibs -g3 -Wl,-O1 -Wl,-Tlinker.lds $(covl_$(COV))
44
49
45
modules:=
50
modules:=
46
all-obj-for-clean:=
51
all-obj-for-clean:=
 Lines 146-149    Link Here 
146
menuconfig:
151
menuconfig:
147
	$(MAKE) -C $(KERNEL_DIR) ARCH=sim menuconfig
152
	$(MAKE) -C $(KERNEL_DIR) ARCH=sim menuconfig
148
153
149
.PHONY : clean
154
.PHONY : clean
(-)a/sim/include/sim-init.h (+15 lines)
 Lines 4-9    Link Here 
4
#include <stdarg.h>
4
#include <stdarg.h>
5
#include <linux/types.h>
5
#include <linux/types.h>
6
#include <linux/socket.h>
6
#include <linux/socket.h>
7
#include <stdio.h>
7
#include "sim-types.h"
8
#include "sim-types.h"
8
9
9
#ifdef __cplusplus
10
#ifdef __cplusplus
 Lines 56-61    Link Here 
56
  void (*free) (struct SimKernel *kernel, void *buffer);
57
  void (*free) (struct SimKernel *kernel, void *buffer);
57
  void *(*memcpy) (struct SimKernel *kernel, void *dst, const void *src, unsigned long size);
58
  void *(*memcpy) (struct SimKernel *kernel, void *dst, const void *src, unsigned long size);
58
  void *(*memset) (struct SimKernel *kernel, void *dst, char value, unsigned long size);
59
  void *(*memset) (struct SimKernel *kernel, void *dst, char value, unsigned long size);
60
  int (*atexit) (struct SimKernel *kernel, void (*function)(void));
61
  int (*access) (struct SimKernel *kernel, const char *pathname, int mode);
62
  char *(*getenv) (struct SimKernel *kernel, const char *name);
63
  int (*mkdir)(struct SimKernel *kernel, const char *pathname, mode_t mode);
64
  int (*open)(struct SimKernel *kernel, const char *pathname, int flags);
65
  int (*__fxstat) (struct SimKernel *kernel, int ver, int fd, void *buf);
66
  int (*fseek)(struct SimKernel *kernel, FILE *stream, long offset, int whence);
67
  void (*setbuf)(struct SimKernel *kernel, FILE *stream, char *buf);
68
  FILE *(*fdopen)(struct SimKernel *kernel, int fd, const char *mode);
69
  long (*ftell)(struct SimKernel *kernel, FILE *stream);
70
  int (*fclose)(struct SimKernel *kernel, FILE *fp);
71
  size_t (*fread)(struct SimKernel *kernel, void *ptr, size_t size, size_t nmemb, FILE *stream);
72
  size_t (*fwrite)(struct SimKernel *kernel, const void *ptr, size_t size, size_t nmemb, FILE *stream);
73
59
  unsigned long (*random) (struct SimKernel *kernel);
74
  unsigned long (*random) (struct SimKernel *kernel);
60
  void *(*event_schedule_ns) (struct SimKernel *kernel, __u64 ns, void (*fn) (void *context), void *context,
75
  void *(*event_schedule_ns) (struct SimKernel *kernel, __u64 ns, void (*fn) (void *context), void *context,
61
			      void (*pre_fn) (void));
76
			      void (*pre_fn) (void));
(-)a/sim/modules.c (-1 / +1 lines)
 Lines 14-19    Link Here 
14
int __request_module(bool wait, const char *fmt, ...)
14
int __request_module(bool wait, const char *fmt, ...)
15
{
15
{
16
  // we really should never be trying to load modules that way.
16
  // we really should never be trying to load modules that way.
17
  sim_assert (false);
17
  // sim_assert (false);
18
  return 0;
18
  return 0;
19
}
19
}
(-)a/sim/proc.c (+4 lines)
 Lines 33-38    Link Here 
33
{
33
{
34
  // insert new entry at head of subdir list in parent
34
  // insert new entry at head of subdir list in parent
35
  struct proc_dir_entry * child = kzalloc (sizeof(struct proc_dir_entry), GFP_KERNEL);
35
  struct proc_dir_entry * child = kzalloc (sizeof(struct proc_dir_entry), GFP_KERNEL);
36
  if (!child)
37
    {
38
      return NULL;
39
    }
36
  child->name = kstrdup (name, GFP_KERNEL);
40
  child->name = kstrdup (name, GFP_KERNEL);
37
  child->namelen = strlen (name);
41
  child->namelen = strlen (name);
38
  child->parent = parent;
42
  child->parent = parent;
(-)a/sim/sched.c (+6 lines)
 Lines 22-33    Link Here 
22
struct SimTask *sim_task_create (void *private, unsigned long pid)
22
struct SimTask *sim_task_create (void *private, unsigned long pid)
23
{
23
{
24
  struct SimTask *task = sim_malloc (sizeof (struct SimTask));
24
  struct SimTask *task = sim_malloc (sizeof (struct SimTask));
25
  if (!task) return NULL;
25
  struct cred *cred = sim_malloc (sizeof (struct cred));
26
  struct cred *cred = sim_malloc (sizeof (struct cred));
27
  if (!cred) return NULL;
26
  // XXX: we could optimize away this allocation by sharing it for all tasks
28
  // XXX: we could optimize away this allocation by sharing it for all tasks
27
  struct nsproxy *ns = sim_malloc (sizeof (struct nsproxy));
29
  struct nsproxy *ns = sim_malloc (sizeof (struct nsproxy));
30
  if (!ns) return NULL;
28
  struct user_struct *user = sim_malloc (sizeof (struct user_struct));
31
  struct user_struct *user = sim_malloc (sizeof (struct user_struct));
32
  if (!user) return NULL;
29
  struct thread_info *info = alloc_thread_info (&task->kernel_task);
33
  struct thread_info *info = alloc_thread_info (&task->kernel_task);
34
  if (!info) return NULL;
30
  struct pid *kpid = sim_malloc (sizeof (struct pid));
35
  struct pid *kpid = sim_malloc (sizeof (struct pid));
36
  if (!kpid) return NULL;
31
  kpid->numbers[0].nr = pid;
37
  kpid->numbers[0].nr = pid;
32
  user->user_ns = 0;
38
  user->user_ns = 0;
33
  cred->fsuid = 0;
39
  cred->fsuid = 0;
(-)a/sim/sim-socket.c (+10 lines)
 Lines 16-21    Link Here 
16
{
16
{
17
  int size = sizeof (struct iovec) * len;
17
  int size = sizeof (struct iovec) * len;
18
  struct iovec *output = sim_malloc (size);
18
  struct iovec *output = sim_malloc (size);
19
  if (!output)
20
    return NULL;
19
  sim_memcpy (output, input, size);
21
  sim_memcpy (output, input, size);
20
  return output;
22
  return output;
21
}
23
}
 Lines 189-194    Link Here 
189
{
191
{
190
  struct socket *sock = (struct socket *)socket;
192
  struct socket *sock = (struct socket *)socket;
191
  wait_queue_t *wait = ( wait_queue_t * ) sim_malloc (sizeof(wait_queue_t));
193
  wait_queue_t *wait = ( wait_queue_t * ) sim_malloc (sizeof(wait_queue_t));
194
  if (!wait)
195
    return NULL;
192
196
193
  wait->func = sim_wake_function;
197
  wait->func = sim_wake_function;
194
  wait->private = context;
198
  wait->private = context;
 Lines 298-303    Link Here 
298
      ( struct sim_ptable_entry * ) sim_malloc (sizeof(struct sim_ptable_entry));
302
      ( struct sim_ptable_entry * ) sim_malloc (sizeof(struct sim_ptable_entry));
299
  struct poll_table_ref *fromDCE =  (struct poll_table_ref *) pwq->table;
303
  struct poll_table_ref *fromDCE =  (struct poll_table_ref *) pwq->table;
300
304
305
  if (!entry)
306
    return;
307
301
  entry->opaque = fromDCE->opaque; // Copy DCE poll table reference
308
  entry->opaque = fromDCE->opaque; // Copy DCE poll table reference
302
  entry->eventMask = fromDCE->ret; // Copy poll mask of wanted events.
309
  entry->eventMask = fromDCE->ret; // Copy poll mask of wanted events.
303
310
 Lines 333-338    Link Here 
333
  if ( ret->opaque )
340
  if ( ret->opaque )
334
    {
341
    {
335
      ptable = (struct poll_wqueues *)sim_malloc (sizeof(struct poll_wqueues));
342
      ptable = (struct poll_wqueues *)sim_malloc (sizeof(struct poll_wqueues));
343
      if (!ptable)
344
        return;
345
336
      dce_poll_initwait(ptable);
346
      dce_poll_initwait(ptable);
337
347
338
      pwait = &(ptable->pt);
348
      pwait = &(ptable->pt);
(-)a/sim/sim.c (+86 lines)
 Lines 1-6    Link Here 
1
#include <linux/init.h> // initcall_t
1
#include <linux/init.h> // initcall_t
2
#include <linux/kernel.h> // SYSTEM_BOOTING
2
#include <linux/kernel.h> // SYSTEM_BOOTING
3
#include <linux/sched.h> // struct task_struct
3
#include <linux/sched.h> // struct task_struct
4
#include <stdio.h>
4
#include "sim-init.h"
5
#include "sim-init.h"
5
#include "sim.h"
6
#include "sim.h"
6
7
 Lines 113-118    Link Here 
113
114
114
static struct SimKernel *g_kernel;
115
static struct SimKernel *g_kernel;
115
116
117
118
static int num_handler = 0;
119
void *atexit_list[1024];
120
116
void sim_init (struct SimExported *exported, const struct SimImported *imported, struct SimKernel *kernel)
121
void sim_init (struct SimExported *exported, const struct SimImported *imported, struct SimKernel *kernel)
117
{
122
{
118
  // make sure we can call the callbacks
123
  // make sure we can call the callbacks
 Lines 172-177    Link Here 
172
177
173
  // finally, put the system in RUNNING state.
178
  // finally, put the system in RUNNING state.
174
  system_state = SYSTEM_RUNNING;
179
  system_state = SYSTEM_RUNNING;
180
181
  /* XXX handle atexit registration for gcov */
182
  int i;
183
  for (i = 0; i < 1024; i++)
184
    {
185
      if (atexit_list [i])
186
        g_imported.atexit (g_kernel, (void (*)(void))atexit_list[i]);
187
    }
188
175
}
189
}
176
190
177
191
 Lines 195-200    Link Here 
195
{
209
{
196
  return g_imported.memset (g_kernel, dst, value, size);
210
  return g_imported.memset (g_kernel, dst, value, size);
197
}
211
}
212
int atexit (void (*function)(void))
213
{
214
  if (g_imported.atexit == 0)
215
    {
216
      atexit_list[num_handler++] = function;
217
      return 0;
218
    }
219
  else
220
    {
221
      return g_imported.atexit (g_kernel, function);
222
    }
223
}
224
int access (const char *pathname, int mode)
225
{
226
  return g_imported.access (g_kernel, pathname, mode);
227
}
228
char *getenv (const char *name)
229
{
230
  return g_imported.getenv (g_kernel, name);
231
}
232
pid_t getpid(void)
233
{
234
  return (pid_t)0;
235
}
236
int mkdir(const char *pathname, mode_t mode)
237
{
238
  return g_imported.mkdir (g_kernel, pathname, mode);
239
}
240
int open(const char *pathname, int flags)
241
{
242
  return g_imported.open (g_kernel, pathname, flags);
243
}
244
int fcntl(int fd, int cmd, ... /* arg */ )
245
{
246
  return 0;
247
}
248
int __fxstat (int ver, int fd, void *buf)
249
{
250
  return g_imported.__fxstat (g_kernel, ver, fd, buf);
251
}
252
int fseek(FILE *stream, long offset, int whence)
253
{
254
  return g_imported.fseek (g_kernel, stream, offset, whence);
255
}
256
long ftell(FILE *stream)
257
{
258
  return g_imported.ftell (g_kernel, stream);
259
}
260
void setbuf(FILE *stream, char *buf)
261
{
262
  return g_imported.setbuf (g_kernel, stream, buf);
263
}
264
FILE *fdopen(int fd, const char *mode)
265
{
266
  return g_imported.fdopen (g_kernel, fd, mode);
267
}
268
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
269
{
270
  return g_imported.fread (g_kernel, ptr, size, nmemb, stream);
271
}
272
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
273
{
274
  return g_imported.fwrite (g_kernel, ptr, size, nmemb, stream);
275
}
276
int fclose(FILE *fp)
277
{
278
  return g_imported.fclose (g_kernel, fp);
279
}
198
unsigned long sim_random (void)
280
unsigned long sim_random (void)
199
{
281
{
200
  return g_imported.random (g_kernel);
282
  return g_imported.random (g_kernel);
 Lines 230-235    Link Here 
230
struct SimTask *sim_task_start (void (*callback) (void *), void *context)
312
struct SimTask *sim_task_start (void (*callback) (void *), void *context)
231
{
313
{
232
  struct SimTaskTrampolineContext *ctx = sim_malloc (sizeof (struct SimTaskTrampolineContext));
314
  struct SimTaskTrampolineContext *ctx = sim_malloc (sizeof (struct SimTaskTrampolineContext));
315
  if (!ctx)
316
    {
317
      return NULL;
318
    }
233
  ctx->callback = callback;
319
  ctx->callback = callback;
234
  ctx->context = context;
320
  ctx->context = context;
235
  return g_imported.task_start (g_kernel, &sim_task_start_trampoline, ctx);
321
  return g_imported.task_start (g_kernel, &sim_task_start_trampoline, ctx);
(-)a/sim/slab.c (+8 lines)
 Lines 22-27    Link Here 
22
void *__kmalloc(size_t size, gfp_t flags)
22
void *__kmalloc(size_t size, gfp_t flags)
23
{
23
{
24
  void *p = sim_malloc (size + sizeof (size));
24
  void *p = sim_malloc (size + sizeof (size));
25
  if (!p)
26
    {
27
      return NULL;
28
    }
25
29
26
  if (p != 0 && (flags & __GFP_ZERO))
30
  if (p != 0 && (flags & __GFP_ZERO))
27
    {
31
    {
 Lines 54-59    Link Here 
54
		  unsigned long flags, void (*ctor)(void *))
58
		  unsigned long flags, void (*ctor)(void *))
55
{
59
{
56
  struct kmem_cache *cache = kmalloc (sizeof (struct kmem_cache), flags);
60
  struct kmem_cache *cache = kmalloc (sizeof (struct kmem_cache), flags);
61
  if (!cache)
62
    {
63
      return NULL;
64
    }
57
  cache->name = name;
65
  cache->name = name;
58
  cache->size = size;
66
  cache->size = size;
59
  cache->align = align;
67
  cache->align = align;

Return to bug 1594