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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
New wrapper files for network related functions. These are separated so
that they can be easily overridden when SOCKS support is desired.
--- m3/m3core/src/runtime/FreeBSD2/accept.c.orig Thu Oct 24 13:11:22 1996
+++ m3/m3core/src/runtime/FreeBSD2/accept.c Thu Oct 24 12:47:29 1996
@@ -0,0 +1,16 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_accept(int s, struct sockaddr *addr, int *addrlen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(addr);
+ MAKE_WRITABLE(addrlen);
+ result = accept(s, addr, addrlen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/bind.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/bind.c Thu Oct 24 12:48:12 1996
@@ -0,0 +1,15 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_bind(int s, const struct sockaddr *name, int namelen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(name);
+ result = bind(s, name, namelen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/close.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/close.c Thu Oct 24 12:48:51 1996
@@ -0,0 +1,13 @@
+#include "wrap.h"
+#include <unistd.h>
+
+int
+m3_close(int d)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ result = close(d);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/connect.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/connect.c Thu Oct 24 12:49:40 1996
@@ -0,0 +1,15 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_connect(int s, const struct sockaddr *name, int namelen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(name);
+ result = connect(s, name, namelen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/dup.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/dup.c Thu Oct 24 12:50:09 1996
@@ -0,0 +1,13 @@
+#include "wrap.h"
+#include <unistd.h>
+
+int
+m3_dup(int oldd)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ result = dup(oldd);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/dup2.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/dup2.c Thu Oct 24 12:50:28 1996
@@ -0,0 +1,13 @@
+#include "wrap.h"
+#include <unistd.h>
+
+int
+m3_dup2(int oldd, int newd)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ result = dup2(oldd, newd);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/gethostbyaddr.c.orig Thu Oct 24 16:07:10 1996
+++ m3/m3core/src/runtime/FreeBSD2/gethostbyaddr.c Thu Oct 24 16:10:19 1996
@@ -0,0 +1,14 @@
+#include "wrap.h"
+#include <netdb.h>
+
+struct hostent *
+m3_gethostbyaddr(const char *addr, int len, int type)
+{
+ struct hostent *result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(addr);
+ result = gethostbyaddr(addr, len, type);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/gethostbyname.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/gethostbyname.c Thu Oct 24 16:08:41 1996
@@ -0,0 +1,14 @@
+#include "wrap.h"
+#include <netdb.h>
+
+struct hostent *
+m3_gethostbyname(const char *name)
+{
+ struct hostent *result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(name);
+ result = gethostbyname(name);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/getpeername.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/getpeername.c Thu Oct 24 12:52:25 1996
@@ -0,0 +1,16 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_getpeername(int s, struct sockaddr *name, int *namelen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(name);
+ MAKE_WRITABLE(namelen);
+ result = getpeername(s, name, namelen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/getsockname.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/getsockname.c Thu Oct 24 12:52:56 1996
@@ -0,0 +1,16 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_getsockname(int s, struct sockaddr *name, int *namelen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(name);
+ MAKE_WRITABLE(namelen);
+ result = getsockname(s, name, namelen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/listen.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/listen.c Thu Oct 24 12:53:42 1996
@@ -0,0 +1,14 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_listen(int s, int backlog)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ result = listen(s, backlog);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/read.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/read.c Thu Oct 24 12:55:56 1996
@@ -0,0 +1,15 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <unistd.h>
+
+ssize_t
+m3_read(int d, void *buf, size_t nbytes)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(buf);
+ result = read(d, buf, nbytes);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/recv.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/recv.c Thu Oct 24 12:56:57 1996
@@ -0,0 +1,15 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+ssize_t
+m3_recv(int s, void *buf, size_t len, int flags)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(buf);
+ result = recv(s, buf, len, flags);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/recvfrom.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/recvfrom.c Thu Oct 24 12:58:10 1996
@@ -0,0 +1,18 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+ssize_t
+m3_recvfrom(int s, void *buf, size_t len, int flags,
+ struct sockaddr *from, int *fromlen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(buf);
+ MAKE_WRITABLE(from);
+ MAKE_WRITABLE(fromlen);
+ result = recvfrom(s, buf, len, flags, from, fromlen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/select.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/select.c Thu Oct 24 12:59:17 1996
@@ -0,0 +1,20 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+int
+m3_select(int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_WRITABLE(readfds);
+ MAKE_WRITABLE(writefds);
+ MAKE_WRITABLE(exceptfds);
+ MAKE_READABLE(timeout);
+ result = select(nfds, readfds, writefds, exceptfds, timeout);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/send.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/send.c Thu Oct 24 13:00:25 1996
@@ -0,0 +1,15 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+ssize_t
+m3_send(int s, const void *msg, size_t len, int flags)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(msg);
+ result = send(s, msg, len, flags);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/sendto.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/sendto.c Thu Oct 24 13:01:18 1996
@@ -0,0 +1,17 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+ssize_t
+m3_sendto(int s, const void *msg, size_t len, int flags,
+ const struct sockaddr *to, int tolen)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(msg);
+ MAKE_READABLE(to);
+ result = sendto(s, msg, len, flags, to, tolen);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/shutdown.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/shutdown.c Thu Oct 24 13:01:40 1996
@@ -0,0 +1,14 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_shutdown(int s, int how)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ result = shutdown(s, how);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/socket.c.orig Thu Oct 24 16:11:12 1996
+++ m3/m3core/src/runtime/FreeBSD2/socket.c Thu Oct 24 16:12:22 1996
@@ -0,0 +1,14 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int
+m3_socket(int domain, int type, int protocol)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ result = socket(domain, type, protocol);
+ EXIT_CRITICAL;
+ return result;
+}
--- m3/m3core/src/runtime/FreeBSD2/socksconf.h.orig Fri Oct 25 14:05:03 1996
+++ m3/m3core/src/runtime/FreeBSD2/socksconf.h Fri Oct 25 14:05:28 1996
@@ -0,0 +1,6 @@
+/*
+ * Define 0 or 1 of these, to select the variety of SOCKS support you want.
+ */
+#undef HPSOCKS
+#undef SOCKS4
+#undef SOCKS5
--- m3/m3core/src/runtime/FreeBSD2/wrap.h.orig Thu Oct 24 20:50:16 1996
+++ m3/m3core/src/runtime/FreeBSD2/wrap.h Fri Oct 25 14:04:13 1996
@@ -0,0 +1,61 @@
+#include "socksconf.h"
+
+#if defined(HPSOCKS) /* { */
+ #define accept Raccept
+ #define bind Rxbind
+ #define close Rclose
+ #define connect Rconnect
+ #define dup Rdup
+ #define dup2 Rdup2
+ #define gethostbyaddr Rgethostbyaddr
+ #define gethostbyname Rgethostbyname
+ #define getpeername Rgetpeername
+ #define getsockname Rgetsockname
+ #define listen Rlisten
+ #define recv Rrecv
+ #define recvfrom Rrecvfrom
+ #define send Rsend
+ #define sendto Rsendto
+ #define shutdown Rshutdown
+ #define socket Rsocket
+#elif defined(SOCKS4) /* } { */
+ #define accept Raccept
+ #define bind Rbind
+ #define connect Rconnect
+ #define getpeername Rgetpeername
+ #define getsockname Rgetsockname
+ #define listen Rlisten
+ #define select Rselect
+#elif defined(SOCKS5) /* } { */
+ #define accept SOCKSaccept
+ #define bind SOCKSbind
+ #define close SOCKSclose
+ #define connect SOCKSconnect
+ #define dup SOCKSdup
+ #define dup2 SOCKSdup2
+ #define fclose SOCKSfclose
+ #define gethostbyname SOCKSgethostbyname
+ #define getpeername SOCKSgetpeername
+ #define getsockname SOCKSgetsockname
+ #define listen SOCKSlisten
+ #define read SOCKSread
+ #define recv SOCKSrecv
+ #define recvfrom SOCKSrecvfrom
+ #define rresvport SOCKSrresvport
+ #define select SOCKSselect
+ #define send SOCKSsend
+ #define sendto SOCKSsendto
+ #define shutdown SOCKSshutdown
+ #define write SOCKSwrite
+#endif /* } */
+
+extern int RT0u__inCritical;
+#define ENTER_CRITICAL RT0u__inCritical++
+#define EXIT_CRITICAL RT0u__inCritical--
+
+static char RTHeapDepC__c;
+#define MAKE_READABLE(x) \
+ if ((int)x) { RTHeapDepC__c = *(char*)(x); }
+
+#define MAKE_WRITABLE(x) \
+ if ((int)x) { *(char*)(x) = RTHeapDepC__c = *(char*)(x); }
--- m3/m3core/src/runtime/FreeBSD2/write.c.orig Thu Oct 24 13:11:23 1996
+++ m3/m3core/src/runtime/FreeBSD2/write.c Thu Oct 24 13:02:24 1996
@@ -0,0 +1,15 @@
+#include "wrap.h"
+#include <sys/types.h>
+#include <unistd.h>
+
+size_t
+m3_write(int fd, const void *buf, int nbytes)
+{
+ int result;
+
+ ENTER_CRITICAL;
+ MAKE_READABLE(buf);
+ result = write(fd, buf, nbytes);
+ EXIT_CRITICAL;
+ return result;
+}
|