OS/2: more missing definitions.
[p5sagit/p5-mst-13.2.git] / os2 / os2ish.h
1 #include <signal.h>
2 #include <io.h>
3 /* #include <sys/select.h> */
4
5 /* HAS_IOCTL:
6  *      This symbol, if defined, indicates that the ioctl() routine is
7  *      available to set I/O characteristics
8  */
9 #define HAS_IOCTL               /**/
10  
11 /* HAS_UTIME:
12  *      This symbol, if defined, indicates that the routine utime() is
13  *      available to update the access and modification times of files.
14  */
15 #define HAS_UTIME               /**/
16
17 #define HAS_KILL
18 #define HAS_WAIT
19 #define HAS_DLERROR
20 #define HAS_WAITPID_RUNTIME (_emx_env & 0x200)
21
22 /* HAS_PASSWD
23  *      This symbol, if defined, indicates that the getpwnam() and
24  *      getpwuid() routines are available to get password entries.
25  *      The getpwent() has a separate definition, HAS_GETPWENT.
26  */
27 #define HAS_PASSWD
28
29 /* HAS_GROUP
30  *      This symbol, if defined, indicates that the getgrnam() and
31  *      getgrgid() routines are available to get group entries.
32  *      The getgrent() has a separate definition, HAS_GETGRENT.
33  */
34 #define HAS_GROUP
35 #define HAS_GETGRENT                    /* fake */
36 #define HAS_SETGRENT                    /* fake */
37 #define HAS_ENDGRENT                    /* fake */
38
39 /* USEMYBINMODE
40  *      This symbol, if defined, indicates that the program should
41  *      use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
42  *      that a file is in "binary" mode -- that is, that no translation
43  *      of bytes occurs on read or write operations.
44  */
45 #undef USEMYBINMODE
46
47 /* Stat_t:
48  *      This symbol holds the type used to declare buffers for information
49  *      returned by stat().  It's usually just struct stat.  It may be necessary
50  *      to include <sys/stat.h> and <sys/types.h> to get any typedef'ed
51  *      information.
52  */
53 #define Stat_t struct stat
54
55 /* USE_STAT_RDEV:
56  *      This symbol is defined if this system has a stat structure declaring
57  *      st_rdev
58  */
59 #define USE_STAT_RDEV   /**/
60
61 /* ACME_MESS:
62  *      This symbol, if defined, indicates that error messages should be 
63  *      should be generated in a format that allows the use of the Acme
64  *      GUI/editor's autofind feature.
65  */
66 #undef ACME_MESS        /**/
67
68 /* ALTERNATE_SHEBANG:
69  *      This symbol, if defined, contains a "magic" string which may be used
70  *      as the first line of a Perl program designed to be executed directly
71  *      by name, instead of the standard Unix #!.  If ALTERNATE_SHEBANG
72  *      begins with a character other then #, then Perl will only treat
73  *      it as a command line if if finds the string "perl" in the first
74  *      word; otherwise it's treated as the first line of code in the script.
75  *      (IOW, Perl won't hand off to another interpreter via an alternate
76  *      shebang sequence that might be legal Perl code.)
77  */
78 #define ALTERNATE_SHEBANG "extproc "
79
80 #ifndef SIGABRT
81 #    define SIGABRT SIGILL
82 #endif
83 #ifndef SIGILL
84 #    define SIGILL 6         /* blech */
85 #endif
86 #define ABORT() kill(PerlProc_getpid(),SIGABRT);
87
88 #define BIT_BUCKET "/dev/nul"  /* Will this work? */
89
90 /* Apparently TCPIPV4 defines may be included even with only IAK present */
91
92 #if !defined(NO_TCPIPV4) && !defined(TCPIPV4)
93 #  define TCPIPV4
94 #  define TCPIPV4_FORCED                /* Just in case */
95 #endif
96
97 #if defined(I_SYS_UN) && !defined(TCPIPV4)
98 /* It is not working without TCPIPV4 defined. */
99 # undef I_SYS_UN
100 #endif 
101
102 #ifdef USE_5005THREADS
103
104 #define do_spawn(a)      os2_do_spawn(aTHX_ (a))
105 #define do_aspawn(a,b,c) os2_do_aspawn(aTHX_ (a),(b),(c))
106
107 #define OS2_ERROR_ALREADY_POSTED 299    /* Avoid os2.h */
108
109 extern int rc;
110
111 #define MUTEX_INIT(m) \
112     STMT_START {                                                \
113         int rc;                                                 \
114         if ((rc = _rmutex_create(m,0)))                         \
115             Perl_croak_nocontext("panic: MUTEX_INIT: rc=%i", rc);       \
116     } STMT_END
117 #define MUTEX_LOCK(m) \
118     STMT_START {                                                \
119         int rc;                                                 \
120         if ((rc = _rmutex_request(m,_FMR_IGNINT)))              \
121             Perl_croak_nocontext("panic: MUTEX_LOCK: rc=%i", rc);       \
122     } STMT_END
123 #define MUTEX_UNLOCK(m) \
124     STMT_START {                                                \
125         int rc;                                                 \
126         if ((rc = _rmutex_release(m)))                          \
127             Perl_croak_nocontext("panic: MUTEX_UNLOCK: rc=%i", rc);     \
128     } STMT_END
129 #define MUTEX_DESTROY(m) \
130     STMT_START {                                                \
131         int rc;                                                 \
132         if ((rc = _rmutex_close(m)))                            \
133             Perl_croak_nocontext("panic: MUTEX_DESTROY: rc=%i", rc);    \
134     } STMT_END
135
136 #define COND_INIT(c) \
137     STMT_START {                                                \
138         int rc;                                                 \
139         if ((rc = DosCreateEventSem(NULL,c,0,0)))               \
140             Perl_croak_nocontext("panic: COND_INIT: rc=%i", rc);        \
141     } STMT_END
142 #define COND_SIGNAL(c) \
143     STMT_START {                                                \
144         int rc;                                                 \
145         if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
146             Perl_croak_nocontext("panic: COND_SIGNAL, rc=%ld", rc);     \
147     } STMT_END
148 #define COND_BROADCAST(c) \
149     STMT_START {                                                \
150         int rc;                                                 \
151         if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
152             Perl_croak_nocontext("panic: COND_BROADCAST, rc=%i", rc);   \
153     } STMT_END
154 /* #define COND_WAIT(c, m) \
155     STMT_START {                                                \
156         if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED)  \
157             Perl_croak_nocontext("panic: COND_WAIT");           \
158     } STMT_END
159 */
160 #define COND_WAIT(c, m) os2_cond_wait(c,m)
161
162 #define COND_WAIT_win32(c, m) \
163     STMT_START {                                                \
164         int rc;                                                 \
165         if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE)))       \
166             Perl_croak_nocontext("panic: COND_WAIT");                   \
167         else                                                    \
168             MUTEX_LOCK(m);                                      \
169     } STMT_END
170 #define COND_DESTROY(c) \
171     STMT_START {                                                \
172         int rc;                                                 \
173         if ((rc = DosCloseEventSem(*(c))))                      \
174             Perl_croak_nocontext("panic: COND_DESTROY, rc=%i", rc);     \
175     } STMT_END
176 /*#define THR ((struct thread *) TlsGetValue(PL_thr_key))
177 */
178
179 #ifdef USE_SLOW_THREAD_SPECIFIC
180 #  define pthread_getspecific(k)        (*_threadstore())
181 #  define pthread_setspecific(k,v)      (*_threadstore()=v,0)
182 #  define pthread_key_create(keyp,flag) (*keyp=_gettid(),0)
183 #else /* USE_SLOW_THREAD_SPECIFIC */
184 #  define pthread_getspecific(k)        (*(k))
185 #  define pthread_setspecific(k,v)      (*(k)=(v),0)
186 #  define pthread_key_create(keyp,flag)                 \
187         ( DosAllocThreadLocalMemory(1,(U32*)keyp)       \
188           ? Perl_croak_nocontext("LocalMemory"),1       \
189           : 0                                           \
190         )
191 #endif /* USE_SLOW_THREAD_SPECIFIC */
192 #define pthread_key_delete(keyp)
193 #define pthread_self()                  _gettid()
194 #define YIELD                           DosSleep(0)
195
196 #ifdef PTHREADS_INCLUDED                /* For ./x2p stuff. */
197 int pthread_join(pthread_t tid, void **status);
198 int pthread_detach(pthread_t tid);
199 int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
200                    void *(*start_routine)(void*), void *arg);
201 #endif /* PTHREAD_INCLUDED */
202
203 #define THREADS_ELSEWHERE
204
205 #else /* USE_5005THREADS */
206
207 #define do_spawn(a)      os2_do_spawn(a)
208 #define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c))
209
210 #endif /* USE_5005THREADS */
211  
212 void Perl_OS2_init(char **);
213 void Perl_OS2_init3(char **envp, void **excH, int flags);
214 void Perl_OS2_term(void **excH, int exitstatus, int flags);
215
216 /* The code without INIT3 hideously puts env inside: */
217
218 /* These ones should be in the same block as PERL_SYS_TERM() */
219 #ifdef PERL_CORE
220
221 #  define PERL_SYS_INIT3(argcp, argvp, envp)    \
222   { void *xreg[2];                              \
223     _response(argcp, argvp);                    \
224     _wildcard(argcp, argvp);                    \
225     Perl_OS2_init3(*envp, xreg, 0)
226
227 #  define PERL_SYS_INIT(argcp, argvp)  {        \
228   { void *xreg[2];                              \
229     _response(argcp, argvp);                    \
230     _wildcard(argcp, argvp);                    \
231     Perl_OS2_init3(NULL, xreg, 0)
232
233 #else  /* Compiling embedded Perl or Perl extension */
234
235 #  define PERL_SYS_INIT3(argcp, argvp, envp)    \
236   { void *xreg[2];                              \
237     Perl_OS2_init3(*envp, xreg, 0)
238 #  define PERL_SYS_INIT(argcp, argvp)   {       \
239   { void *xreg[2];                              \
240     Perl_OS2_init3(NULL, xreg, 0)
241 #endif
242
243 #define FORCE_EMX_DEINIT_EXIT           1
244 #define FORCE_EMX_DEINIT_CRT_TERM       2
245 #define FORCE_EMX_DEINIT_RUN_ATEXIT     4
246
247 #define PERL_SYS_TERM2(xreg,flags)                                      \
248   Perl_OS2_term(xreg, 0, flags);                                        \
249   MALLOC_TERM
250
251 #define PERL_SYS_TERM1(xreg)                                            \
252      Perl_OS2_term(xreg, 0, FORCE_EMX_DEINIT_RUN_ATEXIT)
253
254 /* This one should come in pair with PERL_SYS_INIT() and in the same block */
255 #define PERL_SYS_TERM()                                                 \
256      PERL_SYS_TERM1(xreg);                                              \
257   }
258
259 #ifndef __EMX__
260 #  define PERL_CALLCONV _System
261 #endif
262
263 /* #define PERL_SYS_TERM() STMT_START { \
264     if (Perl_HAB_set) WinTerminate(Perl_hab);   } STMT_END */
265
266 #define dXSUB_SYS OS2_XS_init()
267
268 #ifdef PERL_IS_AOUT
269 /* #  define HAS_FORK */
270 /* #  define HIDEMYMALLOC */
271 /* #  define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
272 #else /* !PERL_IS_AOUT */
273 #  ifndef PERL_FOR_X2P
274 #    ifdef EMX_BAD_SBRK
275 #      define USE_PERL_SBRK
276 #    endif 
277 #  else
278 #    define PerlIO FILE
279 #  endif 
280 #  define SYSTEM_ALLOC(a) sys_alloc(a)
281
282 void *sys_alloc(int size);
283
284 #endif /* !PERL_IS_AOUT */
285 #if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
286 #  define PerlIO FILE
287 #endif 
288
289 /* os2ish is used from a2p/a2p.h without pTHX/pTHX_ first being
290  * defined.  Hack around this to get us to compile.
291 */
292 #ifdef PTHX_UNUSED
293 # ifndef pTHX
294 #  define pTHX
295 # endif
296 # ifndef pTHX_
297 #  define pTHX_
298 # endif
299 #endif
300
301 #define TMPPATH1 "plXXXXXX"
302 extern char *tmppath;
303 PerlIO *my_syspopen(pTHX_ char *cmd, char *mode);
304 /* Cannot prototype with I32 at this point. */
305 int my_syspclose(PerlIO *f);
306 FILE *my_tmpfile (void);
307 char *my_tmpnam (char *);
308 int my_mkdir (__const__ char *, long);
309 int my_rmdir (__const__ char *);
310 struct passwd *my_getpwent (void);
311 void my_setpwent (void);
312 void my_endpwent (void);
313 char *gcvt_os2(double value, int digits, char *buffer);
314
315 struct group *getgrent (void);
316 void setgrent (void);
317 void endgrent (void);
318
319 struct passwd *my_getpwuid (uid_t);
320 struct passwd *my_getpwnam (__const__ char *);
321
322 #undef L_tmpnam
323 #define L_tmpnam MAXPATHLEN
324
325 #define tmpfile my_tmpfile
326 #define tmpnam  my_tmpnam
327 #define isatty  _isterm
328 #define rand    random
329 #define srand   srandom
330 #define strtoll _strtoll
331 #define strtoull        _strtoull
332
333 /*
334  * fwrite1() should be a routine with the same calling sequence as fwrite(),
335  * but which outputs all of the bytes requested as a single stream (unlike
336  * fwrite() itself, which on some systems outputs several distinct records
337  * if the number_of_items parameter is >1).
338  */
339 #define fwrite1 fwrite
340
341 #define my_getenv(var) getenv(var)
342 #define flock   my_flock
343 #define rmdir   my_rmdir
344 #define mkdir   my_mkdir
345 #define setpwent        my_setpwent
346 #define getpwent        my_getpwent
347 #define endpwent        my_endpwent
348 #define getpwuid        my_getpwuid
349 #define getpwnam        my_getpwnam
350
351 void *emx_calloc (size_t, size_t);
352 void emx_free (void *);
353 void *emx_malloc (size_t);
354 void *emx_realloc (void *, size_t);
355
356 /*****************************************************************************/
357
358 #include <stdlib.h>     /* before the following definitions */
359 #include <unistd.h>     /* before the following definitions */
360 #include <fcntl.h>
361 #include <sys/stat.h>
362
363 #define chdir   _chdir2
364 #define getcwd  _getcwd2
365
366 /* This guy is needed for quick stdstd  */
367
368 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
369         /* Perl uses ungetc only with successful return */
370 #  define ungetc(c,fp) \
371         (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
372          ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
373 #endif
374
375 #define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd)
376
377 #ifdef __GNUG__
378 # define HAS_BOOL 
379 #endif
380 #ifndef HAS_BOOL
381 # define bool char
382 # define HAS_BOOL 1
383 #endif
384
385 static inline bool
386 _PERLIO_IS_BINMODE_FD(int fd)
387 {
388     int *pflags = _fd_flags(fd);
389
390     return pflags && (*pflags) & O_BINARY;
391 }
392
393 /* ctermid is missing from emx0.9d */
394 char *ctermid(char *s);
395
396 #define OP_BINARY O_BINARY
397
398 #define OS2_STAT_HACK 1
399 #if OS2_STAT_HACK
400
401 #define Stat(fname,bufptr) os2_stat((fname),(bufptr))
402 #define Fstat(fd,bufptr)   fstat((fd),(bufptr))
403 #define Fflush(fp)         fflush(fp)
404 #define Mkdir(path,mode)   mkdir((path),(mode))
405
406 #undef S_IFBLK
407 #undef S_ISBLK
408 #define S_IFBLK         0120000
409 #define S_ISBLK(mode)   (((mode) & S_IFMT) == S_IFBLK)
410
411 #else
412
413 #define Stat(fname,bufptr) stat((fname),(bufptr))
414 #define Fstat(fd,bufptr)   fstat((fd),(bufptr))
415 #define Fflush(fp)         fflush(fp)
416 #define Mkdir(path,mode)   mkdir((path),(mode))
417
418 #endif
419
420 /* With SD386 it is impossible to debug register variables. */
421 #if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
422 #  define register
423 #endif
424
425 /* Our private OS/2 specific data. */
426
427 typedef struct OS2_Perl_data {
428   unsigned long flags;
429   unsigned long phab;
430   int (*xs_init)();
431   unsigned long rc;
432   unsigned long severity;
433   unsigned long phmq;                   /* Handle to message queue */
434   unsigned long phmq_refcnt;
435   unsigned long phmq_servers;
436   unsigned long initial_mode;           /* VIO etc. mode we were started in */
437 } OS2_Perl_data_t;
438
439 extern OS2_Perl_data_t OS2_Perl_data;
440
441 #define Perl_hab                ((HAB)OS2_Perl_data.phab)
442 #define Perl_rc                 (OS2_Perl_data.rc)
443 #define Perl_severity           (OS2_Perl_data.severity)
444 #define errno_isOS2             12345678
445 #define errno_isOS2_set         12345679
446 #define OS2_Perl_flags  (OS2_Perl_data.flags)
447 #define Perl_HAB_set_f  1
448 #define Perl_HAB_set    (OS2_Perl_flags & Perl_HAB_set_f)
449 #define set_Perl_HAB_f  (OS2_Perl_flags |= Perl_HAB_set_f)
450 #define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
451 #define _obtain_Perl_HAB (init_PMWIN_entries(),                         \
452                           Perl_hab = (*PMWIN_entries.Initialize)(0),    \
453                           set_Perl_HAB_f, Perl_hab)
454 #define perl_hab_GET()  (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB)
455 #define Acquire_hab()   perl_hab_GET()
456 #define Perl_hmq        ((HMQ)OS2_Perl_data.phmq)
457 #define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt)
458 #define Perl_hmq_servers        (OS2_Perl_data.phmq_servers)
459 #define Perl_os2_initial_mode   (OS2_Perl_data.initial_mode)
460
461 unsigned long Perl_hab_GET();
462 unsigned long Perl_Register_MQ(int serve);
463 void    Perl_Deregister_MQ(int serve);
464 int     Perl_Serve_Messages(int force);
465 /* Cannot prototype with I32 at this point. */
466 int     Perl_Process_Messages(int force, long *cntp);
467 char    *os2_execname(pTHX);
468
469 struct _QMSG;
470 struct PMWIN_entries_t {
471     unsigned long (*Initialize)( unsigned long fsOptions );
472     unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg);
473     int (*DestroyMsgQueue)(unsigned long hmq);
474     int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg,
475                    unsigned long hwndFilter, unsigned long msgFilterFirst,
476                    unsigned long msgFilterLast, unsigned long fl);
477     int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg,
478                   unsigned long hwndFilter, unsigned long msgFilterFirst,
479                   unsigned long msgFilterLast);
480     void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg);
481     unsigned long (*GetLastError)(unsigned long hab);
482     unsigned long (*CancelShutdown)(unsigned long hmq, unsigned long fCancelAlways);
483 };
484 extern struct PMWIN_entries_t PMWIN_entries;
485 void init_PMWIN_entries(void);
486
487 #define perl_hmq_GET(serve)     Perl_Register_MQ(serve)
488 #define perl_hmq_UNSET(serve)   Perl_Deregister_MQ(serve)
489
490 #define OS2_XS_init() (*OS2_Perl_data.xs_init)(aTHX)
491
492 #if _EMX_CRT_REV_ >= 60
493 # define os2_setsyserrno(rc)    (Perl_rc = rc, errno = errno_isOS2_set, \
494                                 _setsyserrno(rc))
495 #else
496 # define os2_setsyserrno(rc)    (Perl_rc = rc, errno = errno_isOS2)
497 #endif
498
499 /* The expressions below return true on error. */
500 /* INCL_DOSERRORS needed. rc should be declared outside. */
501 #define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
502 /* INCL_WINERRORS needed. */
503 #define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
504
505 /* This form propagates the return value, setting $^E if needed */
506 #define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
507
508 /* This form propagates the return value, dieing with $^E if needed */
509 #define SaveCroakWinError(expr,die,name1,name2)         \
510   ((expr) ? : (CroakWinError(die,name1 name2), 0))
511
512 #define FillOSError(rc) (os2_setsyserrno(rc),                           \
513                         Perl_severity = SEVERITY_ERROR) 
514
515 #define WinError_2_Perl_rc      \
516  (      init_PMWIN_entries(),   \
517         Perl_rc=(*PMWIN_entries.GetLastError)(perl_hab_GET()) )
518
519 /* Calling WinGetLastError() resets the error code of the current thread.
520    Since for some Win* API return value 0 is normal, one needs to call
521    this before calling them to distinguish normal and anomalous returns.  */
522 /*#define ResetWinError()       WinError_2_Perl_rc */
523
524 /* At this moment init_PMWIN_entries() should be a nop (WinInitialize should
525    be called already, right?), so we do not risk stepping over our own error */
526 #define FillWinError (  WinError_2_Perl_rc,                             \
527                         Perl_severity = ERRORIDSEV(Perl_rc),            \
528                         Perl_rc = ERRORIDERROR(Perl_rc),                \
529                         os2_setsyserrno(Perl_rc))
530
531 #define STATIC_FILE_LENGTH 127
532
533     /* This should match loadOrdinals[] array in os2.c */
534 enum entries_ordinals {
535     ORD_DosQueryExtLibpath,
536     ORD_DosSetExtLibpath,
537     ORD_DosVerifyPidTid,
538     ORD_SETHOSTENT,
539     ORD_SETNETENT, 
540     ORD_SETPROTOENT,
541     ORD_SETSERVENT,
542     ORD_GETHOSTENT,
543     ORD_GETNETENT, 
544     ORD_GETPROTOENT,
545     ORD_GETSERVENT,
546     ORD_ENDHOSTENT,
547     ORD_ENDNETENT,
548     ORD_ENDPROTOENT,
549     ORD_ENDSERVENT,
550     ORD_WinInitialize,
551     ORD_WinCreateMsgQueue,
552     ORD_WinDestroyMsgQueue,
553     ORD_WinPeekMsg,
554     ORD_WinGetMsg,
555     ORD_WinDispatchMsg,
556     ORD_WinGetLastError,
557     ORD_WinCancelShutdown,
558     ORD_RexxStart,
559     ORD_RexxVariablePool,
560     ORD_RexxRegisterFunctionExe,
561     ORD_RexxDeregisterFunction,
562     ORD_DOSSMSETTITLE,
563     ORD_PRF32QUERYPROFILESIZE,
564     ORD_PRF32OPENPROFILE,
565     ORD_PRF32CLOSEPROFILE,
566     ORD_PRF32QUERYPROFILE,
567     ORD_PRF32RESET,
568     ORD_PRF32QUERYPROFILEDATA,
569     ORD_PRF32WRITEPROFILEDATA,
570
571     ORD_WinChangeSwitchEntry,
572     ORD_WinQuerySwitchEntry,
573     ORD_WinQuerySwitchHandle,
574     ORD_WinQuerySwitchList,
575     ORD_WinSwitchToProgram,
576     ORD_WinBeginEnumWindows,
577     ORD_WinEndEnumWindows,
578     ORD_WinEnumDlgItem,
579     ORD_WinGetNextWindow,
580     ORD_WinIsChild,
581     ORD_WinQueryActiveWindow,
582     ORD_WinQueryClassName,
583     ORD_WinQueryFocus,
584     ORD_WinQueryWindow,
585     ORD_WinQueryWindowPos,
586     ORD_WinQueryWindowProcess,
587     ORD_WinQueryWindowText,
588     ORD_WinQueryWindowTextLength,
589     ORD_WinSetFocus,
590     ORD_WinSetWindowPos,
591     ORD_WinSetWindowText,
592     ORD_WinShowWindow,
593     ORD_WinIsWindow,
594     ORD_WinWindowFromId,
595     ORD_WinWindowFromPoint,
596     ORD_WinPostMsg,
597     ORD_WinEnableWindow,
598     ORD_WinEnableWindowUpdate,
599     ORD_WinIsWindowEnabled,
600     ORD_WinIsWindowShowing,
601     ORD_WinIsWindowVisible,
602     ORD_WinQueryWindowPtr,
603     ORD_WinQueryWindowULong,
604     ORD_WinQueryWindowUShort,
605     ORD_WinSetWindowBits,
606     ORD_WinSetWindowPtr,
607     ORD_WinSetWindowULong,
608     ORD_WinSetWindowUShort,
609     ORD_WinQueryDesktopWindow,
610     ORD_WinSetActiveWindow,
611     ORD_DosQueryModFromEIP,
612     ORD_NENTRIES
613 };
614
615 /* RET: return type, AT: argument signature in (), ARGS: should be in () */
616 #define CallORD(ret,o,at,args)  (((ret (*)at) loadByOrdinal(o, 1))args)
617 #define DeclFuncByORD(ret,name,o,at,args)       \
618   ret name at { return CallORD(ret,o,at,args); }
619 #define DeclVoidFuncByORD(name,o,at,args)       \
620   void name at { CallORD(void,o,at,args); }
621
622 /* These functions return false on error, and save the error info in $^E */
623 #define DeclOSFuncByORD(ret,name,o,at,args)     \
624   ret name at { unsigned long rc; return !CheckOSError(CallORD(ret,o,at,args)); }
625 #define DeclWinFuncByORD(ret,name,o,at,args)    \
626   ret name at { return SaveWinError(CallORD(ret,o,at,args)); }
627
628 #define AssignFuncPByORD(p,o)   (*(Perl_PFN*)&(p) = (loadByOrdinal(o, 1)))
629
630 /* This flavor caches the procedure pointer (named as p__Win#name) locally */
631 #define DeclWinFuncByORD_CACHE(ret,name,o,at,args)      \
632         DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,1)
633
634 /* This flavor may reset the last error before the call (if ret=0 may be OK) */
635 #define DeclWinFuncByORD_CACHE_resetError(ret,name,o,at,args)   \
636         DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,1)
637
638 /* Two flavors below do the same as above, but do not auto-croak */
639 /* This flavor caches the procedure pointer (named as p__Win#name) locally */
640 #define DeclWinFuncByORD_CACHE_survive(ret,name,o,at,args)      \
641         DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,0)
642
643 /* This flavor may reset the last error before the call (if ret=0 may be OK) */
644 #define DeclWinFuncByORD_CACHE_resetError_survive(ret,name,o,at,args)   \
645         DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,0)
646
647 #define DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,r,die)      \
648   static ret (*CAT2(p__Win,name)) at;                           \
649   static ret name at {                                          \
650         if (!CAT2(p__Win,name))                                 \
651             AssignFuncPByORD(CAT2(p__Win,name), o);             \
652         if (r) ResetWinError();                                 \
653         return SaveCroakWinError(CAT2(p__Win,name) args, die, "[Win]", STRINGIFY(name)); }
654
655 /* These flavors additionally assume ORD is name with prepended ORD_Win  */
656 #define DeclWinFunc_CACHE(ret,name,at,args)     \
657         DeclWinFuncByORD_CACHE(ret,name,CAT2(ORD_Win,name),at,args)
658 #define DeclWinFunc_CACHE_resetError(ret,name,at,args)  \
659         DeclWinFuncByORD_CACHE_resetError(ret,name,CAT2(ORD_Win,name),at,args)
660 #define DeclWinFunc_CACHE_survive(ret,name,at,args)     \
661         DeclWinFuncByORD_CACHE_survive(ret,name,CAT2(ORD_Win,name),at,args)
662 #define DeclWinFunc_CACHE_resetError_survive(ret,name,at,args)  \
663         DeclWinFuncByORD_CACHE_resetError_survive(ret,name,CAT2(ORD_Win,name),at,args)
664
665 void ResetWinError(void);
666 void CroakWinError(int die, char *name);
667
668 #define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
669 char *perllib_mangle(char *, unsigned int);
670
671 typedef int (*Perl_PFN)();
672 Perl_PFN loadByOrdinal(enum entries_ordinals ord, int fail);
673 extern const Perl_PFN * const pExtFCN;
674 char *os2error(int rc);
675 int os2_stat(const char *name, struct stat *st);
676 int setpriority(int which, int pid, int val);
677 int getpriority(int which /* ignored */, int pid);
678
679 #ifdef PERL_CORE
680 int os2_do_spawn(pTHX_ char *cmd);
681 int os2_do_aspawn(pTHX_ SV *really, void **vmark, void **vsp);
682 #endif
683
684 #ifndef LOG_DAEMON
685
686 /* Replacement for syslog.h */
687 #  define       LOG_EMERG       0       /* system is unusable */
688 #  define       LOG_ALERT       1       /* action must be taken immediately */
689 #  define       LOG_CRIT        2       /* critical conditions */
690 #  define       LOG_ERR 3       /* error conditions */
691 #  define       LOG_WARNING     4       /* warning conditions */
692 #  define       LOG_NOTICE      5       /* normal but significant condition */
693 #  define       LOG_INFO        6       /* informational */
694 #  define       LOG_DEBUG       7       /* debug-level messages */
695
696 #  define       LOG_PRIMASK     0x007   /* mask to extract priority part (internal) */
697                                 /* extract priority */
698 #  define       LOG_PRI(p)      ((p) & LOG_PRIMASK)
699 #  define       LOG_MAKEPRI(fac, pri)   (((fac) << 3) | (pri))
700
701 /* facility codes */
702 #  define       LOG_KERN        (0<<3)  /* kernel messages */
703 #  define       LOG_USER        (1<<3)  /* random user-level messages */
704 #  define       LOG_MAIL        (2<<3)  /* mail system */
705 #  define       LOG_DAEMON      (3<<3)  /* system daemons */
706 #  define       LOG_AUTH        (4<<3)  /* security/authorization messages */
707 #  define       LOG_SYSLOG      (5<<3)  /* messages generated internally by syslogd */
708 #  define       LOG_LPR (6<<3)  /* line printer subsystem */
709 #  define       LOG_NEWS        (7<<3)  /* network news subsystem */
710 #  define       LOG_UUCP        (8<<3)  /* UUCP subsystem */
711 #  define       LOG_CRON        (15<<3) /* clock daemon */
712         /* other codes through 15 reserved for system use */
713 #  define       LOG_LOCAL0      (16<<3) /* reserved for local use */
714 #  define       LOG_LOCAL1      (17<<3) /* reserved for local use */
715 #  define       LOG_LOCAL2      (18<<3) /* reserved for local use */
716 #  define       LOG_LOCAL3      (19<<3) /* reserved for local use */
717 #  define       LOG_LOCAL4      (20<<3) /* reserved for local use */
718 #  define       LOG_LOCAL5      (21<<3) /* reserved for local use */
719 #  define       LOG_LOCAL6      (22<<3) /* reserved for local use */
720 #  define       LOG_LOCAL7      (23<<3) /* reserved for local use */
721
722 #  define       LOG_NFACILITIES 24      /* current number of facilities */
723 #  define       LOG_FACMASK     0x03f8  /* mask to extract facility part */
724                                 /* facility of pri */
725 #  define       LOG_FAC(p)      (((p) & LOG_FACMASK) >> 3)
726
727 /*
728  * arguments to setlogmask.
729  */
730 #  define       LOG_MASK(pri)   (1 << (pri))            /* mask for one priority */
731 #  define       LOG_UPTO(pri)   ((1 << ((pri)+1)) - 1)  /* all priorities through pri */
732
733 /*
734  * Option flags for openlog.
735  *
736  * LOG_ODELAY no longer does anything.
737  * LOG_NDELAY is the inverse of what it used to be.
738  */
739 #  define       LOG_PID         0x01    /* log the pid with each message */
740 #  define       LOG_CONS        0x02    /* log on the console if errors in sending */
741 #  define       LOG_ODELAY      0x04    /* delay open until first syslog() (default) */
742 #  define       LOG_NDELAY      0x08    /* don't delay open */
743 #  define       LOG_NOWAIT      0x10    /* don't wait for console forks: DEPRECATED */
744 #  define       LOG_PERROR      0x20    /* log to stderr as well */
745
746 #endif
747
748 /* ************************************************************ */
749 #define Dos32QuerySysState DosQuerySysState
750 #define QuerySysState(flags, pid, buf, bufsz) \
751         Dos32QuerySysState(flags, 0,  pid, 0, buf, bufsz)
752
753 #define QSS_PROCESS     1
754 #define QSS_MODULE      4
755 #define QSS_SEMAPHORES  2
756 #define QSS_FILE        8               /* Buggy until fixpack18 */
757 #define QSS_SHARED      16
758
759 #ifdef _OS2_H
760
761 APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
762                         ULONG _res_,PVOID buf,ULONG bufsz);
763 typedef struct {
764         ULONG   threadcnt;
765         ULONG   proccnt;
766         ULONG   modulecnt;
767 } QGLOBAL, *PQGLOBAL;
768
769 typedef struct {
770         ULONG   rectype;
771         USHORT  threadid;
772         USHORT  slotid;
773         ULONG   sleepid;
774         ULONG   priority;
775         ULONG   systime;
776         ULONG   usertime;
777         UCHAR   state;
778         UCHAR   _reserved1_;    /* padding to ULONG */
779         USHORT  _reserved2_;    /* padding to ULONG */
780 } QTHREAD, *PQTHREAD;
781
782 typedef struct {
783         USHORT  sfn;
784         USHORT  refcnt;
785         USHORT  flags1;
786         USHORT  flags2;
787         USHORT  accmode1;
788         USHORT  accmode2;
789         ULONG   filesize;
790         USHORT  volhnd;
791         USHORT  attrib;
792         USHORT  _reserved_;
793 } QFDS, *PQFDS;
794
795 typedef struct qfile {
796         ULONG           rectype;
797         struct qfile    *next;
798         ULONG           opencnt;
799         PQFDS           filedata;
800         char            name[1];
801 } QFILE, *PQFILE;
802
803 typedef struct {
804         ULONG   rectype;
805         PQTHREAD threads;
806         USHORT  pid;
807         USHORT  ppid;
808         ULONG   type;
809         ULONG   state;
810         ULONG   sessid;
811         USHORT  hndmod;
812         USHORT  threadcnt;
813         ULONG   privsem32cnt;
814         ULONG   _reserved2_;
815         USHORT  sem16cnt;
816         USHORT  dllcnt;
817         USHORT  shrmemcnt;
818         USHORT  fdscnt;
819         PUSHORT sem16s;
820         PUSHORT dlls;
821         PUSHORT shrmems;
822         PUSHORT fds;
823 } QPROCESS, *PQPROCESS;
824
825 typedef struct sema {
826         struct sema *next;
827         USHORT  refcnt;
828         UCHAR   sysflags;
829         UCHAR   sysproccnt;
830         ULONG   _reserved1_;
831         USHORT  index;
832         CHAR    name[1];
833 } QSEMA, *PQSEMA;
834
835 typedef struct {
836         ULONG   rectype;
837         ULONG   _reserved1_;
838         USHORT  _reserved2_;
839         USHORT  syssemidx;
840         ULONG   index;
841         QSEMA   sema;
842 } QSEMSTRUC, *PQSEMSTRUC;
843
844 typedef struct {
845         USHORT  pid;
846         USHORT  opencnt;
847 } QSEMOWNER32, *PQSEMOWNER32;
848
849 typedef struct {
850         PQSEMOWNER32    own;
851         PCHAR           name;
852         PVOID           semrecs; /* array of associated sema's */
853         USHORT          flags;
854         USHORT          semreccnt;
855         USHORT          waitcnt;
856         USHORT          _reserved_;     /* padding to ULONG */
857 } QSEMSMUX32, *PQSEMSMUX32;
858
859 typedef struct {
860         PQSEMOWNER32    own;
861         PCHAR           name;
862         PQSEMSMUX32     mux;
863         USHORT          flags;
864         USHORT          postcnt;
865 } QSEMEV32, *PQSEMEV32;
866
867 typedef struct {
868         PQSEMOWNER32    own;
869         PCHAR           name;
870         PQSEMSMUX32     mux;
871         USHORT          flags;
872         USHORT          refcnt;
873         USHORT          thrdnum;
874         USHORT          _reserved_;     /* padding to ULONG */
875 } QSEMMUX32, *PQSEMMUX32;
876
877 typedef struct semstr32 {
878         struct semstr *next;
879         QSEMEV32 evsem;
880         QSEMMUX32  muxsem;
881         QSEMSMUX32 smuxsem;
882 } QSEMSTRUC32, *PQSEMSTRUC32;
883
884 typedef struct shrmem {
885         struct shrmem *next;
886         USHORT  hndshr;
887         USHORT  selshr;
888         USHORT  refcnt;
889         CHAR    name[1];
890 } QSHRMEM, *PQSHRMEM;
891
892 typedef struct module {
893         struct module *next;
894         USHORT  hndmod;
895         USHORT  type;
896         ULONG   refcnt;
897         ULONG   segcnt;
898         PVOID   _reserved_;
899         PCHAR   name;
900         USHORT  modref[1];
901 } QMODULE, *PQMODULE;
902
903 typedef struct {
904         PQGLOBAL        gbldata;
905         PQPROCESS       procdata;
906         PQSEMSTRUC      semadata;
907         PQSEMSTRUC32    sem32data;
908         PQSHRMEM        shrmemdata;
909         PQMODULE        moddata;
910         PVOID           _reserved2_;
911         PQFILE          filedata;
912 } QTOPLEVEL, *PQTOPLEVEL;
913 /* ************************************************************ */
914
915 PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
916
917 #endif /* _OS2_H */
918