-
Notifications
You must be signed in to change notification settings - Fork 19
/
sim.c
112 lines (102 loc) · 2.43 KB
/
sim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* network simulator backend for library version of Linux kernel
* Copyright (c) 2015 INRIA, Hajime Tazaki
*
* Author: Mathieu Lacage <[email protected]>
* Hajime Tazaki <[email protected]>
*/
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <asm/types.h>
#include "sim-init.h"
#include "sim.h"
FILE *stderr = NULL;
extern struct SimImported g_imported;
extern struct SimKernel *g_kernel;
static int num_handler = 0;
void *atexit_list[1024];
extern void lib_init(struct SimExported *exported,
const struct SimImported *imported,
struct SimKernel *kernel);
void sim_init(struct SimExported *exported, const struct SimImported *imported,
struct SimKernel *kernel)
{
int i;
lib_init(exported, imported, kernel);
/* XXX handle atexit registration for gcov */
for (i = 0; i < 1024; i++) {
if (atexit_list[i]) {
g_imported.atexit(g_kernel,
(void (*)(void))atexit_list[i]);
}
}
}
int fclose(FILE *fp)
{
return g_imported.fclose(g_kernel, fp);
}
char *getenv(const char *name)
{
return g_imported.getenv(g_kernel, name);
}
int access(const char *pathname, int mode)
{
return g_imported.access(g_kernel, pathname, mode);
}
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);
}
}
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);
}