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