Commit | Line | Data |
4633a7c4 |
1 | #include <signal.h> |
2 | |
3 | /* HAS_IOCTL: |
4 | * This symbol, if defined, indicates that the ioctl() routine is |
5 | * available to set I/O characteristics |
6 | */ |
7 | #define HAS_IOCTL /**/ |
8 | |
9 | /* HAS_UTIME: |
10 | * This symbol, if defined, indicates that the routine utime() is |
11 | * available to update the access and modification times of files. |
12 | */ |
13 | #define HAS_UTIME /**/ |
14 | |
15 | #define HAS_KILL |
16 | #define HAS_WAIT |
4ea6d94f |
17 | #define HAS_DLERROR |
367f3c24 |
18 | #define HAS_WAITPID_RUNTIME (_emx_env & 0x200) |
4ea6d94f |
19 | |
20 | /* USEMYBINMODE |
21 | * This symbol, if defined, indicates that the program should |
22 | * use the routine my_binmode(FILE *fp, char iotype) to insure |
23 | * that a file is in "binary" mode -- that is, that no translation |
24 | * of bytes occurs on read or write operations. |
25 | */ |
26 | #undef USEMYBINMODE |
27 | |
61bb5906 |
28 | /* Stat_t: |
29 | * This symbol holds the type used to declare buffers for information |
30 | * returned by stat(). It's usually just struct stat. It may be necessary |
31 | * to include <sys/stat.h> and <sys/types.h> to get any typedef'ed |
32 | * information. |
33 | */ |
34 | #define Stat_t struct stat |
35 | |
4ea6d94f |
36 | /* USE_STAT_RDEV: |
37 | * This symbol is defined if this system has a stat structure declaring |
38 | * st_rdev |
39 | */ |
40 | #define USE_STAT_RDEV /**/ |
41 | |
42 | /* ACME_MESS: |
43 | * This symbol, if defined, indicates that error messages should be |
44 | * should be generated in a format that allows the use of the Acme |
45 | * GUI/editor's autofind feature. |
46 | */ |
47 | #undef ACME_MESS /**/ |
4633a7c4 |
48 | |
44a8e56a |
49 | /* ALTERNATE_SHEBANG: |
50 | * This symbol, if defined, contains a "magic" string which may be used |
51 | * as the first line of a Perl program designed to be executed directly |
52 | * by name, instead of the standard Unix #!. If ALTERNATE_SHEBANG |
53 | * begins with a character other then #, then Perl will only treat |
54 | * it as a command line if if finds the string "perl" in the first |
55 | * word; otherwise it's treated as the first line of code in the script. |
56 | * (IOW, Perl won't hand off to another interpreter via an alternate |
57 | * shebang sequence that might be legal Perl code.) |
58 | */ |
aa689395 |
59 | #define ALTERNATE_SHEBANG "extproc " |
44a8e56a |
60 | |
4633a7c4 |
61 | #ifndef SIGABRT |
62 | # define SIGABRT SIGILL |
63 | #endif |
64 | #ifndef SIGILL |
65 | # define SIGILL 6 /* blech */ |
66 | #endif |
67 | #define ABORT() kill(getpid(),SIGABRT); |
68 | |
760ac839 |
69 | #define BIT_BUCKET "/dev/nul" /* Will this work? */ |
c07a80fd |
70 | |
4a6a15c8 |
71 | #if defined(I_SYS_UN) && !defined(TCPIPV4) |
72 | /* It is not working without TCPIPV4 defined. */ |
73 | # undef I_SYS_UN |
74 | #endif |
dd96f567 |
75 | |
76 | #ifdef USE_THREADS |
77 | |
78 | #define OS2_ERROR_ALREADY_POSTED 299 /* Avoid os2.h */ |
79 | |
80 | extern int rc; |
81 | |
82 | #define MUTEX_INIT(m) \ |
83 | STMT_START { \ |
84 | int rc; \ |
85 | if ((rc = _rmutex_create(m,0))) \ |
86 | croak("panic: MUTEX_INIT: rc=%i", rc); \ |
87 | } STMT_END |
88 | #define MUTEX_LOCK(m) \ |
89 | STMT_START { \ |
90 | int rc; \ |
91 | if ((rc = _rmutex_request(m,_FMR_IGNINT))) \ |
92 | croak("panic: MUTEX_LOCK: rc=%i", rc); \ |
93 | } STMT_END |
94 | #define MUTEX_UNLOCK(m) \ |
95 | STMT_START { \ |
96 | int rc; \ |
97 | if ((rc = _rmutex_release(m))) \ |
98 | croak("panic: MUTEX_UNLOCK: rc=%i", rc); \ |
99 | } STMT_END |
100 | #define MUTEX_DESTROY(m) \ |
101 | STMT_START { \ |
102 | int rc; \ |
103 | if ((rc = _rmutex_close(m))) \ |
104 | croak("panic: MUTEX_DESTROY: rc=%i", rc); \ |
105 | } STMT_END |
106 | |
107 | #define COND_INIT(c) \ |
108 | STMT_START { \ |
109 | int rc; \ |
110 | if ((rc = DosCreateEventSem(NULL,c,0,0))) \ |
111 | croak("panic: COND_INIT: rc=%i", rc); \ |
112 | } STMT_END |
113 | #define COND_SIGNAL(c) \ |
114 | STMT_START { \ |
115 | int rc; \ |
116 | if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED) \ |
117 | croak("panic: COND_SIGNAL, rc=%ld", rc); \ |
118 | } STMT_END |
119 | #define COND_BROADCAST(c) \ |
120 | STMT_START { \ |
121 | int rc; \ |
122 | if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\ |
123 | croak("panic: COND_BROADCAST, rc=%i", rc); \ |
124 | } STMT_END |
125 | /* #define COND_WAIT(c, m) \ |
126 | STMT_START { \ |
127 | if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \ |
128 | croak("panic: COND_WAIT"); \ |
129 | } STMT_END |
130 | */ |
131 | #define COND_WAIT(c, m) os2_cond_wait(c,m) |
132 | |
133 | #define COND_WAIT_win32(c, m) \ |
134 | STMT_START { \ |
135 | int rc; \ |
136 | if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE)))\ |
137 | croak("panic: COND_WAIT"); \ |
138 | else \ |
139 | MUTEX_LOCK(m); \ |
140 | } STMT_END |
141 | #define COND_DESTROY(c) \ |
142 | STMT_START { \ |
143 | int rc; \ |
144 | if ((rc = DosCloseEventSem(*(c)))) \ |
145 | croak("panic: COND_DESTROY, rc=%i", rc); \ |
146 | } STMT_END |
147 | /*#define THR ((struct thread *) TlsGetValue(thr_key)) |
148 | #define dTHR struct thread *thr = THR |
149 | */ |
150 | |
151 | #define pthread_getspecific(k) (*_threadstore()) |
152 | #define pthread_setspecific(k,v) (*_threadstore()=v,0) |
153 | #define pthread_self() _gettid() |
154 | #define pthread_key_create(keyp,flag) (*keyp=_gettid(),0) |
155 | #define sched_yield() DosSleep(0) |
156 | |
157 | #ifdef PTHREADS_INCLUDED /* For ./x2p stuff. */ |
158 | int pthread_join(pthread_t tid, void **status); |
159 | int pthread_detach(pthread_t tid); |
160 | int pthread_create(pthread_t *tid, const pthread_attr_t *attr, |
161 | void *(*start_routine)(void*), void *arg); |
162 | #endif |
163 | |
164 | #define THREADS_ELSEWHERE |
165 | |
166 | #endif |
4a6a15c8 |
167 | |
aa689395 |
168 | void Perl_OS2_init(char **); |
169 | |
170 | /* XXX This code hideously puts env inside: */ |
365eb7b5 |
171 | |
172 | #define PERL_SYS_INIT(argcp, argvp) STMT_START { \ |
eacfb5f1 |
173 | _response(argcp, argvp); \ |
c0c09dfd |
174 | _wildcard(argcp, argvp); \ |
aa689395 |
175 | Perl_OS2_init(env); } STMT_END |
365eb7b5 |
176 | |
18f739ee |
177 | #define PERL_SYS_TERM() MALLOC_TERM |
365eb7b5 |
178 | |
4ea6d94f |
179 | /* #define PERL_SYS_TERM() STMT_START { \ |
180 | if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */ |
181 | |
8cc95fdb |
182 | #define dXSUB_SYS OS2_XS_init() |
eacfb5f1 |
183 | |
4ea6d94f |
184 | #ifdef PERL_IS_AOUT |
4a6a15c8 |
185 | /* # define HAS_FORK */ |
760ac839 |
186 | /* # define HIDEMYMALLOC */ |
187 | /* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */ |
188 | #else /* !PERL_IS_AOUT */ |
189 | # ifndef PERL_FOR_X2P |
4a6a15c8 |
190 | # ifdef EMX_BAD_SBRK |
191 | # define USE_PERL_SBRK |
192 | # endif |
193 | # else |
194 | # define PerlIO FILE |
760ac839 |
195 | # endif |
196 | # define SYSTEM_ALLOC(a) sys_alloc(a) |
197 | |
198 | void *sys_alloc(int size); |
199 | |
200 | #endif /* !PERL_IS_AOUT */ |
4a6a15c8 |
201 | #if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */ |
202 | # define PerlIO FILE |
203 | #endif |
4ea6d94f |
204 | |
c0c09dfd |
205 | #define TMPPATH tmppath |
206 | #define TMPPATH1 "plXXXXXX" |
207 | extern char *tmppath; |
4a6a15c8 |
208 | PerlIO *my_syspopen(char *cmd, char *mode); |
209 | /* Cannot prototype with I32 at this point. */ |
210 | int my_syspclose(PerlIO *f); |
55497cff |
211 | FILE *my_tmpfile (void); |
212 | char *my_tmpnam (char *); |
213 | |
214 | #define tmpfile my_tmpfile |
215 | #define tmpnam my_tmpnam |
3ed26a2c |
216 | #define isatty _isterm |
44a8e56a |
217 | #define rand random |
218 | #define srand srandom |
eacfb5f1 |
219 | |
4633a7c4 |
220 | /* |
221 | * fwrite1() should be a routine with the same calling sequence as fwrite(), |
222 | * but which outputs all of the bytes requested as a single stream (unlike |
223 | * fwrite() itself, which on some systems outputs several distinct records |
224 | * if the number_of_items parameter is >1). |
225 | */ |
226 | #define fwrite1 fwrite |
227 | |
228 | #define my_getenv(var) getenv(var) |
367f3c24 |
229 | #define flock my_flock |
4633a7c4 |
230 | |
df3ef7a9 |
231 | void *emx_calloc (size_t, size_t); |
232 | void emx_free (void *); |
233 | void *emx_malloc (size_t); |
234 | void *emx_realloc (void *, size_t); |
235 | |
4633a7c4 |
236 | /*****************************************************************************/ |
237 | |
238 | #include <stdlib.h> /* before the following definitions */ |
239 | #include <unistd.h> /* before the following definitions */ |
240 | |
241 | #define chdir _chdir2 |
242 | #define getcwd _getcwd2 |
243 | |
244 | /* This guy is needed for quick stdstd */ |
245 | |
246 | #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE) |
4633a7c4 |
247 | /* Perl uses ungetc only with successful return */ |
248 | # define ungetc(c,fp) \ |
249 | (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \ |
250 | ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp)) |
251 | #endif |
252 | |
253 | #define OP_BINARY O_BINARY |
254 | |
255 | #define OS2_STAT_HACK 1 |
256 | #if OS2_STAT_HACK |
257 | |
258 | #define Stat(fname,bufptr) os2_stat((fname),(bufptr)) |
259 | #define Fstat(fd,bufptr) fstat((fd),(bufptr)) |
365eb7b5 |
260 | #define Fflush(fp) fflush(fp) |
8cc95fdb |
261 | #define Mkdir(path,mode) mkdir((path),(mode)) |
4633a7c4 |
262 | |
263 | #undef S_IFBLK |
264 | #undef S_ISBLK |
265 | #define S_IFBLK 0120000 |
266 | #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) |
267 | |
268 | #else |
269 | |
270 | #define Stat(fname,bufptr) stat((fname),(bufptr)) |
271 | #define Fstat(fd,bufptr) fstat((fd),(bufptr)) |
365eb7b5 |
272 | #define Fflush(fp) fflush(fp) |
8cc95fdb |
273 | #define Mkdir(path,mode) mkdir((path),(mode)) |
4633a7c4 |
274 | |
275 | #endif |
365eb7b5 |
276 | |
44a8e56a |
277 | /* With SD386 it is impossible to debug register variables. */ |
278 | #if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register) |
279 | # define register |
280 | #endif |
281 | |
365eb7b5 |
282 | /* Our private OS/2 specific data. */ |
283 | |
284 | typedef struct OS2_Perl_data { |
285 | unsigned long flags; |
286 | unsigned long phab; |
287 | int (*xs_init)(); |
4ea6d94f |
288 | unsigned long rc; |
289 | unsigned long severity; |
365eb7b5 |
290 | } OS2_Perl_data_t; |
291 | |
292 | extern OS2_Perl_data_t OS2_Perl_data; |
293 | |
4ea6d94f |
294 | #define Perl_hab ((HAB)OS2_Perl_data.phab) |
295 | #define Perl_rc (OS2_Perl_data.rc) |
296 | #define Perl_severity (OS2_Perl_data.severity) |
297 | #define errno_isOS2 12345678 |
298 | #define OS2_Perl_flags (OS2_Perl_data.flags) |
365eb7b5 |
299 | #define Perl_HAB_set_f 1 |
4ea6d94f |
300 | #define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f) |
301 | #define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f) |
302 | #define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h) |
365eb7b5 |
303 | #define OS2_XS_init() (*OS2_Perl_data.xs_init)() |
4ea6d94f |
304 | /* The expressions below return true on error. */ |
4a6a15c8 |
305 | /* INCL_DOSERRORS needed. rc should be declared outside. */ |
4ea6d94f |
306 | #define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1)) |
307 | /* INCL_WINERRORS needed. */ |
308 | #define SaveWinError(expr) ((expr) ? : (FillWinError, 0)) |
309 | #define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1)) |
310 | #define FillOSError(rc) (Perl_rc = rc, \ |
311 | errno = errno_isOS2, \ |
312 | Perl_severity = SEVERITY_ERROR) |
313 | #define FillWinError (Perl_rc = WinGetLastError(Perl_hab), \ |
314 | errno = errno_isOS2, \ |
315 | Perl_severity = ERRORIDSEV(Perl_rc), \ |
316 | Perl_rc = ERRORIDERROR(Perl_rc)) |
317 | #define Acquire_hab() if (!Perl_HAB_set) { \ |
318 | Perl_hab = WinInitialize(0); \ |
319 | if (!Perl_hab) die("WinInitialize failed"); \ |
320 | set_Perl_HAB_f; \ |
321 | } |
322 | |
760ac839 |
323 | #define STATIC_FILE_LENGTH 127 |
ff68c719 |
324 | |
760ac839 |
325 | #define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n)) |
326 | char *perllib_mangle(char *, unsigned int); |
4ea6d94f |
327 | |
328 | char *os2error(int rc); |
329 | |
330 | /* ************************************************************ */ |
331 | #define Dos32QuerySysState DosQuerySysState |
332 | #define QuerySysState(flags, pid, buf, bufsz) \ |
333 | Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz) |
334 | |
335 | #define QSS_PROCESS 1 |
df3ef7a9 |
336 | #define QSS_MODULE 4 |
337 | #define QSS_SEMAPHORES 2 |
4ea6d94f |
338 | #define QSS_FILE 8 /* Buggy until fixpack18 */ |
339 | #define QSS_SHARED 16 |
340 | |
341 | #ifdef _OS2EMX_H |
342 | |
343 | APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid, |
344 | ULONG _res_,PVOID buf,ULONG bufsz); |
345 | typedef struct { |
346 | ULONG threadcnt; |
347 | ULONG proccnt; |
348 | ULONG modulecnt; |
349 | } QGLOBAL, *PQGLOBAL; |
350 | |
351 | typedef struct { |
352 | ULONG rectype; |
353 | USHORT threadid; |
354 | USHORT slotid; |
355 | ULONG sleepid; |
356 | ULONG priority; |
357 | ULONG systime; |
358 | ULONG usertime; |
359 | UCHAR state; |
360 | UCHAR _reserved1_; /* padding to ULONG */ |
361 | USHORT _reserved2_; /* padding to ULONG */ |
362 | } QTHREAD, *PQTHREAD; |
363 | |
364 | typedef struct { |
365 | USHORT sfn; |
366 | USHORT refcnt; |
367 | USHORT flags1; |
368 | USHORT flags2; |
369 | USHORT accmode1; |
370 | USHORT accmode2; |
371 | ULONG filesize; |
372 | USHORT volhnd; |
373 | USHORT attrib; |
374 | USHORT _reserved_; |
375 | } QFDS, *PQFDS; |
376 | |
377 | typedef struct qfile { |
378 | ULONG rectype; |
379 | struct qfile *next; |
380 | ULONG opencnt; |
381 | PQFDS filedata; |
382 | char name[1]; |
383 | } QFILE, *PQFILE; |
384 | |
385 | typedef struct { |
386 | ULONG rectype; |
387 | PQTHREAD threads; |
388 | USHORT pid; |
389 | USHORT ppid; |
390 | ULONG type; |
391 | ULONG state; |
392 | ULONG sessid; |
393 | USHORT hndmod; |
394 | USHORT threadcnt; |
395 | ULONG privsem32cnt; |
396 | ULONG _reserved2_; |
397 | USHORT sem16cnt; |
398 | USHORT dllcnt; |
399 | USHORT shrmemcnt; |
400 | USHORT fdscnt; |
401 | PUSHORT sem16s; |
402 | PUSHORT dlls; |
403 | PUSHORT shrmems; |
404 | PUSHORT fds; |
405 | } QPROCESS, *PQPROCESS; |
406 | |
407 | typedef struct sema { |
408 | struct sema *next; |
409 | USHORT refcnt; |
410 | UCHAR sysflags; |
411 | UCHAR sysproccnt; |
412 | ULONG _reserved1_; |
413 | USHORT index; |
414 | CHAR name[1]; |
415 | } QSEMA, *PQSEMA; |
416 | |
417 | typedef struct { |
418 | ULONG rectype; |
419 | ULONG _reserved1_; |
420 | USHORT _reserved2_; |
421 | USHORT syssemidx; |
422 | ULONG index; |
423 | QSEMA sema; |
424 | } QSEMSTRUC, *PQSEMSTRUC; |
425 | |
426 | typedef struct { |
427 | USHORT pid; |
428 | USHORT opencnt; |
429 | } QSEMOWNER32, *PQSEMOWNER32; |
430 | |
431 | typedef struct { |
432 | PQSEMOWNER32 own; |
433 | PCHAR name; |
434 | PVOID semrecs; /* array of associated sema's */ |
435 | USHORT flags; |
436 | USHORT semreccnt; |
437 | USHORT waitcnt; |
438 | USHORT _reserved_; /* padding to ULONG */ |
439 | } QSEMSMUX32, *PQSEMSMUX32; |
440 | |
441 | typedef struct { |
442 | PQSEMOWNER32 own; |
443 | PCHAR name; |
444 | PQSEMSMUX32 mux; |
445 | USHORT flags; |
446 | USHORT postcnt; |
447 | } QSEMEV32, *PQSEMEV32; |
448 | |
449 | typedef struct { |
450 | PQSEMOWNER32 own; |
451 | PCHAR name; |
452 | PQSEMSMUX32 mux; |
453 | USHORT flags; |
454 | USHORT refcnt; |
455 | USHORT thrdnum; |
456 | USHORT _reserved_; /* padding to ULONG */ |
457 | } QSEMMUX32, *PQSEMMUX32; |
458 | |
459 | typedef struct semstr32 { |
460 | struct semstr *next; |
461 | QSEMEV32 evsem; |
462 | QSEMMUX32 muxsem; |
463 | QSEMSMUX32 smuxsem; |
464 | } QSEMSTRUC32, *PQSEMSTRUC32; |
465 | |
466 | typedef struct shrmem { |
467 | struct shrmem *next; |
468 | USHORT hndshr; |
469 | USHORT selshr; |
470 | USHORT refcnt; |
471 | CHAR name[1]; |
472 | } QSHRMEM, *PQSHRMEM; |
473 | |
474 | typedef struct module { |
475 | struct module *next; |
476 | USHORT hndmod; |
477 | USHORT type; |
478 | ULONG refcnt; |
479 | ULONG segcnt; |
480 | PVOID _reserved_; |
481 | PCHAR name; |
482 | USHORT modref[1]; |
483 | } QMODULE, *PQMODULE; |
484 | |
485 | typedef struct { |
486 | PQGLOBAL gbldata; |
487 | PQPROCESS procdata; |
488 | PQSEMSTRUC semadata; |
489 | PQSEMSTRUC32 sem32data; |
490 | PQSHRMEM shrmemdata; |
491 | PQMODULE moddata; |
492 | PVOID _reserved2_; |
493 | PQFILE filedata; |
494 | } QTOPLEVEL, *PQTOPLEVEL; |
495 | /* ************************************************************ */ |
496 | |
497 | PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags); |
498 | |
499 | #endif /* _OS2EMX_H */ |
5ae7bdf7 |
500 | |