Integrate mainperl.
[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
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
80extern 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
6b88bc9c 147/*#define THR ((struct thread *) TlsGetValue(PL_thr_key))
dd96f567 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. */
158int pthread_join(pthread_t tid, void **status);
159int pthread_detach(pthread_t tid);
160int 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 168void Perl_OS2_init(char **);
169
170/* XXX This code hideously puts env inside: */
365eb7b5 171
aab1f907 172#ifdef __EMX__
173# define PERL_SYS_INIT(argcp, argvp) STMT_START { \
eacfb5f1 174 _response(argcp, argvp); \
c0c09dfd 175 _wildcard(argcp, argvp); \
aa689395 176 Perl_OS2_init(env); } STMT_END
aab1f907 177#else /* Compiling embedded Perl with non-EMX compiler */
178# define PERL_SYS_INIT(argcp, argvp) STMT_START { \
179 Perl_OS2_init(env); } STMT_END
180# define PERL_CALLCONV _System
181#endif
18f739ee 182#define PERL_SYS_TERM() MALLOC_TERM
365eb7b5 183
4ea6d94f 184/* #define PERL_SYS_TERM() STMT_START { \
185 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
186
8cc95fdb 187#define dXSUB_SYS OS2_XS_init()
eacfb5f1 188
4ea6d94f 189#ifdef PERL_IS_AOUT
4a6a15c8 190/* # define HAS_FORK */
760ac839 191/* # define HIDEMYMALLOC */
192/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
193#else /* !PERL_IS_AOUT */
194# ifndef PERL_FOR_X2P
4a6a15c8 195# ifdef EMX_BAD_SBRK
196# define USE_PERL_SBRK
197# endif
198# else
199# define PerlIO FILE
760ac839 200# endif
201# define SYSTEM_ALLOC(a) sys_alloc(a)
202
203void *sys_alloc(int size);
204
205#endif /* !PERL_IS_AOUT */
4a6a15c8 206#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
207# define PerlIO FILE
208#endif
4ea6d94f 209
c0c09dfd 210#define TMPPATH tmppath
211#define TMPPATH1 "plXXXXXX"
212extern char *tmppath;
4a6a15c8 213PerlIO *my_syspopen(char *cmd, char *mode);
214/* Cannot prototype with I32 at this point. */
215int my_syspclose(PerlIO *f);
55497cff 216FILE *my_tmpfile (void);
217char *my_tmpnam (char *);
218
219#define tmpfile my_tmpfile
220#define tmpnam my_tmpnam
3ed26a2c 221#define isatty _isterm
44a8e56a 222#define rand random
223#define srand srandom
eacfb5f1 224
4633a7c4 225/*
226 * fwrite1() should be a routine with the same calling sequence as fwrite(),
227 * but which outputs all of the bytes requested as a single stream (unlike
228 * fwrite() itself, which on some systems outputs several distinct records
229 * if the number_of_items parameter is >1).
230 */
231#define fwrite1 fwrite
232
233#define my_getenv(var) getenv(var)
367f3c24 234#define flock my_flock
4633a7c4 235
df3ef7a9 236void *emx_calloc (size_t, size_t);
237void emx_free (void *);
238void *emx_malloc (size_t);
239void *emx_realloc (void *, size_t);
240
4633a7c4 241/*****************************************************************************/
242
243#include <stdlib.h> /* before the following definitions */
244#include <unistd.h> /* before the following definitions */
245
246#define chdir _chdir2
247#define getcwd _getcwd2
248
249/* This guy is needed for quick stdstd */
250
251#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4 252 /* Perl uses ungetc only with successful return */
253# define ungetc(c,fp) \
254 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
255 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
256#endif
257
258#define OP_BINARY O_BINARY
259
260#define OS2_STAT_HACK 1
261#if OS2_STAT_HACK
262
263#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
264#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 265#define Fflush(fp) fflush(fp)
8cc95fdb 266#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4 267
268#undef S_IFBLK
269#undef S_ISBLK
270#define S_IFBLK 0120000
271#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
272
273#else
274
275#define Stat(fname,bufptr) stat((fname),(bufptr))
276#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 277#define Fflush(fp) fflush(fp)
8cc95fdb 278#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4 279
280#endif
365eb7b5 281
44a8e56a 282/* With SD386 it is impossible to debug register variables. */
283#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
284# define register
285#endif
286
365eb7b5 287/* Our private OS/2 specific data. */
288
289typedef struct OS2_Perl_data {
290 unsigned long flags;
291 unsigned long phab;
292 int (*xs_init)();
4ea6d94f 293 unsigned long rc;
294 unsigned long severity;
365eb7b5 295} OS2_Perl_data_t;
296
297extern OS2_Perl_data_t OS2_Perl_data;
298
4ea6d94f 299#define Perl_hab ((HAB)OS2_Perl_data.phab)
300#define Perl_rc (OS2_Perl_data.rc)
301#define Perl_severity (OS2_Perl_data.severity)
302#define errno_isOS2 12345678
303#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 304#define Perl_HAB_set_f 1
4ea6d94f 305#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
306#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
307#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
365eb7b5 308#define OS2_XS_init() (*OS2_Perl_data.xs_init)()
4ea6d94f 309/* The expressions below return true on error. */
4a6a15c8 310/* INCL_DOSERRORS needed. rc should be declared outside. */
4ea6d94f 311#define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
312/* INCL_WINERRORS needed. */
313#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
314#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
315#define FillOSError(rc) (Perl_rc = rc, \
316 errno = errno_isOS2, \
317 Perl_severity = SEVERITY_ERROR)
318#define FillWinError (Perl_rc = WinGetLastError(Perl_hab), \
319 errno = errno_isOS2, \
320 Perl_severity = ERRORIDSEV(Perl_rc), \
321 Perl_rc = ERRORIDERROR(Perl_rc))
322#define Acquire_hab() if (!Perl_HAB_set) { \
323 Perl_hab = WinInitialize(0); \
324 if (!Perl_hab) die("WinInitialize failed"); \
325 set_Perl_HAB_f; \
326 }
327
760ac839 328#define STATIC_FILE_LENGTH 127
ff68c719 329
760ac839 330#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
331char *perllib_mangle(char *, unsigned int);
4ea6d94f 332
333char *os2error(int rc);
334
335/* ************************************************************ */
336#define Dos32QuerySysState DosQuerySysState
337#define QuerySysState(flags, pid, buf, bufsz) \
338 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
339
340#define QSS_PROCESS 1
df3ef7a9 341#define QSS_MODULE 4
342#define QSS_SEMAPHORES 2
4ea6d94f 343#define QSS_FILE 8 /* Buggy until fixpack18 */
344#define QSS_SHARED 16
345
346#ifdef _OS2EMX_H
347
348APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
349 ULONG _res_,PVOID buf,ULONG bufsz);
350typedef struct {
351 ULONG threadcnt;
352 ULONG proccnt;
353 ULONG modulecnt;
354} QGLOBAL, *PQGLOBAL;
355
356typedef struct {
357 ULONG rectype;
358 USHORT threadid;
359 USHORT slotid;
360 ULONG sleepid;
361 ULONG priority;
362 ULONG systime;
363 ULONG usertime;
364 UCHAR state;
365 UCHAR _reserved1_; /* padding to ULONG */
366 USHORT _reserved2_; /* padding to ULONG */
367} QTHREAD, *PQTHREAD;
368
369typedef struct {
370 USHORT sfn;
371 USHORT refcnt;
372 USHORT flags1;
373 USHORT flags2;
374 USHORT accmode1;
375 USHORT accmode2;
376 ULONG filesize;
377 USHORT volhnd;
378 USHORT attrib;
379 USHORT _reserved_;
380} QFDS, *PQFDS;
381
382typedef struct qfile {
383 ULONG rectype;
384 struct qfile *next;
385 ULONG opencnt;
386 PQFDS filedata;
387 char name[1];
388} QFILE, *PQFILE;
389
390typedef struct {
391 ULONG rectype;
392 PQTHREAD threads;
393 USHORT pid;
394 USHORT ppid;
395 ULONG type;
396 ULONG state;
397 ULONG sessid;
398 USHORT hndmod;
399 USHORT threadcnt;
400 ULONG privsem32cnt;
401 ULONG _reserved2_;
402 USHORT sem16cnt;
403 USHORT dllcnt;
404 USHORT shrmemcnt;
405 USHORT fdscnt;
406 PUSHORT sem16s;
407 PUSHORT dlls;
408 PUSHORT shrmems;
409 PUSHORT fds;
410} QPROCESS, *PQPROCESS;
411
412typedef struct sema {
413 struct sema *next;
414 USHORT refcnt;
415 UCHAR sysflags;
416 UCHAR sysproccnt;
417 ULONG _reserved1_;
418 USHORT index;
419 CHAR name[1];
420} QSEMA, *PQSEMA;
421
422typedef struct {
423 ULONG rectype;
424 ULONG _reserved1_;
425 USHORT _reserved2_;
426 USHORT syssemidx;
427 ULONG index;
428 QSEMA sema;
429} QSEMSTRUC, *PQSEMSTRUC;
430
431typedef struct {
432 USHORT pid;
433 USHORT opencnt;
434} QSEMOWNER32, *PQSEMOWNER32;
435
436typedef struct {
437 PQSEMOWNER32 own;
438 PCHAR name;
439 PVOID semrecs; /* array of associated sema's */
440 USHORT flags;
441 USHORT semreccnt;
442 USHORT waitcnt;
443 USHORT _reserved_; /* padding to ULONG */
444} QSEMSMUX32, *PQSEMSMUX32;
445
446typedef struct {
447 PQSEMOWNER32 own;
448 PCHAR name;
449 PQSEMSMUX32 mux;
450 USHORT flags;
451 USHORT postcnt;
452} QSEMEV32, *PQSEMEV32;
453
454typedef struct {
455 PQSEMOWNER32 own;
456 PCHAR name;
457 PQSEMSMUX32 mux;
458 USHORT flags;
459 USHORT refcnt;
460 USHORT thrdnum;
461 USHORT _reserved_; /* padding to ULONG */
462} QSEMMUX32, *PQSEMMUX32;
463
464typedef struct semstr32 {
465 struct semstr *next;
466 QSEMEV32 evsem;
467 QSEMMUX32 muxsem;
468 QSEMSMUX32 smuxsem;
469} QSEMSTRUC32, *PQSEMSTRUC32;
470
471typedef struct shrmem {
472 struct shrmem *next;
473 USHORT hndshr;
474 USHORT selshr;
475 USHORT refcnt;
476 CHAR name[1];
477} QSHRMEM, *PQSHRMEM;
478
479typedef struct module {
480 struct module *next;
481 USHORT hndmod;
482 USHORT type;
483 ULONG refcnt;
484 ULONG segcnt;
485 PVOID _reserved_;
486 PCHAR name;
487 USHORT modref[1];
488} QMODULE, *PQMODULE;
489
490typedef struct {
491 PQGLOBAL gbldata;
492 PQPROCESS procdata;
493 PQSEMSTRUC semadata;
494 PQSEMSTRUC32 sem32data;
495 PQSHRMEM shrmemdata;
496 PQMODULE moddata;
497 PVOID _reserved2_;
498 PQFILE filedata;
499} QTOPLEVEL, *PQTOPLEVEL;
500/* ************************************************************ */
501
502PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
503
504#endif /* _OS2EMX_H */
5ae7bdf7 505