This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta updates
[perl5.git] / os2 / os2ish.h
CommitLineData
4633a7c4
LW
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
CB
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
LW
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
202975e6
IZ
71/* Apparently TCPIPV4 defines may be included even with only IAK present */
72
73#if !defined(NO_TCPIPV4) && !defined(TCPIPV4)
74# define TCPIPV4
75# define TCPIPV4_FORCED /* Just in case */
76#endif
77
4a6a15c8
IZ
78#if defined(I_SYS_UN) && !defined(TCPIPV4)
79/* It is not working without TCPIPV4 defined. */
80# undef I_SYS_UN
81#endif
dd96f567
IZ
82
83#ifdef USE_THREADS
84
85#define OS2_ERROR_ALREADY_POSTED 299 /* Avoid os2.h */
86
87extern int rc;
88
89#define MUTEX_INIT(m) \
90 STMT_START { \
91 int rc; \
92 if ((rc = _rmutex_create(m,0))) \
93 croak("panic: MUTEX_INIT: rc=%i", rc); \
94 } STMT_END
95#define MUTEX_LOCK(m) \
96 STMT_START { \
97 int rc; \
98 if ((rc = _rmutex_request(m,_FMR_IGNINT))) \
99 croak("panic: MUTEX_LOCK: rc=%i", rc); \
100 } STMT_END
101#define MUTEX_UNLOCK(m) \
102 STMT_START { \
103 int rc; \
104 if ((rc = _rmutex_release(m))) \
105 croak("panic: MUTEX_UNLOCK: rc=%i", rc); \
106 } STMT_END
107#define MUTEX_DESTROY(m) \
108 STMT_START { \
109 int rc; \
110 if ((rc = _rmutex_close(m))) \
111 croak("panic: MUTEX_DESTROY: rc=%i", rc); \
112 } STMT_END
113
114#define COND_INIT(c) \
115 STMT_START { \
116 int rc; \
117 if ((rc = DosCreateEventSem(NULL,c,0,0))) \
118 croak("panic: COND_INIT: rc=%i", rc); \
119 } STMT_END
120#define COND_SIGNAL(c) \
121 STMT_START { \
122 int rc; \
123 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED) \
124 croak("panic: COND_SIGNAL, rc=%ld", rc); \
125 } STMT_END
126#define COND_BROADCAST(c) \
127 STMT_START { \
128 int rc; \
129 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
130 croak("panic: COND_BROADCAST, rc=%i", rc); \
131 } STMT_END
132/* #define COND_WAIT(c, m) \
133 STMT_START { \
134 if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \
135 croak("panic: COND_WAIT"); \
136 } STMT_END
137*/
138#define COND_WAIT(c, m) os2_cond_wait(c,m)
139
140#define COND_WAIT_win32(c, m) \
141 STMT_START { \
142 int rc; \
143 if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE)))\
144 croak("panic: COND_WAIT"); \
145 else \
146 MUTEX_LOCK(m); \
147 } STMT_END
148#define COND_DESTROY(c) \
149 STMT_START { \
150 int rc; \
151 if ((rc = DosCloseEventSem(*(c)))) \
152 croak("panic: COND_DESTROY, rc=%i", rc); \
153 } STMT_END
6b88bc9c 154/*#define THR ((struct thread *) TlsGetValue(PL_thr_key))
dd96f567
IZ
155#define dTHR struct thread *thr = THR
156*/
157
90866323
IZ
158#ifdef USE_SLOW_THREAD_SPECIFIC
159# define pthread_getspecific(k) (*_threadstore())
160# define pthread_setspecific(k,v) (*_threadstore()=v,0)
161# define pthread_key_create(keyp,flag) (*keyp=_gettid(),0)
162#else
163# define pthread_getspecific(k) (*(k))
164# define pthread_setspecific(k,v) (*(k)=(v),0)
165# define pthread_key_create(keyp,flag) (DosAllocThreadLocalMemory(1,(U32*)keyp) ? croak("LocalMemory"),1 : 0)
166#endif
167#define pthread_key_delete(keyp)
dd96f567 168#define pthread_self() _gettid()
27139dc0 169#define YIELD DosSleep(0)
dd96f567
IZ
170
171#ifdef PTHREADS_INCLUDED /* For ./x2p stuff. */
172int pthread_join(pthread_t tid, void **status);
173int pthread_detach(pthread_t tid);
174int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
175 void *(*start_routine)(void*), void *arg);
176#endif
177
178#define THREADS_ELSEWHERE
179
180#endif
4a6a15c8 181
aa689395 182void Perl_OS2_init(char **);
183
184/* XXX This code hideously puts env inside: */
365eb7b5 185
aab1f907
IZ
186#ifdef __EMX__
187# define PERL_SYS_INIT(argcp, argvp) STMT_START { \
eacfb5f1 188 _response(argcp, argvp); \
c0c09dfd 189 _wildcard(argcp, argvp); \
aa689395 190 Perl_OS2_init(env); } STMT_END
aab1f907
IZ
191#else /* Compiling embedded Perl with non-EMX compiler */
192# define PERL_SYS_INIT(argcp, argvp) STMT_START { \
193 Perl_OS2_init(env); } STMT_END
194# define PERL_CALLCONV _System
195#endif
18f739ee 196#define PERL_SYS_TERM() MALLOC_TERM
365eb7b5 197
4ea6d94f 198/* #define PERL_SYS_TERM() STMT_START { \
199 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
200
8cc95fdb 201#define dXSUB_SYS OS2_XS_init()
eacfb5f1 202
4ea6d94f 203#ifdef PERL_IS_AOUT
4a6a15c8 204/* # define HAS_FORK */
760ac839
LW
205/* # define HIDEMYMALLOC */
206/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
207#else /* !PERL_IS_AOUT */
208# ifndef PERL_FOR_X2P
4a6a15c8
IZ
209# ifdef EMX_BAD_SBRK
210# define USE_PERL_SBRK
211# endif
212# else
213# define PerlIO FILE
760ac839
LW
214# endif
215# define SYSTEM_ALLOC(a) sys_alloc(a)
216
217void *sys_alloc(int size);
218
219#endif /* !PERL_IS_AOUT */
4a6a15c8
IZ
220#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
221# define PerlIO FILE
222#endif
4ea6d94f 223
c0c09dfd 224#define TMPPATH tmppath
225#define TMPPATH1 "plXXXXXX"
226extern char *tmppath;
4a6a15c8
IZ
227PerlIO *my_syspopen(char *cmd, char *mode);
228/* Cannot prototype with I32 at this point. */
229int my_syspclose(PerlIO *f);
55497cff 230FILE *my_tmpfile (void);
231char *my_tmpnam (char *);
232
233#define tmpfile my_tmpfile
234#define tmpnam my_tmpnam
3ed26a2c 235#define isatty _isterm
44a8e56a 236#define rand random
237#define srand srandom
eacfb5f1 238
4633a7c4
LW
239/*
240 * fwrite1() should be a routine with the same calling sequence as fwrite(),
241 * but which outputs all of the bytes requested as a single stream (unlike
242 * fwrite() itself, which on some systems outputs several distinct records
243 * if the number_of_items parameter is >1).
244 */
245#define fwrite1 fwrite
246
247#define my_getenv(var) getenv(var)
367f3c24 248#define flock my_flock
4633a7c4 249
df3ef7a9
IZ
250void *emx_calloc (size_t, size_t);
251void emx_free (void *);
252void *emx_malloc (size_t);
253void *emx_realloc (void *, size_t);
254
4633a7c4
LW
255/*****************************************************************************/
256
257#include <stdlib.h> /* before the following definitions */
258#include <unistd.h> /* before the following definitions */
259
260#define chdir _chdir2
261#define getcwd _getcwd2
262
263/* This guy is needed for quick stdstd */
264
265#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4
LW
266 /* Perl uses ungetc only with successful return */
267# define ungetc(c,fp) \
268 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
269 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
270#endif
271
272#define OP_BINARY O_BINARY
273
274#define OS2_STAT_HACK 1
275#if OS2_STAT_HACK
276
277#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
278#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 279#define Fflush(fp) fflush(fp)
8cc95fdb 280#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4
LW
281
282#undef S_IFBLK
283#undef S_ISBLK
284#define S_IFBLK 0120000
285#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
286
287#else
288
289#define Stat(fname,bufptr) stat((fname),(bufptr))
290#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 291#define Fflush(fp) fflush(fp)
8cc95fdb 292#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4
LW
293
294#endif
365eb7b5 295
44a8e56a 296/* With SD386 it is impossible to debug register variables. */
297#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
298# define register
299#endif
300
365eb7b5 301/* Our private OS/2 specific data. */
302
303typedef struct OS2_Perl_data {
304 unsigned long flags;
305 unsigned long phab;
306 int (*xs_init)();
4ea6d94f 307 unsigned long rc;
308 unsigned long severity;
4bfbfac5
IZ
309 unsigned long phmq; /* Handle to message queue */
310 unsigned long phmq_refcnt;
311 unsigned long phmq_servers;
312 unsigned long initial_mode; /* VIO etc. mode we were started in */
365eb7b5 313} OS2_Perl_data_t;
314
315extern OS2_Perl_data_t OS2_Perl_data;
316
4ea6d94f 317#define Perl_hab ((HAB)OS2_Perl_data.phab)
318#define Perl_rc (OS2_Perl_data.rc)
319#define Perl_severity (OS2_Perl_data.severity)
320#define errno_isOS2 12345678
321#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 322#define Perl_HAB_set_f 1
4ea6d94f 323#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
324#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
325#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
4bfbfac5
IZ
326#define _obtain_Perl_HAB (init_PMWIN_entries(), \
327 Perl_hab = (*PMWIN_entries.Initialize)(0), \
328 set_Perl_HAB_f, Perl_hab)
329#define perl_hab_GET() (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB)
330#define Acquire_hab() perl_hab_GET()
331#define Perl_hmq ((HMQ)OS2_Perl_data.phmq)
332#define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt)
333#define Perl_hmq_servers (OS2_Perl_data.phmq_servers)
334#define Perl_os2_initial_mode (OS2_Perl_data.initial_mode)
335
336unsigned long Perl_hab_GET();
337unsigned long Perl_Register_MQ(int serve);
338void Perl_Deregister_MQ(int serve);
339int Perl_Serve_Messages(int force);
340/* Cannot prototype with I32 at this point. */
341int Perl_Process_Messages(int force, long *cntp);
342
343struct _QMSG;
344struct PMWIN_entries_t {
345 unsigned long (*Initialize)( unsigned long fsOptions );
346 unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg);
347 int (*DestroyMsgQueue)(unsigned long hmq);
348 int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg,
349 unsigned long hwndFilter, unsigned long msgFilterFirst,
350 unsigned long msgFilterLast, unsigned long fl);
351 int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg,
352 unsigned long hwndFilter, unsigned long msgFilterFirst,
353 unsigned long msgFilterLast);
354 void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg);
355};
356extern struct PMWIN_entries_t PMWIN_entries;
357void init_PMWIN_entries(void);
358
359#define perl_hmq_GET(serve) Perl_Register_MQ(serve);
360#define perl_hmq_UNSET(serve) Perl_Deregister_MQ(serve);
361
365eb7b5 362#define OS2_XS_init() (*OS2_Perl_data.xs_init)()
4ea6d94f 363/* The expressions below return true on error. */
4a6a15c8 364/* INCL_DOSERRORS needed. rc should be declared outside. */
4ea6d94f 365#define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
366/* INCL_WINERRORS needed. */
367#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
368#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
369#define FillOSError(rc) (Perl_rc = rc, \
370 errno = errno_isOS2, \
371 Perl_severity = SEVERITY_ERROR)
372#define FillWinError (Perl_rc = WinGetLastError(Perl_hab), \
373 errno = errno_isOS2, \
374 Perl_severity = ERRORIDSEV(Perl_rc), \
375 Perl_rc = ERRORIDERROR(Perl_rc))
4ea6d94f 376
760ac839 377#define STATIC_FILE_LENGTH 127
ff68c719 378
760ac839
LW
379#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
380char *perllib_mangle(char *, unsigned int);
4ea6d94f 381
382char *os2error(int rc);
383
384/* ************************************************************ */
385#define Dos32QuerySysState DosQuerySysState
386#define QuerySysState(flags, pid, buf, bufsz) \
387 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
388
389#define QSS_PROCESS 1
df3ef7a9
IZ
390#define QSS_MODULE 4
391#define QSS_SEMAPHORES 2
4ea6d94f 392#define QSS_FILE 8 /* Buggy until fixpack18 */
393#define QSS_SHARED 16
394
395#ifdef _OS2EMX_H
396
397APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
398 ULONG _res_,PVOID buf,ULONG bufsz);
399typedef struct {
400 ULONG threadcnt;
401 ULONG proccnt;
402 ULONG modulecnt;
403} QGLOBAL, *PQGLOBAL;
404
405typedef struct {
406 ULONG rectype;
407 USHORT threadid;
408 USHORT slotid;
409 ULONG sleepid;
410 ULONG priority;
411 ULONG systime;
412 ULONG usertime;
413 UCHAR state;
414 UCHAR _reserved1_; /* padding to ULONG */
415 USHORT _reserved2_; /* padding to ULONG */
416} QTHREAD, *PQTHREAD;
417
418typedef struct {
419 USHORT sfn;
420 USHORT refcnt;
421 USHORT flags1;
422 USHORT flags2;
423 USHORT accmode1;
424 USHORT accmode2;
425 ULONG filesize;
426 USHORT volhnd;
427 USHORT attrib;
428 USHORT _reserved_;
429} QFDS, *PQFDS;
430
431typedef struct qfile {
432 ULONG rectype;
433 struct qfile *next;
434 ULONG opencnt;
435 PQFDS filedata;
436 char name[1];
437} QFILE, *PQFILE;
438
439typedef struct {
440 ULONG rectype;
441 PQTHREAD threads;
442 USHORT pid;
443 USHORT ppid;
444 ULONG type;
445 ULONG state;
446 ULONG sessid;
447 USHORT hndmod;
448 USHORT threadcnt;
449 ULONG privsem32cnt;
450 ULONG _reserved2_;
451 USHORT sem16cnt;
452 USHORT dllcnt;
453 USHORT shrmemcnt;
454 USHORT fdscnt;
455 PUSHORT sem16s;
456 PUSHORT dlls;
457 PUSHORT shrmems;
458 PUSHORT fds;
459} QPROCESS, *PQPROCESS;
460
461typedef struct sema {
462 struct sema *next;
463 USHORT refcnt;
464 UCHAR sysflags;
465 UCHAR sysproccnt;
466 ULONG _reserved1_;
467 USHORT index;
468 CHAR name[1];
469} QSEMA, *PQSEMA;
470
471typedef struct {
472 ULONG rectype;
473 ULONG _reserved1_;
474 USHORT _reserved2_;
475 USHORT syssemidx;
476 ULONG index;
477 QSEMA sema;
478} QSEMSTRUC, *PQSEMSTRUC;
479
480typedef struct {
481 USHORT pid;
482 USHORT opencnt;
483} QSEMOWNER32, *PQSEMOWNER32;
484
485typedef struct {
486 PQSEMOWNER32 own;
487 PCHAR name;
488 PVOID semrecs; /* array of associated sema's */
489 USHORT flags;
490 USHORT semreccnt;
491 USHORT waitcnt;
492 USHORT _reserved_; /* padding to ULONG */
493} QSEMSMUX32, *PQSEMSMUX32;
494
495typedef struct {
496 PQSEMOWNER32 own;
497 PCHAR name;
498 PQSEMSMUX32 mux;
499 USHORT flags;
500 USHORT postcnt;
501} QSEMEV32, *PQSEMEV32;
502
503typedef struct {
504 PQSEMOWNER32 own;
505 PCHAR name;
506 PQSEMSMUX32 mux;
507 USHORT flags;
508 USHORT refcnt;
509 USHORT thrdnum;
510 USHORT _reserved_; /* padding to ULONG */
511} QSEMMUX32, *PQSEMMUX32;
512
513typedef struct semstr32 {
514 struct semstr *next;
515 QSEMEV32 evsem;
516 QSEMMUX32 muxsem;
517 QSEMSMUX32 smuxsem;
518} QSEMSTRUC32, *PQSEMSTRUC32;
519
520typedef struct shrmem {
521 struct shrmem *next;
522 USHORT hndshr;
523 USHORT selshr;
524 USHORT refcnt;
525 CHAR name[1];
526} QSHRMEM, *PQSHRMEM;
527
528typedef struct module {
529 struct module *next;
530 USHORT hndmod;
531 USHORT type;
532 ULONG refcnt;
533 ULONG segcnt;
534 PVOID _reserved_;
535 PCHAR name;
536 USHORT modref[1];
537} QMODULE, *PQMODULE;
538
539typedef struct {
540 PQGLOBAL gbldata;
541 PQPROCESS procdata;
542 PQSEMSTRUC semadata;
543 PQSEMSTRUC32 sem32data;
544 PQSHRMEM shrmemdata;
545 PQMODULE moddata;
546 PVOID _reserved2_;
547 PQFILE filedata;
548} QTOPLEVEL, *PQTOPLEVEL;
549/* ************************************************************ */
550
551PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
552
553#endif /* _OS2EMX_H */
5ae7bdf7 554