3 /* #include <sys/select.h> */
6 * This symbol, if defined, indicates that the ioctl() routine is
7 * available to set I/O characteristics
12 * This symbol, if defined, indicates that the routine utime() is
13 * available to update the access and modification times of files.
15 #define HAS_UTIME /**/
18 * This symbol is defined if Time_t is an unsigned type on this system.
25 #define HAS_WAITPID_RUNTIME (_emx_env & 0x200)
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.
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.
40 #define HAS_GETGRENT /* fake */
41 #define HAS_SETGRENT /* fake */
42 #define HAS_ENDGRENT /* fake */
45 * This symbol, if defined, indicates that the program should
46 * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
47 * that a file is in "binary" mode -- that is, that no translation
48 * of bytes occurs on read or write operations.
52 #define SOCKET_OPEN_MODE "b"
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
60 #define Stat_t struct stat
63 * This symbol is defined if this system has a stat structure declaring
66 #define USE_STAT_RDEV /**/
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.
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.)
85 #define ALTERNATE_SHEBANG "extproc "
88 # define SIGABRT SIGILL
91 # define SIGILL 6 /* blech */
93 #define ABORT() kill(PerlProc_getpid(),SIGABRT);
95 #define BIT_BUCKET "/dev/nul" /* Will this work? */
97 /* Apparently TCPIPV4 defines may be included even with only IAK present */
99 #if !defined(NO_TCPIPV4) && !defined(TCPIPV4)
101 # define TCPIPV4_FORCED /* Just in case */
104 #if defined(I_SYS_UN) && !defined(TCPIPV4)
105 /* It is not working without TCPIPV4 defined. */
111 #define do_spawn(a) os2_do_spawn(aTHX_ (a))
112 #define do_aspawn(a,b,c) os2_do_aspawn(aTHX_ (a),(b),(c))
114 #define OS2_ERROR_ALREADY_POSTED 299 /* Avoid os2.h */
118 #define MUTEX_INIT(m) \
121 if ((rc = _rmutex_create(m,0))) \
122 Perl_croak_nocontext("panic: MUTEX_INIT: rc=%i", rc); \
124 #define MUTEX_LOCK(m) \
127 if ((rc = _rmutex_request(m,_FMR_IGNINT))) \
128 Perl_croak_nocontext("panic: MUTEX_LOCK: rc=%i", rc); \
130 #define MUTEX_UNLOCK(m) \
133 if ((rc = _rmutex_release(m))) \
134 Perl_croak_nocontext("panic: MUTEX_UNLOCK: rc=%i", rc); \
136 #define MUTEX_DESTROY(m) \
139 if ((rc = _rmutex_close(m))) \
140 Perl_croak_nocontext("panic: MUTEX_DESTROY: rc=%i", rc); \
143 #define COND_INIT(c) \
146 if ((rc = DosCreateEventSem(NULL,c,0,0))) \
147 Perl_croak_nocontext("panic: COND_INIT: rc=%i", rc); \
149 #define COND_SIGNAL(c) \
152 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
153 Perl_croak_nocontext("panic: COND_SIGNAL, rc=%ld", rc); \
155 #define COND_BROADCAST(c) \
158 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
159 Perl_croak_nocontext("panic: COND_BROADCAST, rc=%i", rc); \
161 /* #define COND_WAIT(c, m) \
163 if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \
164 Perl_croak_nocontext("panic: COND_WAIT"); \
167 #define COND_WAIT(c, m) os2_cond_wait(c,m)
169 #define COND_WAIT_win32(c, m) \
172 if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE))) \
173 Perl_croak_nocontext("panic: COND_WAIT"); \
177 #define COND_DESTROY(c) \
180 if ((rc = DosCloseEventSem(*(c)))) \
181 Perl_croak_nocontext("panic: COND_DESTROY, rc=%i", rc); \
183 /*#define THR ((struct thread *) TlsGetValue(PL_thr_key))
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 \
198 #endif /* USE_SLOW_THREAD_SPECIFIC */
199 #define pthread_key_delete(keyp)
200 #define pthread_self() _gettid()
201 #define YIELD DosSleep(0)
203 #ifdef PTHREADS_INCLUDED /* For ./x2p stuff. */
204 int pthread_join(pthread_t tid, void **status);
205 int pthread_detach(pthread_t tid);
206 int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
207 void *(*start_routine)(void*), void *arg);
208 #endif /* PTHREAD_INCLUDED */
210 #define THREADS_ELSEWHERE
212 #else /* USE_ITHREADS */
214 #define do_spawn(a) os2_do_spawn(a)
215 #define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c))
217 void Perl_OS2_init(char **);
218 void Perl_OS2_init3(char **envp, void **excH, int flags);
219 void Perl_OS2_term(void **excH, int exitstatus, int flags);
221 /* The code without INIT3 hideously puts env inside: */
223 /* These ones should be in the same block as PERL_SYS_TERM() */
226 # define PERL_SYS_INIT3(argcp, argvp, envp) \
228 MALLOC_CHECK_TAINT(*argcp, *argvp, *envp) \
229 _response(argcp, argvp); \
230 _wildcard(argcp, argvp); \
231 Perl_OS2_init3(*envp, xreg, 0); \
234 # define PERL_SYS_INIT(argcp, argvp) { \
236 _response(argcp, argvp); \
237 _wildcard(argcp, argvp); \
238 Perl_OS2_init3(NULL, xreg, 0); \
241 #else /* Compiling embedded Perl or Perl extension */
243 # define PERL_SYS_INIT3(argcp, argvp, envp) \
245 Perl_OS2_init3(*envp, xreg, 0); \
247 # define PERL_SYS_INIT(argcp, argvp) { \
249 Perl_OS2_init3(NULL, xreg, 0); \
253 #define FORCE_EMX_DEINIT_EXIT 1
254 #define FORCE_EMX_DEINIT_CRT_TERM 2
255 #define FORCE_EMX_DEINIT_RUN_ATEXIT 4
257 #define PERL_SYS_TERM2(xreg,flags) \
258 Perl_OS2_term(xreg, 0, flags); \
262 #define PERL_SYS_TERM1(xreg) \
263 Perl_OS2_term(xreg, 0, FORCE_EMX_DEINIT_RUN_ATEXIT)
265 /* This one should come in pair with PERL_SYS_INIT() and in the same block */
266 #define PERL_SYS_TERM() \
267 PERL_SYS_TERM1(xreg); \
271 # define PERL_CALLCONV _System
274 /* #define PERL_SYS_TERM() STMT_START { \
275 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
277 #define dXSUB_SYS OS2_XS_init()
280 /* # define HAS_FORK */
281 /* # define HIDEMYMALLOC */
282 /* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
283 #else /* !PERL_IS_AOUT */
284 # ifndef PERL_FOR_X2P
286 # define USE_PERL_SBRK
291 # define SYSTEM_ALLOC(a) sys_alloc(a)
293 void *sys_alloc(int size);
295 #endif /* !PERL_IS_AOUT */
296 #if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
300 /* os2ish is used from a2p/a2p.h without pTHX/pTHX_ first being
301 * defined. Hack around this to get us to compile.
312 #define TMPPATH1 "plXXXXXX"
313 extern const char *tmppath;
314 PerlIO *my_syspopen(pTHX_ char *cmd, char *mode);
315 /* Cannot prototype with I32 at this point. */
316 int my_syspclose(PerlIO *f);
317 FILE *my_tmpfile (void);
318 char *my_tmpnam (char *);
319 int my_mkdir (__const__ char *, long);
320 int my_rmdir (__const__ char *);
321 struct passwd *my_getpwent (void);
322 void my_setpwent (void);
323 void my_endpwent (void);
324 char *gcvt_os2(double value, int digits, char *buffer);
326 extern int async_mssleep(unsigned long ms, int switch_priority);
327 extern unsigned long msCounter(void);
328 extern unsigned long InfoTable(int local);
329 extern unsigned long find_myself(void);
331 #define MAX_SLEEP (((1<30) / (1000/4))-1) /* 1<32 msec */
333 static __inline__ unsigned
334 my_sleep(unsigned sec)
337 while (sec > MAX_SLEEP) {
339 remain = sleep(MAX_SLEEP);
346 #define sleep my_sleep
349 unsigned long DosSleep(unsigned long);
350 unsigned long DosAllocThreadLocalMemory (unsigned long cb, unsigned long **p);
353 struct group *getgrent (void);
354 void setgrent (void);
355 void endgrent (void);
357 struct passwd *my_getpwuid (uid_t);
358 struct passwd *my_getpwnam (__const__ char *);
361 #define L_tmpnam MAXPATHLEN
363 #define tmpfile my_tmpfile
364 #define tmpnam my_tmpnam
365 #define isatty _isterm
367 #define srand srandom
368 #define strtoll _strtoll
369 #define strtoull _strtoull
371 #define usleep(usec) ((void)async_mssleep(((usec)+500)/1000, 500))
375 * fwrite1() should be a routine with the same calling sequence as fwrite(),
376 * but which outputs all of the bytes requested as a single stream (unlike
377 * fwrite() itself, which on some systems outputs several distinct records
378 * if the number_of_items parameter is >1).
380 #define fwrite1 fwrite
382 #define my_getenv(var) getenv(var)
383 #define flock my_flock
384 #define rmdir my_rmdir
385 #define mkdir my_mkdir
386 #define setpwent my_setpwent
387 #define getpwent my_getpwent
388 #define endpwent my_endpwent
389 #define getpwuid my_getpwuid
390 #define getpwnam my_getpwnam
392 void *emx_calloc (size_t, size_t);
393 void emx_free (void *);
394 void *emx_malloc (size_t);
395 void *emx_realloc (void *, size_t);
397 /*****************************************************************************/
399 #include <stdlib.h> /* before the following definitions */
400 #include <unistd.h> /* before the following definitions */
402 #include <sys/stat.h>
404 #define chdir _chdir2
405 #define getcwd _getcwd2
407 /* This guy is needed for quick stdstd */
409 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
410 /* Perl uses ungetc only with successful return */
411 # define ungetc(c,fp) \
412 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
413 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
416 #define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd)
426 #include <emx/io.h> /* for _fd_flags() prototype */
429 _PERLIO_IS_BINMODE_FD(int fd)
431 int *pflags = _fd_flags(fd);
433 return pflags && (*pflags) & O_BINARY;
436 /* ctermid is missing from emx0.9d */
437 char *ctermid(char *s);
439 #define OP_BINARY O_BINARY
441 #define OS2_STAT_HACK 1
444 #define Stat(fname,bufptr) os2_stat((fname),(bufptr))
445 #define Fstat(fd,bufptr) os2_fstat((fd),(bufptr))
446 #define Fflush(fp) fflush(fp)
447 #define Mkdir(path,mode) mkdir((path),(mode))
448 #define chmod(path,mode) os2_chmod((path),(mode))
452 #define S_IFBLK 0120000 /* Hacks to make things compile... */
453 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
455 int os2_chmod(const char *name, int pmode);
456 int os2_fstat(int handle, struct stat *st);
460 #define Stat(fname,bufptr) stat((fname),(bufptr))
461 #define Fstat(fd,bufptr) fstat((fd),(bufptr))
462 #define Fflush(fp) fflush(fp)
463 #define Mkdir(path,mode) mkdir((path),(mode))
467 /* With SD386 it is impossible to debug register variables. */
468 #if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
472 /* Our private OS/2 specific data. */
474 typedef struct OS2_Perl_data {
479 unsigned long severity;
480 unsigned long phmq; /* Handle to message queue */
481 unsigned long phmq_refcnt;
482 unsigned long phmq_servers;
483 unsigned long initial_mode; /* VIO etc. mode we were started in */
484 unsigned long morph_refcnt;
487 extern OS2_Perl_data_t OS2_Perl_data;
489 #define Perl_hab ((HAB)OS2_Perl_data.phab)
490 #define Perl_rc (OS2_Perl_data.rc)
491 #define Perl_severity (OS2_Perl_data.severity)
492 #define errno_isOS2 12345678
493 #define errno_isOS2_set 12345679
494 #define OS2_Perl_flags (OS2_Perl_data.flags)
495 #define Perl_HAB_set_f 1
496 #define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
497 #define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
498 #define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
499 #define _obtain_Perl_HAB (init_PMWIN_entries(), \
500 Perl_hab = (*PMWIN_entries.Initialize)(0), \
501 set_Perl_HAB_f, Perl_hab)
502 #define perl_hab_GET() (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB)
503 #define Acquire_hab() perl_hab_GET()
504 #define Perl_hmq ((HMQ)OS2_Perl_data.phmq)
505 #define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt)
506 #define Perl_hmq_servers (OS2_Perl_data.phmq_servers)
507 #define Perl_os2_initial_mode (OS2_Perl_data.initial_mode)
508 #define Perl_morph_refcnt (OS2_Perl_data.morph_refcnt)
510 unsigned long Perl_hab_GET();
511 unsigned long Perl_Register_MQ(int serve);
512 void Perl_Deregister_MQ(int serve);
513 int Perl_Serve_Messages(int force);
514 /* Cannot prototype with I32 at this point. */
515 int Perl_Process_Messages(int force, long *cntp);
516 char *os2_execname(pTHX);
519 struct PMWIN_entries_t {
520 unsigned long (*Initialize)( unsigned long fsOptions );
521 unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg);
522 int (*DestroyMsgQueue)(unsigned long hmq);
523 int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg,
524 unsigned long hwndFilter, unsigned long msgFilterFirst,
525 unsigned long msgFilterLast, unsigned long fl);
526 int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg,
527 unsigned long hwndFilter, unsigned long msgFilterFirst,
528 unsigned long msgFilterLast);
529 void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg);
530 unsigned long (*GetLastError)(unsigned long hab);
531 unsigned long (*CancelShutdown)(unsigned long hmq, unsigned long fCancelAlways);
533 extern struct PMWIN_entries_t PMWIN_entries;
534 void init_PMWIN_entries(void);
536 #define perl_hmq_GET(serve) Perl_Register_MQ(serve)
537 #define perl_hmq_UNSET(serve) Perl_Deregister_MQ(serve)
539 #define OS2_XS_init() (*OS2_Perl_data.xs_init)(aTHX)
541 #if _EMX_CRT_REV_ >= 60
542 # define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2_set, \
545 # define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2)
548 /* The expressions below return true on error. */
549 /* INCL_DOSERRORS needed. rc should be declared outside. */
550 #define CheckOSError(expr) ((rc = (expr)) ? (FillOSError(rc), rc) : 0)
551 /* INCL_WINERRORS needed. */
552 #define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
554 /* This form propagates the return value, setting $^E if needed */
555 #define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
557 /* This form propagates the return value, dieing with $^E if needed */
558 #define SaveCroakWinError(expr,die,name1,name2) \
559 ((expr) ? : (CroakWinError(die,name1 name2), 0))
561 #define FillOSError(rc) (os2_setsyserrno(rc), \
562 Perl_severity = SEVERITY_ERROR)
564 #define WinError_2_Perl_rc \
565 ( init_PMWIN_entries(), \
566 Perl_rc=(*PMWIN_entries.GetLastError)(perl_hab_GET()) )
568 /* Calling WinGetLastError() resets the error code of the current thread.
569 Since for some Win* API return value 0 is normal, one needs to call
570 this before calling them to distinguish normal and anomalous returns. */
571 /*#define ResetWinError() WinError_2_Perl_rc */
573 /* At this moment init_PMWIN_entries() should be a nop (WinInitialize should
574 be called already, right?), so we do not risk stepping over our own error */
575 #define FillWinError ( WinError_2_Perl_rc, \
576 Perl_severity = ERRORIDSEV(Perl_rc), \
577 Perl_rc = ERRORIDERROR(Perl_rc), \
578 os2_setsyserrno(Perl_rc))
580 #define STATIC_FILE_LENGTH 127
582 /* This should match loadOrdinals[] array in os2.c */
583 enum entries_ordinals {
584 ORD_DosQueryExtLibpath,
585 ORD_DosSetExtLibpath,
600 ORD_WinCreateMsgQueue,
601 ORD_WinDestroyMsgQueue,
606 ORD_WinCancelShutdown,
608 ORD_RexxVariablePool,
609 ORD_RexxRegisterFunctionExe,
610 ORD_RexxDeregisterFunction,
612 ORD_PRF32QUERYPROFILESIZE,
613 ORD_PRF32OPENPROFILE,
614 ORD_PRF32CLOSEPROFILE,
615 ORD_PRF32QUERYPROFILE,
617 ORD_PRF32QUERYPROFILEDATA,
618 ORD_PRF32WRITEPROFILEDATA,
620 ORD_WinChangeSwitchEntry,
621 ORD_WinQuerySwitchEntry,
622 ORD_WinQuerySwitchHandle,
623 ORD_WinQuerySwitchList,
624 ORD_WinSwitchToProgram,
625 ORD_WinBeginEnumWindows,
626 ORD_WinEndEnumWindows,
628 ORD_WinGetNextWindow,
630 ORD_WinQueryActiveWindow,
631 ORD_WinQueryClassName,
634 ORD_WinQueryWindowPos,
635 ORD_WinQueryWindowProcess,
636 ORD_WinQueryWindowText,
637 ORD_WinQueryWindowTextLength,
640 ORD_WinSetWindowText,
644 ORD_WinWindowFromPoint,
647 ORD_WinEnableWindowUpdate,
648 ORD_WinIsWindowEnabled,
649 ORD_WinIsWindowShowing,
650 ORD_WinIsWindowVisible,
651 ORD_WinQueryWindowPtr,
652 ORD_WinQueryWindowULong,
653 ORD_WinQueryWindowUShort,
654 ORD_WinSetWindowBits,
656 ORD_WinSetWindowULong,
657 ORD_WinSetWindowUShort,
658 ORD_WinQueryDesktopWindow,
659 ORD_WinSetActiveWindow,
660 ORD_DosQueryModFromEIP,
661 ORD_Dos32QueryHeaderInfo,
664 ORD_WinQueryActiveDesktopPathname,
665 ORD_WinInvalidateRect,
666 ORD_WinCreateFrameControls,
667 ORD_WinQueryClipbrdFmtInfo,
668 ORD_WinQueryClipbrdOwner,
669 ORD_WinQueryClipbrdViewer,
670 ORD_WinQueryClipbrdData,
673 ORD_WinSetClipbrdData,
674 ORD_WinSetClipbrdOwner,
675 ORD_WinSetClipbrdViewer,
676 ORD_WinEnumClipbrdFmts,
681 ORD_WinQueryAtomUsage,
682 ORD_WinQueryAtomName,
683 ORD_WinQueryAtomLength,
684 ORD_WinQuerySystemAtomTable,
685 ORD_WinCreateAtomTable,
686 ORD_WinDestroyAtomTable,
693 ORD_WinQuerySysValue,
698 ORD_WinQuerySysPointer,
699 ORD_DosReplaceModule,
701 ORD_RexxRegisterSubcomExe,
705 /* RET: return type, AT: argument signature in (), ARGS: should be in () */
706 #define CallORD(ret,o,at,args) (((ret (*)at) loadByOrdinal(o, 1))args)
707 #define DeclFuncByORD(ret,name,o,at,args) \
708 ret name at { return CallORD(ret,o,at,args); }
709 #define DeclVoidFuncByORD(name,o,at,args) \
710 void name at { CallORD(void,o,at,args); }
712 /* This function returns error code on error, and saves the error info in $^E and Perl_rc */
713 #define DeclOSFuncByORD_native(ret,name,o,at,args) \
714 ret name at { unsigned long rc; return CheckOSError(CallORD(ret,o,at,args)); }
716 /* These functions return false on error, and save the error info in $^E and Perl_rc */
717 #define DeclOSFuncByORD(ret,name,o,at,args) \
718 ret name at { unsigned long rc; return !CheckOSError(CallORD(ret,o,at,args)); }
719 #define DeclWinFuncByORD(ret,name,o,at,args) \
720 ret name at { return SaveWinError(CallORD(ret,o,at,args)); }
722 #define AssignFuncPByORD(p,o) (*(Perl_PFN*)&(p) = (loadByOrdinal(o, 1)))
724 /* This flavor caches the procedure pointer (named as p__Win#name) locally */
725 #define DeclWinFuncByORD_CACHE(ret,name,o,at,args) \
726 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,1)
728 /* This flavor may reset the last error before the call (if ret=0 may be OK) */
729 #define DeclWinFuncByORD_CACHE_resetError(ret,name,o,at,args) \
730 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,1)
732 /* Two flavors below do the same as above, but do not auto-croak */
733 /* This flavor caches the procedure pointer (named as p__Win#name) locally */
734 #define DeclWinFuncByORD_CACHE_survive(ret,name,o,at,args) \
735 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,0)
737 /* This flavor may reset the last error before the call (if ret=0 may be OK) */
738 #define DeclWinFuncByORD_CACHE_resetError_survive(ret,name,o,at,args) \
739 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,0)
741 #define DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,r,die) \
742 static ret (*CAT2(p__Win,name)) at; \
743 static ret name at { \
744 if (!CAT2(p__Win,name)) \
745 AssignFuncPByORD(CAT2(p__Win,name), o); \
746 if (r) ResetWinError(); \
747 return SaveCroakWinError(CAT2(p__Win,name) args, die, "[Win]", STRINGIFY(name)); }
749 /* These flavors additionally assume ORD is name with prepended ORD_Win */
750 #define DeclWinFunc_CACHE(ret,name,at,args) \
751 DeclWinFuncByORD_CACHE(ret,name,CAT2(ORD_Win,name),at,args)
752 #define DeclWinFunc_CACHE_resetError(ret,name,at,args) \
753 DeclWinFuncByORD_CACHE_resetError(ret,name,CAT2(ORD_Win,name),at,args)
754 #define DeclWinFunc_CACHE_survive(ret,name,at,args) \
755 DeclWinFuncByORD_CACHE_survive(ret,name,CAT2(ORD_Win,name),at,args)
756 #define DeclWinFunc_CACHE_resetError_survive(ret,name,at,args) \
757 DeclWinFuncByORD_CACHE_resetError_survive(ret,name,CAT2(ORD_Win,name),at,args)
759 void ResetWinError(void);
760 void CroakWinError(int die, char *name);
762 enum Perlos2_handler {
763 Perlos2_handler_mangle = 1,
764 Perlos2_handler_perl_sh,
765 Perlos2_handler_perllib_from,
766 Perlos2_handler_perllib_to,
770 dir_subst_pathlike = 2
773 extern int Perl_OS2_handler_install(void *handler, enum Perlos2_handler how);
774 extern char *dir_subst(char *s, unsigned int l, char *b, unsigned int bl, enum dir_subst_e flags, char *msg);
775 extern unsigned long fill_extLibpath(int type, char *pre, char *post, int replace, char *msg);
777 #define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
778 char *perllib_mangle(char *, unsigned int);
780 #define fork fork_with_resources
782 #ifdef EINTR /* x2p do not include perl.h!!! */
783 static __inline__ int
784 my_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
786 if (nfds == 0 && timeout && (_emx_env & 0x200)) {
787 if (async_mssleep(1000 * timeout->tv_sec + (timeout->tv_usec + 500)/1000, 500))
792 return select(nfds, readfds, writefds, exceptfds, timeout);
795 #define select my_select
799 typedef int (*Perl_PFN)();
800 Perl_PFN loadByOrdinal(enum entries_ordinals ord, int fail);
801 extern const Perl_PFN * const pExtFCN;
802 char *os2error(int rc);
803 int os2_stat(const char *name, struct stat *st);
804 int fork_with_resources();
805 int setpriority(int which, int pid, int val);
806 int getpriority(int which /* ignored */, int pid);
808 void croak_with_os2error(char *s) __attribute__((noreturn));
810 /* void return value */
811 #define os2cp_croak(rc,msg) (CheckOSError(rc) && (croak_with_os2error(msg),0))
814 #define os2win_croak(rc,msg) \
815 SaveCroakWinError((expr), 1 /* die */, /* no prefix */, (msg))
817 /* propagates rc; use with functions which may return 0 on success */
818 #define os2win_croak_0OK(rc,msg) \
819 SaveCroakWinError((ResetWinError, (expr)), \
820 1 /* die */, /* no prefix */, (msg))
823 int os2_do_spawn(pTHX_ char *cmd);
824 int os2_do_aspawn(pTHX_ SV *really, SV **vmark, SV **vsp);
829 /* Replacement for syslog.h */
830 # define LOG_EMERG 0 /* system is unusable */
831 # define LOG_ALERT 1 /* action must be taken immediately */
832 # define LOG_CRIT 2 /* critical conditions */
833 # define LOG_ERR 3 /* error conditions */
834 # define LOG_WARNING 4 /* warning conditions */
835 # define LOG_NOTICE 5 /* normal but significant condition */
836 # define LOG_INFO 6 /* informational */
837 # define LOG_DEBUG 7 /* debug-level messages */
839 # define LOG_PRIMASK 0x007 /* mask to extract priority part (internal) */
840 /* extract priority */
841 # define LOG_PRI(p) ((p) & LOG_PRIMASK)
842 # define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
845 # define LOG_KERN (0<<3) /* kernel messages */
846 # define LOG_USER (1<<3) /* random user-level messages */
847 # define LOG_MAIL (2<<3) /* mail system */
848 # define LOG_DAEMON (3<<3) /* system daemons */
849 # define LOG_AUTH (4<<3) /* security/authorization messages */
850 # define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
851 # define LOG_LPR (6<<3) /* line printer subsystem */
852 # define LOG_NEWS (7<<3) /* network news subsystem */
853 # define LOG_UUCP (8<<3) /* UUCP subsystem */
854 # define LOG_CRON (15<<3) /* clock daemon */
855 /* other codes through 15 reserved for system use */
856 # define LOG_LOCAL0 (16<<3) /* reserved for local use */
857 # define LOG_LOCAL1 (17<<3) /* reserved for local use */
858 # define LOG_LOCAL2 (18<<3) /* reserved for local use */
859 # define LOG_LOCAL3 (19<<3) /* reserved for local use */
860 # define LOG_LOCAL4 (20<<3) /* reserved for local use */
861 # define LOG_LOCAL5 (21<<3) /* reserved for local use */
862 # define LOG_LOCAL6 (22<<3) /* reserved for local use */
863 # define LOG_LOCAL7 (23<<3) /* reserved for local use */
865 # define LOG_NFACILITIES 24 /* current number of facilities */
866 # define LOG_FACMASK 0x03f8 /* mask to extract facility part */
867 /* facility of pri */
868 # define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
871 * arguments to setlogmask.
873 # define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
874 # define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
877 * Option flags for openlog.
879 * LOG_ODELAY no longer does anything.
880 * LOG_NDELAY is the inverse of what it used to be.
882 # define LOG_PID 0x01 /* log the pid with each message */
883 # define LOG_CONS 0x02 /* log on the console if errors in sending */
884 # define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
885 # define LOG_NDELAY 0x08 /* don't delay open */
886 # define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
887 # define LOG_PERROR 0x20 /* log to stderr as well */
891 /* ************************************************* */
892 #ifndef MAKEPLINFOSEG
894 /* From $DDK\base32\rel\os2c\include\base\os2\16bit\infoseg.h + typedefs */
897 * The structure below defines the content and organization of the system
898 * information segment (InfoSeg). The actual table is statically defined in
899 * SDATA.ASM. Ring 0, read/write access is obtained by the clock device
900 * driver using the DevHlp GetDOSVar function. (GetDOSVar returns a ring 0,
901 * read-only selector to all other requestors.)
903 * In order to prevent an errant process from destroying the infoseg, two
904 * identical global infosegs are maintained. One is in the tiled shared
905 * arena and is accessible in user mode (and therefore can potentially be
906 * overwritten from ring 2), and the other is in the system arena and is
907 * accessible only in kernel mode. All kernel code (except the clock driver)
908 * is responsible for updating BOTH copies of the infoseg. The copy kept
909 * in the system arena is addressable as DOSGROUP:SISData, and the copy
910 * in the shared arena is addressable via a system arena alias. 16:16 and
911 * 0:32 pointers to the alias are stored in _Sis2.
914 typedef struct InfoSegGDT {
916 /* Time (offset 0x00) */
918 unsigned long SIS_BigTime; /* Time from 1-1-1970 in seconds */
919 unsigned long SIS_MsCount; /* Freerunning milliseconds counter */
920 unsigned char SIS_HrsTime; /* Hours */
921 unsigned char SIS_MinTime; /* Minutes */
922 unsigned char SIS_SecTime; /* Seconds */
923 unsigned char SIS_HunTime; /* Hundredths of seconds */
924 unsigned short SIS_TimeZone; /* Timezone in min from GMT (Set to EST) */
925 unsigned short SIS_ClkIntrvl; /* Timer interval (units=0.0001 secs) */
927 /* Date (offset 0x10) */
929 unsigned char SIS_DayDate; /* Day-of-month (1-31) */
930 unsigned char SIS_MonDate; /* Month (1-12) */
931 unsigned short SIS_YrsDate; /* Year (>= 1980) */
932 unsigned char SIS_DOWDate; /* Day-of-week (1-1-80 = Tues = 3) */
934 /* Version (offset 0x15) */
936 unsigned char SIS_VerMajor; /* Major version number */
937 unsigned char SIS_VerMinor; /* Minor version number */
938 unsigned char SIS_RevLettr; /* Revision letter */
940 /* System Status (offset 0x18) */
942 unsigned char SIS_CurScrnGrp; /* Fgnd screen group # */
943 unsigned char SIS_MaxScrnGrp; /* Maximum number of screen groups */
944 unsigned char SIS_HugeShfCnt; /* Shift count for huge segments */
945 unsigned char SIS_ProtMdOnly; /* Protect-mode-only indicator */
946 unsigned short SIS_FgndPID; /* Foreground process ID */
948 /* Scheduler Parms (offset 0x1E) */
950 unsigned char SIS_Dynamic; /* Dynamic variation flag (1=enabled) */
951 unsigned char SIS_MaxWait; /* Maxwait (seconds) */
952 unsigned short SIS_MinSlice; /* Minimum timeslice (milliseconds) */
953 unsigned short SIS_MaxSlice; /* Maximum timeslice (milliseconds) */
955 /* Boot Drive (offset 0x24) */
957 unsigned short SIS_BootDrv; /* Drive from which system was booted */
959 /* RAS Major Event Code Table (offset 0x26) */
961 unsigned char SIS_mec_table[32]; /* Table of RAS Major Event Codes (MECs) */
963 /* Additional Session Data (offset 0x46) */
965 unsigned char SIS_MaxVioWinSG; /* Max. no. of VIO windowable SG's */
966 unsigned char SIS_MaxPresMgrSG; /* Max. no. of Presentation Manager SG's */
968 /* Error logging Information (offset 0x48) */
970 unsigned short SIS_SysLog; /* Error Logging Status */
972 /* Additional RAS Information (offset 0x4A) */
974 unsigned short SIS_MMIOBase; /* Memory mapped I/O selector */
975 unsigned long SIS_MMIOAddr; /* Memory mapped I/O address */
977 /* Additional 2.0 Data (offset 0x50) */
979 unsigned char SIS_MaxVDMs; /* Max. no. of Virtual DOS machines */
980 unsigned char SIS_Reserved;
982 unsigned char SIS_perf_mec_table[32]; /* varga 6/5/97 Table of Perfomance Major Event Codes (MECS) varga*/
983 } GINFOSEG, *PGINFOSEG;
985 #define SIS_LEN sizeof(struct InfoSegGDT)
988 * InfoSeg LDT Data Segment Structure
990 * The structure below defines the content and organization of the system
991 * information in a special per-process segment to be accessible by the
992 * process through the LDT (read-only).
994 * As in the global infoseg, two copies of the current processes local
995 * infoseg exist, one accessible in both user and kernel mode, the other
996 * only in kernel mode. Kernel code is responsible for updating BOTH copies.
997 * Pointers to the local infoseg copy are stored in _Lis2.
999 * Note that only the currently running process has an extra copy of the
1000 * local infoseg. The copy is done at context switch time.
1003 typedef struct InfoSegLDT {
1004 unsigned short LIS_CurProcID; /* Current process ID */
1005 unsigned short LIS_ParProcID; /* Process ID of parent */
1006 unsigned short LIS_CurThrdPri; /* Current thread priority */
1007 unsigned short LIS_CurThrdID; /* Current thread ID */
1008 unsigned short LIS_CurScrnGrp; /* Screengroup */
1009 unsigned char LIS_ProcStatus; /* Process status bits */
1010 unsigned char LIS_fillbyte1; /* filler byte */
1011 unsigned short LIS_Fgnd; /* Current process is in foreground */
1012 unsigned char LIS_ProcType; /* Current process type */
1013 unsigned char LIS_fillbyte2; /* filler byte */
1015 unsigned short LIS_AX; /* @@V1 Environment selector */
1016 unsigned short LIS_BX; /* @@V1 Offset of command line start */
1017 unsigned short LIS_CX; /* @@V1 Length of Data Segment */
1018 unsigned short LIS_DX; /* @@V1 STACKSIZE from the .EXE file */
1019 unsigned short LIS_SI; /* @@V1 HEAPSIZE from the .EXE file */
1020 unsigned short LIS_DI; /* @@V1 Module handle of the application */
1021 unsigned short LIS_DS; /* @@V1 Data Segment Handle of application */
1023 unsigned short LIS_PackSel; /* First tiled selector in this EXE */
1024 unsigned short LIS_PackShrSel; /* First selector above shared arena */
1025 unsigned short LIS_PackPckSel; /* First selector above packed arena */
1027 unsigned long LIS_pTIB; /* Pointer to TIB */
1028 unsigned long LIS_pPIB; /* Pointer to PIB */
1030 } LINFOSEG, *PLINFOSEG;
1032 #define LIS_LEN sizeof(struct InfoSegLDT)
1036 * Process Type codes
1038 * These are the definitons for the codes stored
1039 * in the LIS_ProcType field in the local infoseg.
1042 #define LIS_PT_FULLSCRN 0 /* Full screen app. */
1043 #define LIS_PT_REALMODE 1 /* Real mode process */
1044 #define LIS_PT_VIOWIN 2 /* VIO windowable app. */
1045 #define LIS_PT_PRESMGR 3 /* Presentation Manager app. */
1046 #define LIS_PT_DETACHED 4 /* Detached app. */
1051 * Process Status Bit Definitions
1055 #define LIS_PS_EXITLIST 0x01 /* In exitlist handler */
1059 * Flags equates for the Global Info Segment
1060 * SIS_SysLog WORD in Global Info Segment
1062 * xxxx xxxx xxxx xxx0 Error Logging Disabled
1063 * xxxx xxxx xxxx xxx1 Error Logging Enabled
1065 * xxxx xxxx xxxx xx0x Error Logging not available
1066 * xxxx xxxx xxxx xx1x Error Logging available
1069 #define LF_LOGENABLE 0x0001 /* Logging enabled */
1070 #define LF_LOGAVAILABLE 0x0002 /* Logging available */
1072 #define MAKEPGINFOSEG(sel) ((PGINFOSEG)MAKEP(sel, 0))
1073 #define MAKEPLINFOSEG(sel) ((PLINFOSEG)MAKEP(sel, 0))
1075 #endif /* ndef(MAKEPLINFOSEG) */
1077 /* ************************************************************ */
1078 #define Dos32QuerySysState DosQuerySysState
1079 #define QuerySysState(flags, pid, buf, bufsz) \
1080 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
1082 #define QSS_PROCESS 1
1083 #define QSS_MODULE 4
1084 #define QSS_SEMAPHORES 2
1085 #define QSS_FILE 8 /* Buggy until fixpack18 */
1086 #define QSS_SHARED 16
1090 APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
1091 ULONG _res_,PVOID buf,ULONG bufsz);
1096 } QGLOBAL, *PQGLOBAL;
1107 UCHAR _reserved1_; /* padding to ULONG */
1108 USHORT _reserved2_; /* padding to ULONG */
1109 } QTHREAD, *PQTHREAD;
1124 typedef struct qfile {
1152 } QPROCESS, *PQPROCESS;
1154 typedef struct sema {
1171 } QSEMSTRUC, *PQSEMSTRUC;
1176 } QSEMOWNER32, *PQSEMOWNER32;
1181 PVOID semrecs; /* array of associated sema's */
1185 USHORT _reserved_; /* padding to ULONG */
1186 } QSEMSMUX32, *PQSEMSMUX32;
1194 } QSEMEV32, *PQSEMEV32;
1203 USHORT _reserved_; /* padding to ULONG */
1204 } QSEMMUX32, *PQSEMMUX32;
1206 typedef struct semstr32 {
1207 struct semstr *next;
1211 } QSEMSTRUC32, *PQSEMSTRUC32;
1213 typedef struct shrmem {
1214 struct shrmem *next;
1219 } QSHRMEM, *PQSHRMEM;
1221 typedef struct module {
1222 struct module *next;
1230 } QMODULE, *PQMODULE;
1235 PQSEMSTRUC semadata;
1236 PQSEMSTRUC32 sem32data;
1237 PQSHRMEM shrmemdata;
1241 } QTOPLEVEL, *PQTOPLEVEL;
1242 /* ************************************************************ */
1244 PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);