Skip to content

Commit 8c33c01

Browse files
committed
Better patch
1 parent fc0989b commit 8c33c01

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
diff --git a/cbits/symbols.c b/cbits/symbols.c
2+
new file mode 100644
3+
index 0000000..d447895
4+
--- /dev/null
5+
+++ b/cbits/symbols.c
6+
@@ -0,0 +1,147 @@
7+
+#include <stddef.h>
8+
+#include <stdio.h>
9+
+#include <string.h>
10+
+#include <stdlib.h>
11+
+#include <signal.h>
12+
+#include <assert.h>
13+
+#include <math.h>
14+
+#include <errno.h>
15+
+#include <unistd.h>
16+
+#include <sys/stat.h>
17+
+#include <sys/wait.h>
18+
+#include <sys/epoll.h>
19+
+// #include <sys/eventfd.h>
20+
+// #include <fcntl.h> // this includes too many overloaded items.
21+
+#include <string.h>
22+
+#include <ctype.h>
23+
+#include <wchar.h>
24+
+#include <utime.h>
25+
+#include <poll.h>
26+
+#include <time.h>
27+
+
28+
+// fnctl stubs, see above
29+
+extern void open(void);
30+
+extern void creat(void);
31+
+extern void eventfd(void);
32+
+extern void eventfd_write(void);
33+
+extern void __stack_chk_fail(void);
34+
+
35+
+typedef void SymbolAddr;
36+
+typedef char SymbolName;
37+
+
38+
+typedef enum _SymStrength {
39+
+ STRENGTH_NORMAL,
40+
+ STRENGTH_WEAK,
41+
+ STRENGTH_STRONG,
42+
+} SymStrength;
43+
+
44+
+typedef enum _SymType {
45+
+ SYM_TYPE_CODE = 1 << 0, /* the symbol is a function and can be relocated via a jump island */
46+
+ SYM_TYPE_DATA = 1 << 1, /* the symbol is data */
47+
+ SYM_TYPE_INDIRECT_DATA = 1 << 2, /* see Note [_iob_func symbol] */
48+
+ SYM_TYPE_DUP_DISCARD = 1 << 3, /* the symbol is a symbol in a BFD import library
49+
+ however if a duplicate is found with a mismatching
50+
+ SymType then discard this one. */
51+
+} SymType;
52+
+
53+
+typedef struct _RtsSymbolVal {
54+
+ const SymbolName* lbl;
55+
+ SymbolAddr* addr;
56+
+ SymStrength strength;
57+
+ SymType type;
58+
+} RtsSymbolVal;
59+
+
60+
+#define SYM(x) { #x, (void*)(&x), STRENGTH_NORMAL, 1 }
61+
+typedef mode_t (*umask_func_ptr_t)(mode_t);
62+
+
63+
+RtsSymbolVal my_iserv_syms[] = {
64+
+ // time.h
65+
+ SYM(clock),
66+
+ // sys/time.h
67+
+ SYM(gettimeofday),SYM(clock_getres),SYM(clock_gettime),SYM(localtime_r),SYM(tzset),
68+
+ // unistd.h
69+
+ SYM(environ),
70+
+ SYM(ftruncate),
71+
+ SYM(getenv),
72+
+ SYM(putenv),
73+
+ SYM(unsetenv),
74+
+ SYM(read),
75+
+ SYM(write),
76+
+ SYM(isatty),
77+
+ SYM(link),
78+
+ SYM(pipe),
79+
+ SYM(unlink),
80+
+ // errno.h
81+
+ SYM(__errno),
82+
+ // math.h
83+
+ SYM(sinhf), SYM(sinh), SYM(sinf), SYM(sin),
84+
+ SYM(coshf), SYM(cosh), SYM(cosf), SYM(cos),
85+
+ SYM(atanhf), SYM(atanh), SYM(atanf), SYM(atan),
86+
+ SYM(asinhf), SYM(asinh), SYM(asinf), SYM(asin),
87+
+ SYM(acoshf), SYM(acosh), SYM(acosf), SYM(acos),
88+
+ SYM(log1pf), SYM(log1p), SYM(logf), SYM(log),
89+
+ SYM(expm1f), SYM(expm1),
90+
+ SYM(expf), SYM(exp),
91+
+ SYM(ldexp),
92+
+ SYM(powf), SYM(pow),
93+
+ SYM(sqrtf), SYM(sqrt),
94+
+ SYM(tanhf), SYM(tanh), SYM(tanf), SYM(tan),
95+
+ // assert.h
96+
+ SYM(__assert2),
97+
+ // signal.h
98+
+ SYM(raise), SYM(sigaddset), SYM(sigemptyset), SYM(sigprocmask),
99+
+ // sys/eventfd.h
100+
+ SYM(eventfd), SYM(eventfd_write),
101+
+ // sys/stat.h
102+
+ SYM(fstat),
103+
+ SYM(lstat),
104+
+ SYM(stat),
105+
+ SYM(chmod),
106+
+ SYM(mkfifo),
107+
+ // SYM(umask),
108+
+ { "umask", (umask_func_ptr_t)(&umask), STRENGTH_NORMAL, 1 },
109+
+ // sys/wait.h
110+
+ SYM(waitpid),
111+
+ // sym/epoll.h
112+
+ SYM(epoll_create), SYM(epoll_ctl), SYM(epoll_wait),
113+
+ // poll.h
114+
+ SYM(poll),
115+
+ // fcntl.h
116+
+ SYM(open), SYM(creat), SYM(fcntl), SYM(ioctl),
117+
+ // string.h
118+
+ SYM(strerror),
119+
+ SYM(strcmp),
120+
+ SYM(memchr),
121+
+ // ctype.h
122+
+ SYM(__ctype_get_mb_cur_max),
123+
+ // wchar.h
124+
+ SYM(mbrtowc), SYM(wcrtomb),
125+
+ // stdlib.h
126+
+ SYM(qsort),
127+
+ // unistd.h
128+
+ SYM(access), SYM(close), SYM(dup), SYM(dup2), SYM(fork), SYM(getpid),
129+
+ SYM(lseek),
130+
+ // utime.h
131+
+ SYM(utime),
132+
+ // ...
133+
+ SYM(__stack_chk_fail),
134+
+ SYM(memmove),
135+
+ SYM(memcmp),
136+
+ SYM(memcpy),
137+
+ SYM(memset),
138+
+ SYM(stderr),
139+
+ SYM(realloc),
140+
+ SYM(calloc),
141+
+ SYM(malloc),
142+
+ SYM(free),
143+
+ SYM(fprintf),
144+
+ SYM(fopen), SYM(fclose),
145+
+ SYM(fread),
146+
+ SYM(abort),
147+
+ SYM(strlen),
148+
+ { 0, 0, STRENGTH_NORMAL, 1 } /* sentinel */
149+
+};
150+
+
151+
+RtsSymbolVal* iserv_syms() {
152+
+ return my_iserv_syms;
153+
+}
154+
\ No newline at end of file
155+
diff --git a/iserv-proxy.cabal b/iserv-proxy.cabal
156+
index a0eeaeb..a146108 100644
157+
--- a/iserv-proxy.cabal
158+
+++ b/iserv-proxy.cabal
159+
@@ -101,6 +101,7 @@ Executable iserv-proxy
160+
Executable iserv-proxy-interpreter
161+
Default-Language: Haskell2010
162+
Main-Is: Interpreter.hs
163+
+ c-sources: cbits/symbols.c
164+
Build-Depends: base >= 4 && < 5,
165+
iserv-proxy
166+

0 commit comments

Comments
 (0)