This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sysconf.t: still failing in tru64, try harder to skip
[perl5.git] / os2 / os2ish.h
CommitLineData
4633a7c4 1#include <signal.h>
2d766320
IZ
2#include <io.h>
3/* #include <sys/select.h> */
4633a7c4
LW
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
a80d47c2
IZ
17/* BIG_TIME:
18 * This symbol is defined if Time_t is an unsigned type on this system.
19 */
20#define BIG_TIME
21
4633a7c4
LW
22#define HAS_KILL
23#define HAS_WAIT
4ea6d94f 24#define HAS_DLERROR
367f3c24 25#define HAS_WAITPID_RUNTIME (_emx_env & 0x200)
4ea6d94f 26
f72c975a
IZ
27/* HAS_PASSWD
28 * This symbol, if defined, indicates that the getpwnam() and
29 * getpwuid() routines are available to get password entries.
30 * The getpwent() has a separate definition, HAS_GETPWENT.
31 */
32#define HAS_PASSWD
33
34/* HAS_GROUP
35 * This symbol, if defined, indicates that the getgrnam() and
36 * getgrgid() routines are available to get group entries.
37 * The getgrent() has a separate definition, HAS_GETGRENT.
38 */
39#define HAS_GROUP
40#define HAS_GETGRENT /* fake */
41#define HAS_SETGRENT /* fake */
42#define HAS_ENDGRENT /* fake */
43
4ea6d94f 44/* USEMYBINMODE
45 * This symbol, if defined, indicates that the program should
16fe6d59 46 * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
4ea6d94f 47 * that a file is in "binary" mode -- that is, that no translation
48 * of bytes occurs on read or write operations.
49 */
50#undef USEMYBINMODE
51
460c8493
IZ
52#define SOCKET_OPEN_MODE "b"
53
61bb5906
CB
54/* Stat_t:
55 * This symbol holds the type used to declare buffers for information
56 * returned by stat(). It's usually just struct stat. It may be necessary
57 * to include <sys/stat.h> and <sys/types.h> to get any typedef'ed
58 * information.
59 */
60#define Stat_t struct stat
61
4ea6d94f 62/* USE_STAT_RDEV:
63 * This symbol is defined if this system has a stat structure declaring
64 * st_rdev
65 */
66#define USE_STAT_RDEV /**/
67
68/* ACME_MESS:
69 * This symbol, if defined, indicates that error messages should be
70 * should be generated in a format that allows the use of the Acme
71 * GUI/editor's autofind feature.
72 */
73#undef ACME_MESS /**/
4633a7c4 74
44a8e56a 75/* ALTERNATE_SHEBANG:
76 * This symbol, if defined, contains a "magic" string which may be used
77 * as the first line of a Perl program designed to be executed directly
78 * by name, instead of the standard Unix #!. If ALTERNATE_SHEBANG
79 * begins with a character other then #, then Perl will only treat
80 * it as a command line if if finds the string "perl" in the first
81 * word; otherwise it's treated as the first line of code in the script.
82 * (IOW, Perl won't hand off to another interpreter via an alternate
83 * shebang sequence that might be legal Perl code.)
84 */
aa689395 85#define ALTERNATE_SHEBANG "extproc "
44a8e56a 86
4633a7c4
LW
87#ifndef SIGABRT
88# define SIGABRT SIGILL
89#endif
90#ifndef SIGILL
91# define SIGILL 6 /* blech */
92#endif
7766f137 93#define ABORT() kill(PerlProc_getpid(),SIGABRT);
4633a7c4 94
760ac839 95#define BIT_BUCKET "/dev/nul" /* Will this work? */
c07a80fd 96
202975e6
IZ
97/* Apparently TCPIPV4 defines may be included even with only IAK present */
98
99#if !defined(NO_TCPIPV4) && !defined(TCPIPV4)
100# define TCPIPV4
101# define TCPIPV4_FORCED /* Just in case */
102#endif
103
4a6a15c8
IZ
104#if defined(I_SYS_UN) && !defined(TCPIPV4)
105/* It is not working without TCPIPV4 defined. */
106# undef I_SYS_UN
107#endif
dd96f567 108
5c728af0
IZ
109#ifdef USE_ITHREADS
110
111#define do_spawn(a) os2_do_spawn(aTHX_ (a))
112#define do_aspawn(a,b,c) os2_do_aspawn(aTHX_ (a),(b),(c))
113
114#define OS2_ERROR_ALREADY_POSTED 299 /* Avoid os2.h */
115
116extern int rc;
117
118#define MUTEX_INIT(m) \
119 STMT_START { \
120 int rc; \
121 if ((rc = _rmutex_create(m,0))) \
122 Perl_croak_nocontext("panic: MUTEX_INIT: rc=%i", rc); \
123 } STMT_END
124#define MUTEX_LOCK(m) \
125 STMT_START { \
126 int rc; \
127 if ((rc = _rmutex_request(m,_FMR_IGNINT))) \
128 Perl_croak_nocontext("panic: MUTEX_LOCK: rc=%i", rc); \
129 } STMT_END
130#define MUTEX_UNLOCK(m) \
131 STMT_START { \
132 int rc; \
133 if ((rc = _rmutex_release(m))) \
134 Perl_croak_nocontext("panic: MUTEX_UNLOCK: rc=%i", rc); \
135 } STMT_END
136#define MUTEX_DESTROY(m) \
137 STMT_START { \
138 int rc; \
139 if ((rc = _rmutex_close(m))) \
140 Perl_croak_nocontext("panic: MUTEX_DESTROY: rc=%i", rc); \
141 } STMT_END
142
143#define COND_INIT(c) \
144 STMT_START { \
145 int rc; \
146 if ((rc = DosCreateEventSem(NULL,c,0,0))) \
147 Perl_croak_nocontext("panic: COND_INIT: rc=%i", rc); \
148 } STMT_END
149#define COND_SIGNAL(c) \
150 STMT_START { \
151 int rc; \
152 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
153 Perl_croak_nocontext("panic: COND_SIGNAL, rc=%ld", rc); \
154 } STMT_END
155#define COND_BROADCAST(c) \
156 STMT_START { \
157 int rc; \
158 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
159 Perl_croak_nocontext("panic: COND_BROADCAST, rc=%i", rc); \
160 } STMT_END
161/* #define COND_WAIT(c, m) \
162 STMT_START { \
163 if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \
164 Perl_croak_nocontext("panic: COND_WAIT"); \
165 } STMT_END
166*/
167#define COND_WAIT(c, m) os2_cond_wait(c,m)
168
169#define COND_WAIT_win32(c, m) \
170 STMT_START { \
171 int rc; \
172 if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE))) \
173 Perl_croak_nocontext("panic: COND_WAIT"); \
174 else \
175 MUTEX_LOCK(m); \
176 } STMT_END
177#define COND_DESTROY(c) \
178 STMT_START { \
179 int rc; \
180 if ((rc = DosCloseEventSem(*(c)))) \
181 Perl_croak_nocontext("panic: COND_DESTROY, rc=%i", rc); \
182 } STMT_END
183/*#define THR ((struct thread *) TlsGetValue(PL_thr_key))
184*/
185
186#ifdef USE_SLOW_THREAD_SPECIFIC
187# define pthread_getspecific(k) (*_threadstore())
188# define pthread_setspecific(k,v) (*_threadstore()=v,0)
189# define pthread_key_create(keyp,flag) (*keyp=_gettid(),0)
190#else /* USE_SLOW_THREAD_SPECIFIC */
191# define pthread_getspecific(k) (*(k))
192# define pthread_setspecific(k,v) (*(k)=(v),0)
193# define pthread_key_create(keyp,flag) \
194 ( DosAllocThreadLocalMemory(1,(unsigned long**)keyp) \
195 ? Perl_croak_nocontext("LocalMemory"),1 \
196 : 0 \
197 )
198#endif /* USE_SLOW_THREAD_SPECIFIC */
199#define pthread_key_delete(keyp)
200#define pthread_self() _gettid()
201#define YIELD DosSleep(0)
202
203#ifdef PTHREADS_INCLUDED /* For ./x2p stuff. */
204int pthread_join(pthread_t tid, void **status);
205int pthread_detach(pthread_t tid);
206int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
207 void *(*start_routine)(void*), void *arg);
208#endif /* PTHREAD_INCLUDED */
209
210#define THREADS_ELSEWHERE
211
212#else /* USE_ITHREADS */
213
23da6c43
GS
214#define do_spawn(a) os2_do_spawn(a)
215#define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c))
4a6a15c8 216
aa689395 217void Perl_OS2_init(char **);
764df951
IZ
218void Perl_OS2_init3(char **envp, void **excH, int flags);
219void Perl_OS2_term(void **excH, int exitstatus, int flags);
aa689395 220
764df951 221/* The code without INIT3 hideously puts env inside: */
365eb7b5 222
764df951 223/* These ones should be in the same block as PERL_SYS_TERM() */
ed344e4f 224#ifdef PERL_CORE
764df951
IZ
225
226# define PERL_SYS_INIT3(argcp, argvp, envp) \
227 { void *xreg[2]; \
22f7c9c9 228 MALLOC_CHECK_TAINT(*argcp, *argvp, *envp) \
ed344e4f
IZ
229 _response(argcp, argvp); \
230 _wildcard(argcp, argvp); \
764df951
IZ
231 Perl_OS2_init3(*envp, xreg, 0)
232
233# define PERL_SYS_INIT(argcp, argvp) { \
234 { void *xreg[2]; \
eacfb5f1 235 _response(argcp, argvp); \
c0c09dfd 236 _wildcard(argcp, argvp); \
764df951
IZ
237 Perl_OS2_init3(NULL, xreg, 0)
238
ed344e4f 239#else /* Compiling embedded Perl or Perl extension */
764df951
IZ
240
241# define PERL_SYS_INIT3(argcp, argvp, envp) \
242 { void *xreg[2]; \
243 Perl_OS2_init3(*envp, xreg, 0)
244# define PERL_SYS_INIT(argcp, argvp) { \
245 { void *xreg[2]; \
246 Perl_OS2_init3(NULL, xreg, 0)
ed344e4f
IZ
247#endif
248
764df951
IZ
249#define FORCE_EMX_DEINIT_EXIT 1
250#define FORCE_EMX_DEINIT_CRT_TERM 2
251#define FORCE_EMX_DEINIT_RUN_ATEXIT 4
252
253#define PERL_SYS_TERM2(xreg,flags) \
254 Perl_OS2_term(xreg, 0, flags); \
255 MALLOC_TERM
256
257#define PERL_SYS_TERM1(xreg) \
258 Perl_OS2_term(xreg, 0, FORCE_EMX_DEINIT_RUN_ATEXIT)
259
260/* This one should come in pair with PERL_SYS_INIT() and in the same block */
261#define PERL_SYS_TERM() \
262 PERL_SYS_TERM1(xreg); \
263 }
264
ed344e4f 265#ifndef __EMX__
aab1f907
IZ
266# define PERL_CALLCONV _System
267#endif
ed344e4f 268
4ea6d94f 269/* #define PERL_SYS_TERM() STMT_START { \
270 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
271
8cc95fdb 272#define dXSUB_SYS OS2_XS_init()
eacfb5f1 273
4ea6d94f 274#ifdef PERL_IS_AOUT
4a6a15c8 275/* # define HAS_FORK */
760ac839
LW
276/* # define HIDEMYMALLOC */
277/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
278#else /* !PERL_IS_AOUT */
279# ifndef PERL_FOR_X2P
4a6a15c8
IZ
280# ifdef EMX_BAD_SBRK
281# define USE_PERL_SBRK
282# endif
283# else
284# define PerlIO FILE
760ac839
LW
285# endif
286# define SYSTEM_ALLOC(a) sys_alloc(a)
287
288void *sys_alloc(int size);
289
290#endif /* !PERL_IS_AOUT */
4a6a15c8
IZ
291#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
292# define PerlIO FILE
293#endif
4ea6d94f 294
23da6c43
GS
295/* os2ish is used from a2p/a2p.h without pTHX/pTHX_ first being
296 * defined. Hack around this to get us to compile.
297*/
298#ifdef PTHX_UNUSED
299# ifndef pTHX
300# define pTHX
301# endif
302# ifndef pTHX_
303# define pTHX_
304# endif
305#endif
306
c0c09dfd 307#define TMPPATH1 "plXXXXXX"
622913ab 308extern const char *tmppath;
23da6c43 309PerlIO *my_syspopen(pTHX_ char *cmd, char *mode);
4a6a15c8
IZ
310/* Cannot prototype with I32 at this point. */
311int my_syspclose(PerlIO *f);
55497cff 312FILE *my_tmpfile (void);
313char *my_tmpnam (char *);
5ba48348
JH
314int my_mkdir (__const__ char *, long);
315int my_rmdir (__const__ char *);
f72c975a
IZ
316struct passwd *my_getpwent (void);
317void my_setpwent (void);
318void my_endpwent (void);
a64c954a 319char *gcvt_os2(double value, int digits, char *buffer);
f72c975a 320
1933e12c
IZ
321extern int async_mssleep(unsigned long ms, int switch_priority);
322extern unsigned long msCounter(void);
323extern unsigned long InfoTable(int local);
324extern unsigned long find_myself(void);
325
622913ab
IZ
326#define MAX_SLEEP (((1<30) / (1000/4))-1) /* 1<32 msec */
327
328static __inline__ unsigned
329my_sleep(unsigned sec)
330{
331 int remain;
332 while (sec > MAX_SLEEP) {
333 sec -= MAX_SLEEP;
334 remain = sleep(MAX_SLEEP);
335 if (remain)
336 return remain + sec;
337 }
338 return sleep(sec);
339}
340
341#define sleep my_sleep
342
343#ifndef INCL_DOS
344unsigned long DosSleep(unsigned long);
345unsigned long DosAllocThreadLocalMemory (unsigned long cb, unsigned long **p);
346#endif
347
f72c975a
IZ
348struct group *getgrent (void);
349void setgrent (void);
350void endgrent (void);
351
352struct passwd *my_getpwuid (uid_t);
353struct passwd *my_getpwnam (__const__ char *);
55497cff 354
bddf7535
GS
355#undef L_tmpnam
356#define L_tmpnam MAXPATHLEN
357
55497cff 358#define tmpfile my_tmpfile
359#define tmpnam my_tmpnam
3ed26a2c 360#define isatty _isterm
44a8e56a 361#define rand random
362#define srand srandom
e75931a7
YST
363#define strtoll _strtoll
364#define strtoull _strtoull
eacfb5f1 365
1933e12c 366#define usleep(usec) ((void)async_mssleep(((usec)+500)/1000, 500))
622913ab
IZ
367
368
4633a7c4
LW
369/*
370 * fwrite1() should be a routine with the same calling sequence as fwrite(),
371 * but which outputs all of the bytes requested as a single stream (unlike
372 * fwrite() itself, which on some systems outputs several distinct records
373 * if the number_of_items parameter is >1).
374 */
375#define fwrite1 fwrite
376
377#define my_getenv(var) getenv(var)
367f3c24 378#define flock my_flock
5ba48348
JH
379#define rmdir my_rmdir
380#define mkdir my_mkdir
f72c975a
IZ
381#define setpwent my_setpwent
382#define getpwent my_getpwent
383#define endpwent my_endpwent
384#define getpwuid my_getpwuid
385#define getpwnam my_getpwnam
4633a7c4 386
df3ef7a9
IZ
387void *emx_calloc (size_t, size_t);
388void emx_free (void *);
389void *emx_malloc (size_t);
390void *emx_realloc (void *, size_t);
391
4633a7c4
LW
392/*****************************************************************************/
393
394#include <stdlib.h> /* before the following definitions */
395#include <unistd.h> /* before the following definitions */
21cdd7e3
JH
396#include <fcntl.h>
397#include <sys/stat.h>
4633a7c4
LW
398
399#define chdir _chdir2
400#define getcwd _getcwd2
401
402/* This guy is needed for quick stdstd */
403
404#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4
LW
405 /* Perl uses ungetc only with successful return */
406# define ungetc(c,fp) \
407 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
408 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
409#endif
410
23b84778
IZ
411#define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd)
412
9c75282f
JH
413#ifdef __GNUG__
414# define HAS_BOOL
415#endif
416#ifndef HAS_BOOL
417# define bool char
418# define HAS_BOOL 1
419#endif
420
ab8d95c9 421#include <emx/io.h> /* for _fd_flags() prototype */
377cf4e9 422
23b84778
IZ
423static inline bool
424_PERLIO_IS_BINMODE_FD(int fd)
425{
426 int *pflags = _fd_flags(fd);
427
428 return pflags && (*pflags) & O_BINARY;
429}
430
46e87256
YST
431/* ctermid is missing from emx0.9d */
432char *ctermid(char *s);
433
4633a7c4
LW
434#define OP_BINARY O_BINARY
435
436#define OS2_STAT_HACK 1
437#if OS2_STAT_HACK
438
439#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
5c728af0 440#define Fstat(fd,bufptr) os2_fstat((fd),(bufptr))
365eb7b5 441#define Fflush(fp) fflush(fp)
8cc95fdb 442#define Mkdir(path,mode) mkdir((path),(mode))
5c728af0 443#define chmod(path,mode) os2_chmod((path),(mode))
4633a7c4
LW
444
445#undef S_IFBLK
446#undef S_ISBLK
5c728af0 447#define S_IFBLK 0120000 /* Hacks to make things compile... */
4633a7c4
LW
448#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
449
5c728af0
IZ
450int os2_chmod(const char *name, int pmode);
451int os2_fstat(int handle, struct stat *st);
452
4633a7c4
LW
453#else
454
455#define Stat(fname,bufptr) stat((fname),(bufptr))
456#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 457#define Fflush(fp) fflush(fp)
8cc95fdb 458#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4
LW
459
460#endif
365eb7b5 461
44a8e56a 462/* With SD386 it is impossible to debug register variables. */
463#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
464# define register
465#endif
466
365eb7b5 467/* Our private OS/2 specific data. */
468
469typedef struct OS2_Perl_data {
470 unsigned long flags;
471 unsigned long phab;
472 int (*xs_init)();
4ea6d94f 473 unsigned long rc;
474 unsigned long severity;
4bfbfac5
IZ
475 unsigned long phmq; /* Handle to message queue */
476 unsigned long phmq_refcnt;
477 unsigned long phmq_servers;
478 unsigned long initial_mode; /* VIO etc. mode we were started in */
622913ab 479 unsigned long morph_refcnt;
365eb7b5 480} OS2_Perl_data_t;
481
482extern OS2_Perl_data_t OS2_Perl_data;
483
4ea6d94f 484#define Perl_hab ((HAB)OS2_Perl_data.phab)
485#define Perl_rc (OS2_Perl_data.rc)
486#define Perl_severity (OS2_Perl_data.severity)
487#define errno_isOS2 12345678
ed344e4f 488#define errno_isOS2_set 12345679
4ea6d94f 489#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 490#define Perl_HAB_set_f 1
4ea6d94f 491#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
492#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
493#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
4bfbfac5
IZ
494#define _obtain_Perl_HAB (init_PMWIN_entries(), \
495 Perl_hab = (*PMWIN_entries.Initialize)(0), \
496 set_Perl_HAB_f, Perl_hab)
497#define perl_hab_GET() (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB)
498#define Acquire_hab() perl_hab_GET()
499#define Perl_hmq ((HMQ)OS2_Perl_data.phmq)
500#define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt)
501#define Perl_hmq_servers (OS2_Perl_data.phmq_servers)
502#define Perl_os2_initial_mode (OS2_Perl_data.initial_mode)
622913ab 503#define Perl_morph_refcnt (OS2_Perl_data.morph_refcnt)
4bfbfac5
IZ
504
505unsigned long Perl_hab_GET();
506unsigned long Perl_Register_MQ(int serve);
507void Perl_Deregister_MQ(int serve);
508int Perl_Serve_Messages(int force);
509/* Cannot prototype with I32 at this point. */
510int Perl_Process_Messages(int force, long *cntp);
23da6c43 511char *os2_execname(pTHX);
4bfbfac5
IZ
512
513struct _QMSG;
514struct PMWIN_entries_t {
515 unsigned long (*Initialize)( unsigned long fsOptions );
516 unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg);
517 int (*DestroyMsgQueue)(unsigned long hmq);
518 int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg,
519 unsigned long hwndFilter, unsigned long msgFilterFirst,
520 unsigned long msgFilterLast, unsigned long fl);
521 int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg,
522 unsigned long hwndFilter, unsigned long msgFilterFirst,
523 unsigned long msgFilterLast);
524 void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg);
5ba48348
JH
525 unsigned long (*GetLastError)(unsigned long hab);
526 unsigned long (*CancelShutdown)(unsigned long hmq, unsigned long fCancelAlways);
4bfbfac5
IZ
527};
528extern struct PMWIN_entries_t PMWIN_entries;
529void init_PMWIN_entries(void);
530
ed344e4f
IZ
531#define perl_hmq_GET(serve) Perl_Register_MQ(serve)
532#define perl_hmq_UNSET(serve) Perl_Deregister_MQ(serve)
4bfbfac5 533
23da6c43 534#define OS2_XS_init() (*OS2_Perl_data.xs_init)(aTHX)
ed344e4f
IZ
535
536#if _EMX_CRT_REV_ >= 60
537# define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2_set, \
538 _setsyserrno(rc))
539#else
540# define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2)
541#endif
542
4ea6d94f 543/* The expressions below return true on error. */
4a6a15c8 544/* INCL_DOSERRORS needed. rc should be declared outside. */
4ab57fcb 545#define CheckOSError(expr) ((rc = (expr)) ? (FillOSError(rc), rc) : 0)
4ea6d94f 546/* INCL_WINERRORS needed. */
4ea6d94f 547#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
30500b05
IZ
548
549/* This form propagates the return value, setting $^E if needed */
550#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
551
552/* This form propagates the return value, dieing with $^E if needed */
553#define SaveCroakWinError(expr,die,name1,name2) \
554 ((expr) ? : (CroakWinError(die,name1 name2), 0))
555
ed344e4f 556#define FillOSError(rc) (os2_setsyserrno(rc), \
4ea6d94f 557 Perl_severity = SEVERITY_ERROR)
5ba48348 558
30500b05
IZ
559#define WinError_2_Perl_rc \
560 ( init_PMWIN_entries(), \
561 Perl_rc=(*PMWIN_entries.GetLastError)(perl_hab_GET()) )
562
563/* Calling WinGetLastError() resets the error code of the current thread.
564 Since for some Win* API return value 0 is normal, one needs to call
565 this before calling them to distinguish normal and anomalous returns. */
566/*#define ResetWinError() WinError_2_Perl_rc */
567
5ba48348
JH
568/* At this moment init_PMWIN_entries() should be a nop (WinInitialize should
569 be called already, right?), so we do not risk stepping over our own error */
30500b05 570#define FillWinError ( WinError_2_Perl_rc, \
5ba48348
JH
571 Perl_severity = ERRORIDSEV(Perl_rc), \
572 Perl_rc = ERRORIDERROR(Perl_rc), \
573 os2_setsyserrno(Perl_rc))
4ea6d94f 574
760ac839 575#define STATIC_FILE_LENGTH 127
ff68c719 576
35bc1fdc
IZ
577 /* This should match loadOrdinals[] array in os2.c */
578enum entries_ordinals {
579 ORD_DosQueryExtLibpath,
580 ORD_DosSetExtLibpath,
581 ORD_DosVerifyPidTid,
582 ORD_SETHOSTENT,
583 ORD_SETNETENT,
584 ORD_SETPROTOENT,
585 ORD_SETSERVENT,
586 ORD_GETHOSTENT,
587 ORD_GETNETENT,
588 ORD_GETPROTOENT,
589 ORD_GETSERVENT,
590 ORD_ENDHOSTENT,
591 ORD_ENDNETENT,
592 ORD_ENDPROTOENT,
593 ORD_ENDSERVENT,
594 ORD_WinInitialize,
595 ORD_WinCreateMsgQueue,
596 ORD_WinDestroyMsgQueue,
597 ORD_WinPeekMsg,
598 ORD_WinGetMsg,
599 ORD_WinDispatchMsg,
600 ORD_WinGetLastError,
601 ORD_WinCancelShutdown,
602 ORD_RexxStart,
603 ORD_RexxVariablePool,
604 ORD_RexxRegisterFunctionExe,
605 ORD_RexxDeregisterFunction,
606 ORD_DOSSMSETTITLE,
607 ORD_PRF32QUERYPROFILESIZE,
608 ORD_PRF32OPENPROFILE,
609 ORD_PRF32CLOSEPROFILE,
610 ORD_PRF32QUERYPROFILE,
611 ORD_PRF32RESET,
612 ORD_PRF32QUERYPROFILEDATA,
613 ORD_PRF32WRITEPROFILEDATA,
614
615 ORD_WinChangeSwitchEntry,
616 ORD_WinQuerySwitchEntry,
617 ORD_WinQuerySwitchHandle,
618 ORD_WinQuerySwitchList,
619 ORD_WinSwitchToProgram,
620 ORD_WinBeginEnumWindows,
621 ORD_WinEndEnumWindows,
622 ORD_WinEnumDlgItem,
623 ORD_WinGetNextWindow,
624 ORD_WinIsChild,
625 ORD_WinQueryActiveWindow,
626 ORD_WinQueryClassName,
627 ORD_WinQueryFocus,
628 ORD_WinQueryWindow,
629 ORD_WinQueryWindowPos,
630 ORD_WinQueryWindowProcess,
631 ORD_WinQueryWindowText,
632 ORD_WinQueryWindowTextLength,
633 ORD_WinSetFocus,
634 ORD_WinSetWindowPos,
635 ORD_WinSetWindowText,
636 ORD_WinShowWindow,
637 ORD_WinIsWindow,
638 ORD_WinWindowFromId,
639 ORD_WinWindowFromPoint,
640 ORD_WinPostMsg,
30500b05
IZ
641 ORD_WinEnableWindow,
642 ORD_WinEnableWindowUpdate,
643 ORD_WinIsWindowEnabled,
644 ORD_WinIsWindowShowing,
645 ORD_WinIsWindowVisible,
646 ORD_WinQueryWindowPtr,
647 ORD_WinQueryWindowULong,
648 ORD_WinQueryWindowUShort,
649 ORD_WinSetWindowBits,
650 ORD_WinSetWindowPtr,
651 ORD_WinSetWindowULong,
652 ORD_WinSetWindowUShort,
653 ORD_WinQueryDesktopWindow,
654 ORD_WinSetActiveWindow,
655 ORD_DosQueryModFromEIP,
622913ab
IZ
656 ORD_Dos32QueryHeaderInfo,
657 ORD_DosTmrQueryFreq,
658 ORD_DosTmrQueryTime,
659 ORD_WinQueryActiveDesktopPathname,
660 ORD_WinInvalidateRect,
661 ORD_WinCreateFrameControls,
662 ORD_WinQueryClipbrdFmtInfo,
663 ORD_WinQueryClipbrdOwner,
664 ORD_WinQueryClipbrdViewer,
665 ORD_WinQueryClipbrdData,
666 ORD_WinOpenClipbrd,
667 ORD_WinCloseClipbrd,
668 ORD_WinSetClipbrdData,
669 ORD_WinSetClipbrdOwner,
670 ORD_WinSetClipbrdViewer,
671 ORD_WinEnumClipbrdFmts,
672 ORD_WinEmptyClipbrd,
673 ORD_WinAddAtom,
674 ORD_WinFindAtom,
675 ORD_WinDeleteAtom,
676 ORD_WinQueryAtomUsage,
677 ORD_WinQueryAtomName,
678 ORD_WinQueryAtomLength,
679 ORD_WinQuerySystemAtomTable,
680 ORD_WinCreateAtomTable,
681 ORD_WinDestroyAtomTable,
682 ORD_WinOpenWindowDC,
683 ORD_DevOpenDC,
684 ORD_DevQueryCaps,
685 ORD_DevCloseDC,
686 ORD_WinMessageBox,
687 ORD_WinMessageBox2,
688 ORD_WinQuerySysValue,
689 ORD_WinSetSysValue,
690 ORD_WinAlarm,
691 ORD_WinFlashWindow,
692 ORD_WinLoadPointer,
693 ORD_WinQuerySysPointer,
4ab57fcb 694 ORD_DosReplaceModule,
59ad941d
IZ
695 ORD_DosPerfSysCall,
696 ORD_RexxRegisterSubcomExe,
35bc1fdc
IZ
697 ORD_NENTRIES
698};
699
700/* RET: return type, AT: argument signature in (), ARGS: should be in () */
701#define CallORD(ret,o,at,args) (((ret (*)at) loadByOrdinal(o, 1))args)
702#define DeclFuncByORD(ret,name,o,at,args) \
703 ret name at { return CallORD(ret,o,at,args); }
704#define DeclVoidFuncByORD(name,o,at,args) \
705 void name at { CallORD(void,o,at,args); }
706
4ab57fcb
IZ
707/* This function returns error code on error, and saves the error info in $^E and Perl_rc */
708#define DeclOSFuncByORD_native(ret,name,o,at,args) \
709 ret name at { unsigned long rc; return CheckOSError(CallORD(ret,o,at,args)); }
710
711/* These functions return false on error, and save the error info in $^E and Perl_rc */
35bc1fdc
IZ
712#define DeclOSFuncByORD(ret,name,o,at,args) \
713 ret name at { unsigned long rc; return !CheckOSError(CallORD(ret,o,at,args)); }
714#define DeclWinFuncByORD(ret,name,o,at,args) \
715 ret name at { return SaveWinError(CallORD(ret,o,at,args)); }
716
717#define AssignFuncPByORD(p,o) (*(Perl_PFN*)&(p) = (loadByOrdinal(o, 1)))
718
30500b05
IZ
719/* This flavor caches the procedure pointer (named as p__Win#name) locally */
720#define DeclWinFuncByORD_CACHE(ret,name,o,at,args) \
721 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,1)
722
723/* This flavor may reset the last error before the call (if ret=0 may be OK) */
724#define DeclWinFuncByORD_CACHE_resetError(ret,name,o,at,args) \
725 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,1)
726
727/* Two flavors below do the same as above, but do not auto-croak */
728/* This flavor caches the procedure pointer (named as p__Win#name) locally */
729#define DeclWinFuncByORD_CACHE_survive(ret,name,o,at,args) \
730 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,0)
731
732/* This flavor may reset the last error before the call (if ret=0 may be OK) */
733#define DeclWinFuncByORD_CACHE_resetError_survive(ret,name,o,at,args) \
734 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,0)
735
736#define DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,r,die) \
737 static ret (*CAT2(p__Win,name)) at; \
738 static ret name at { \
739 if (!CAT2(p__Win,name)) \
740 AssignFuncPByORD(CAT2(p__Win,name), o); \
741 if (r) ResetWinError(); \
742 return SaveCroakWinError(CAT2(p__Win,name) args, die, "[Win]", STRINGIFY(name)); }
743
744/* These flavors additionally assume ORD is name with prepended ORD_Win */
745#define DeclWinFunc_CACHE(ret,name,at,args) \
746 DeclWinFuncByORD_CACHE(ret,name,CAT2(ORD_Win,name),at,args)
747#define DeclWinFunc_CACHE_resetError(ret,name,at,args) \
748 DeclWinFuncByORD_CACHE_resetError(ret,name,CAT2(ORD_Win,name),at,args)
749#define DeclWinFunc_CACHE_survive(ret,name,at,args) \
750 DeclWinFuncByORD_CACHE_survive(ret,name,CAT2(ORD_Win,name),at,args)
751#define DeclWinFunc_CACHE_resetError_survive(ret,name,at,args) \
752 DeclWinFuncByORD_CACHE_resetError_survive(ret,name,CAT2(ORD_Win,name),at,args)
753
754void ResetWinError(void);
755void CroakWinError(int die, char *name);
756
1933e12c
IZ
757enum Perlos2_handler {
758 Perlos2_handler_mangle = 1,
759 Perlos2_handler_perl_sh,
760 Perlos2_handler_perllib_from,
761 Perlos2_handler_perllib_to,
762};
763enum dir_subst_e {
764 dir_subst_fatal = 1,
765 dir_subst_pathlike = 2
766};
767
768extern int Perl_OS2_handler_install(void *handler, enum Perlos2_handler how);
769extern char *dir_subst(char *s, unsigned int l, char *b, unsigned int bl, enum dir_subst_e flags, char *msg);
770extern unsigned long fill_extLibpath(int type, char *pre, char *post, int replace, char *msg);
771
760ac839
LW
772#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
773char *perllib_mangle(char *, unsigned int);
4ea6d94f 774
5c728af0
IZ
775#define fork fork_with_resources
776
46c6a8ac 777#ifdef EINTR /* x2p do not include perl.h!!! */
622913ab
IZ
778static __inline__ int
779my_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
780{
781 if (nfds == 0 && timeout && (_emx_env & 0x200)) {
1933e12c 782 if (async_mssleep(1000 * timeout->tv_sec + (timeout->tv_usec + 500)/1000, 500))
622913ab
IZ
783 return 0;
784 errno = EINTR;
785 return -1;
786 }
787 return select(nfds, readfds, writefds, exceptfds, timeout);
788}
789
790#define select my_select
46c6a8ac 791#endif
622913ab
IZ
792
793
35bc1fdc
IZ
794typedef int (*Perl_PFN)();
795Perl_PFN loadByOrdinal(enum entries_ordinals ord, int fail);
796extern const Perl_PFN * const pExtFCN;
4ea6d94f 797char *os2error(int rc);
2d766320 798int os2_stat(const char *name, struct stat *st);
5c728af0 799int fork_with_resources();
2d766320
IZ
800int setpriority(int which, int pid, int val);
801int getpriority(int which /* ignored */, int pid);
802
622913ab
IZ
803void croak_with_os2error(char *s) __attribute__((noreturn));
804
1933e12c
IZ
805/* void return value */
806#define os2cp_croak(rc,msg) (CheckOSError(rc) && (croak_with_os2error(msg),0))
807
808/* propagates rc */
809#define os2win_croak(rc,msg) \
810 SaveCroakWinError((expr), 1 /* die */, /* no prefix */, (msg))
811
812/* propagates rc; use with functions which may return 0 on success */
813#define os2win_croak_0OK(rc,msg) \
814 SaveCroakWinError((ResetWinError, (expr)), \
815 1 /* die */, /* no prefix */, (msg))
816
2d766320
IZ
817#ifdef PERL_CORE
818int os2_do_spawn(pTHX_ char *cmd);
622913ab 819int os2_do_aspawn(pTHX_ SV *really, SV **vmark, SV **vsp);
2d766320 820#endif
4ea6d94f 821
ee964dfe
IZ
822#ifndef LOG_DAEMON
823
824/* Replacement for syslog.h */
825# define LOG_EMERG 0 /* system is unusable */
826# define LOG_ALERT 1 /* action must be taken immediately */
827# define LOG_CRIT 2 /* critical conditions */
828# define LOG_ERR 3 /* error conditions */
829# define LOG_WARNING 4 /* warning conditions */
830# define LOG_NOTICE 5 /* normal but significant condition */
831# define LOG_INFO 6 /* informational */
832# define LOG_DEBUG 7 /* debug-level messages */
833
834# define LOG_PRIMASK 0x007 /* mask to extract priority part (internal) */
835 /* extract priority */
836# define LOG_PRI(p) ((p) & LOG_PRIMASK)
837# define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
838
839/* facility codes */
840# define LOG_KERN (0<<3) /* kernel messages */
841# define LOG_USER (1<<3) /* random user-level messages */
842# define LOG_MAIL (2<<3) /* mail system */
843# define LOG_DAEMON (3<<3) /* system daemons */
844# define LOG_AUTH (4<<3) /* security/authorization messages */
845# define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
846# define LOG_LPR (6<<3) /* line printer subsystem */
847# define LOG_NEWS (7<<3) /* network news subsystem */
848# define LOG_UUCP (8<<3) /* UUCP subsystem */
849# define LOG_CRON (15<<3) /* clock daemon */
850 /* other codes through 15 reserved for system use */
851# define LOG_LOCAL0 (16<<3) /* reserved for local use */
852# define LOG_LOCAL1 (17<<3) /* reserved for local use */
853# define LOG_LOCAL2 (18<<3) /* reserved for local use */
854# define LOG_LOCAL3 (19<<3) /* reserved for local use */
855# define LOG_LOCAL4 (20<<3) /* reserved for local use */
856# define LOG_LOCAL5 (21<<3) /* reserved for local use */
857# define LOG_LOCAL6 (22<<3) /* reserved for local use */
858# define LOG_LOCAL7 (23<<3) /* reserved for local use */
859
860# define LOG_NFACILITIES 24 /* current number of facilities */
861# define LOG_FACMASK 0x03f8 /* mask to extract facility part */
862 /* facility of pri */
863# define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
864
865/*
866 * arguments to setlogmask.
867 */
868# define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
869# define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
870
871/*
872 * Option flags for openlog.
873 *
874 * LOG_ODELAY no longer does anything.
875 * LOG_NDELAY is the inverse of what it used to be.
876 */
877# define LOG_PID 0x01 /* log the pid with each message */
878# define LOG_CONS 0x02 /* log on the console if errors in sending */
879# define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
880# define LOG_NDELAY 0x08 /* don't delay open */
881# define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
882# define LOG_PERROR 0x20 /* log to stderr as well */
883
884#endif
885
1933e12c
IZ
886/* ************************************************* */
887#ifndef MAKEPLINFOSEG
888
889/* From $DDK\base32\rel\os2c\include\base\os2\16bit\infoseg.h + typedefs */
890
891/*
892 * The structure below defines the content and organization of the system
893 * information segment (InfoSeg). The actual table is statically defined in
894 * SDATA.ASM. Ring 0, read/write access is obtained by the clock device
895 * driver using the DevHlp GetDOSVar function. (GetDOSVar returns a ring 0,
896 * read-only selector to all other requestors.)
897 *
898 * In order to prevent an errant process from destroying the infoseg, two
899 * identical global infosegs are maintained. One is in the tiled shared
900 * arena and is accessible in user mode (and therefore can potentially be
901 * overwritten from ring 2), and the other is in the system arena and is
902 * accessible only in kernel mode. All kernel code (except the clock driver)
903 * is responsible for updating BOTH copies of the infoseg. The copy kept
904 * in the system arena is addressable as DOSGROUP:SISData, and the copy
905 * in the shared arena is addressable via a system arena alias. 16:16 and
906 * 0:32 pointers to the alias are stored in _Sis2.
907 */
908
909typedef struct InfoSegGDT {
910
911/* Time (offset 0x00) */
912
913unsigned long SIS_BigTime; /* Time from 1-1-1970 in seconds */
914unsigned long SIS_MsCount; /* Freerunning milliseconds counter */
915unsigned char SIS_HrsTime; /* Hours */
916unsigned char SIS_MinTime; /* Minutes */
917unsigned char SIS_SecTime; /* Seconds */
918unsigned char SIS_HunTime; /* Hundredths of seconds */
919unsigned short SIS_TimeZone; /* Timezone in min from GMT (Set to EST) */
920unsigned short SIS_ClkIntrvl; /* Timer interval (units=0.0001 secs) */
921
922/* Date (offset 0x10) */
923
924unsigned char SIS_DayDate; /* Day-of-month (1-31) */
925unsigned char SIS_MonDate; /* Month (1-12) */
926unsigned short SIS_YrsDate; /* Year (>= 1980) */
927unsigned char SIS_DOWDate; /* Day-of-week (1-1-80 = Tues = 3) */
928
929/* Version (offset 0x15) */
930
931unsigned char SIS_VerMajor; /* Major version number */
932unsigned char SIS_VerMinor; /* Minor version number */
933unsigned char SIS_RevLettr; /* Revision letter */
934
935/* System Status (offset 0x18) */
936
937unsigned char SIS_CurScrnGrp; /* Fgnd screen group # */
938unsigned char SIS_MaxScrnGrp; /* Maximum number of screen groups */
939unsigned char SIS_HugeShfCnt; /* Shift count for huge segments */
940unsigned char SIS_ProtMdOnly; /* Protect-mode-only indicator */
941unsigned short SIS_FgndPID; /* Foreground process ID */
942
943/* Scheduler Parms (offset 0x1E) */
944
945unsigned char SIS_Dynamic; /* Dynamic variation flag (1=enabled) */
946unsigned char SIS_MaxWait; /* Maxwait (seconds) */
947unsigned short SIS_MinSlice; /* Minimum timeslice (milliseconds) */
948unsigned short SIS_MaxSlice; /* Maximum timeslice (milliseconds) */
949
950/* Boot Drive (offset 0x24) */
951
952unsigned short SIS_BootDrv; /* Drive from which system was booted */
953
954/* RAS Major Event Code Table (offset 0x26) */
955
956unsigned char SIS_mec_table[32]; /* Table of RAS Major Event Codes (MECs) */
957
958/* Additional Session Data (offset 0x46) */
959
960unsigned char SIS_MaxVioWinSG; /* Max. no. of VIO windowable SG's */
961unsigned char SIS_MaxPresMgrSG; /* Max. no. of Presentation Manager SG's */
962
963/* Error logging Information (offset 0x48) */
964
965unsigned short SIS_SysLog; /* Error Logging Status */
966
967/* Additional RAS Information (offset 0x4A) */
968
969unsigned short SIS_MMIOBase; /* Memory mapped I/O selector */
970unsigned long SIS_MMIOAddr; /* Memory mapped I/O address */
971
972/* Additional 2.0 Data (offset 0x50) */
973
974unsigned char SIS_MaxVDMs; /* Max. no. of Virtual DOS machines */
975unsigned char SIS_Reserved;
976
977unsigned char SIS_perf_mec_table[32]; /* varga 6/5/97 Table of Perfomance Major Event Codes (MECS) varga*/
978} GINFOSEG, *PGINFOSEG;
979
980#define SIS_LEN sizeof(struct InfoSegGDT)
981
982/*
983 * InfoSeg LDT Data Segment Structure
984 *
985 * The structure below defines the content and organization of the system
986 * information in a special per-process segment to be accessible by the
987 * process through the LDT (read-only).
988 *
989 * As in the global infoseg, two copies of the current processes local
990 * infoseg exist, one accessible in both user and kernel mode, the other
991 * only in kernel mode. Kernel code is responsible for updating BOTH copies.
992 * Pointers to the local infoseg copy are stored in _Lis2.
993 *
994 * Note that only the currently running process has an extra copy of the
995 * local infoseg. The copy is done at context switch time.
996 */
997
998typedef struct InfoSegLDT {
999unsigned short LIS_CurProcID; /* Current process ID */
1000unsigned short LIS_ParProcID; /* Process ID of parent */
1001unsigned short LIS_CurThrdPri; /* Current thread priority */
1002unsigned short LIS_CurThrdID; /* Current thread ID */
1003unsigned short LIS_CurScrnGrp; /* Screengroup */
1004unsigned char LIS_ProcStatus; /* Process status bits */
1005unsigned char LIS_fillbyte1; /* filler byte */
1006unsigned short LIS_Fgnd; /* Current process is in foreground */
1007unsigned char LIS_ProcType; /* Current process type */
1008unsigned char LIS_fillbyte2; /* filler byte */
1009
1010unsigned short LIS_AX; /* @@V1 Environment selector */
1011unsigned short LIS_BX; /* @@V1 Offset of command line start */
1012unsigned short LIS_CX; /* @@V1 Length of Data Segment */
1013unsigned short LIS_DX; /* @@V1 STACKSIZE from the .EXE file */
1014unsigned short LIS_SI; /* @@V1 HEAPSIZE from the .EXE file */
1015unsigned short LIS_DI; /* @@V1 Module handle of the application */
1016unsigned short LIS_DS; /* @@V1 Data Segment Handle of application */
1017
1018unsigned short LIS_PackSel; /* First tiled selector in this EXE */
1019unsigned short LIS_PackShrSel; /* First selector above shared arena */
1020unsigned short LIS_PackPckSel; /* First selector above packed arena */
1021/* #ifdef SMP */
1022unsigned long LIS_pTIB; /* Pointer to TIB */
1023unsigned long LIS_pPIB; /* Pointer to PIB */
1024/* #endif */
1025} LINFOSEG, *PLINFOSEG;
1026
1027#define LIS_LEN sizeof(struct InfoSegLDT)
1028
1029
1030/*
1031 * Process Type codes
1032 *
1033 * These are the definitons for the codes stored
1034 * in the LIS_ProcType field in the local infoseg.
1035 */
1036
1037#define LIS_PT_FULLSCRN 0 /* Full screen app. */
1038#define LIS_PT_REALMODE 1 /* Real mode process */
1039#define LIS_PT_VIOWIN 2 /* VIO windowable app. */
1040#define LIS_PT_PRESMGR 3 /* Presentation Manager app. */
1041#define LIS_PT_DETACHED 4 /* Detached app. */
1042
1043
1044/*
1045 *
1046 * Process Status Bit Definitions
1047 *
1048 */
1049
1050#define LIS_PS_EXITLIST 0x01 /* In exitlist handler */
1051
1052
1053/*
1054 * Flags equates for the Global Info Segment
1055 * SIS_SysLog WORD in Global Info Segment
1056 *
1057 * xxxx xxxx xxxx xxx0 Error Logging Disabled
1058 * xxxx xxxx xxxx xxx1 Error Logging Enabled
1059 *
1060 * xxxx xxxx xxxx xx0x Error Logging not available
1061 * xxxx xxxx xxxx xx1x Error Logging available
1062 */
1063
1064#define LF_LOGENABLE 0x0001 /* Logging enabled */
1065#define LF_LOGAVAILABLE 0x0002 /* Logging available */
1066
1067#define MAKEPGINFOSEG(sel) ((PGINFOSEG)MAKEP(sel, 0))
1068#define MAKEPLINFOSEG(sel) ((PLINFOSEG)MAKEP(sel, 0))
1069
1070#endif /* ndef(MAKEPLINFOSEG) */
1071
4ea6d94f 1072/* ************************************************************ */
1073#define Dos32QuerySysState DosQuerySysState
1074#define QuerySysState(flags, pid, buf, bufsz) \
1075 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
1076
1077#define QSS_PROCESS 1
df3ef7a9
IZ
1078#define QSS_MODULE 4
1079#define QSS_SEMAPHORES 2
4ea6d94f 1080#define QSS_FILE 8 /* Buggy until fixpack18 */
1081#define QSS_SHARED 16
1082
ed344e4f 1083#ifdef _OS2_H
4ea6d94f 1084
1085APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
1086 ULONG _res_,PVOID buf,ULONG bufsz);
1087typedef struct {
1088 ULONG threadcnt;
1089 ULONG proccnt;
1090 ULONG modulecnt;
1091} QGLOBAL, *PQGLOBAL;
1092
1093typedef struct {
1094 ULONG rectype;
1095 USHORT threadid;
1096 USHORT slotid;
1097 ULONG sleepid;
1098 ULONG priority;
1099 ULONG systime;
1100 ULONG usertime;
1101 UCHAR state;
1102 UCHAR _reserved1_; /* padding to ULONG */
1103 USHORT _reserved2_; /* padding to ULONG */
1104} QTHREAD, *PQTHREAD;
1105
1106typedef struct {
1107 USHORT sfn;
1108 USHORT refcnt;
1109 USHORT flags1;
1110 USHORT flags2;
1111 USHORT accmode1;
1112 USHORT accmode2;
1113 ULONG filesize;
1114 USHORT volhnd;
1115 USHORT attrib;
1116 USHORT _reserved_;
1117} QFDS, *PQFDS;
1118
1119typedef struct qfile {
1120 ULONG rectype;
1121 struct qfile *next;
1122 ULONG opencnt;
1123 PQFDS filedata;
1124 char name[1];
1125} QFILE, *PQFILE;
1126
1127typedef struct {
1128 ULONG rectype;
1129 PQTHREAD threads;
1130 USHORT pid;
1131 USHORT ppid;
1132 ULONG type;
1133 ULONG state;
1134 ULONG sessid;
1135 USHORT hndmod;
1136 USHORT threadcnt;
1137 ULONG privsem32cnt;
1138 ULONG _reserved2_;
1139 USHORT sem16cnt;
1140 USHORT dllcnt;
1141 USHORT shrmemcnt;
1142 USHORT fdscnt;
1143 PUSHORT sem16s;
1144 PUSHORT dlls;
1145 PUSHORT shrmems;
1146 PUSHORT fds;
1147} QPROCESS, *PQPROCESS;
1148
1149typedef struct sema {
1150 struct sema *next;
1151 USHORT refcnt;
1152 UCHAR sysflags;
1153 UCHAR sysproccnt;
1154 ULONG _reserved1_;
1155 USHORT index;
1156 CHAR name[1];
1157} QSEMA, *PQSEMA;
1158
1159typedef struct {
1160 ULONG rectype;
1161 ULONG _reserved1_;
1162 USHORT _reserved2_;
1163 USHORT syssemidx;
1164 ULONG index;
1165 QSEMA sema;
1166} QSEMSTRUC, *PQSEMSTRUC;
1167
1168typedef struct {
1169 USHORT pid;
1170 USHORT opencnt;
1171} QSEMOWNER32, *PQSEMOWNER32;
1172
1173typedef struct {
1174 PQSEMOWNER32 own;
1175 PCHAR name;
1176 PVOID semrecs; /* array of associated sema's */
1177 USHORT flags;
1178 USHORT semreccnt;
1179 USHORT waitcnt;
1180 USHORT _reserved_; /* padding to ULONG */
1181} QSEMSMUX32, *PQSEMSMUX32;
1182
1183typedef struct {
1184 PQSEMOWNER32 own;
1185 PCHAR name;
1186 PQSEMSMUX32 mux;
1187 USHORT flags;
1188 USHORT postcnt;
1189} QSEMEV32, *PQSEMEV32;
1190
1191typedef struct {
1192 PQSEMOWNER32 own;
1193 PCHAR name;
1194 PQSEMSMUX32 mux;
1195 USHORT flags;
1196 USHORT refcnt;
1197 USHORT thrdnum;
1198 USHORT _reserved_; /* padding to ULONG */
1199} QSEMMUX32, *PQSEMMUX32;
1200
1201typedef struct semstr32 {
1202 struct semstr *next;
1203 QSEMEV32 evsem;
1204 QSEMMUX32 muxsem;
1205 QSEMSMUX32 smuxsem;
1206} QSEMSTRUC32, *PQSEMSTRUC32;
1207
1208typedef struct shrmem {
1209 struct shrmem *next;
1210 USHORT hndshr;
1211 USHORT selshr;
1212 USHORT refcnt;
1213 CHAR name[1];
1214} QSHRMEM, *PQSHRMEM;
1215
1216typedef struct module {
1217 struct module *next;
1218 USHORT hndmod;
1219 USHORT type;
1220 ULONG refcnt;
1221 ULONG segcnt;
1222 PVOID _reserved_;
1223 PCHAR name;
1224 USHORT modref[1];
1225} QMODULE, *PQMODULE;
1226
1227typedef struct {
1228 PQGLOBAL gbldata;
1229 PQPROCESS procdata;
1230 PQSEMSTRUC semadata;
1231 PQSEMSTRUC32 sem32data;
1232 PQSHRMEM shrmemdata;
1233 PQMODULE moddata;
1234 PVOID _reserved2_;
1235 PQFILE filedata;
1236} QTOPLEVEL, *PQTOPLEVEL;
1237/* ************************************************************ */
1238
1239PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
1240
ed344e4f 1241#endif /* _OS2_H */
5ae7bdf7 1242