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 /* BIG_TIME: 18 * This symbol is defined if Time_t is an unsigned type on this system. 19 */ 20 #define BIG_TIME 21 22 #define HAS_KILL 23 #define HAS_WAIT 24 #define HAS_DLERROR 25 #define HAS_WAITPID_RUNTIME (_emx_env & 0x200) 26 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 44 /* USEMYBINMODE 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. 49 */ 50 #undef USEMYBINMODE 51 52 #define SOCKET_OPEN_MODE "b" 53 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 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 /**/ 74 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 */ 85 #define ALTERNATE_SHEBANG "extproc " 86 87 #ifndef SIGABRT 88 # define SIGABRT SIGILL 89 #endif 90 #ifndef SIGILL 91 # define SIGILL 6 /* blech */ 92 #endif 93 #define ABORT() kill(PerlProc_getpid(),SIGABRT); 94 95 #define BIT_BUCKET "/dev/nul" /* Will this work? */ 96 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 104 #if defined(I_SYS_UN) && !defined(TCPIPV4) 105 /* It is not working without TCPIPV4 defined. */ 106 # undef I_SYS_UN 107 #endif 108 109 #if defined(USE_5005THREADS) || defined(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 116 extern 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. */ 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 */ 209 210 #define THREADS_ELSEWHERE 211 212 #else /* USE_5005THREADS */ 213 214 #define do_spawn(a) os2_do_spawn(a) 215 #define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c)) 216 217 #endif /* USE_5005THREADS */ 218 219 void Perl_OS2_init(char **); 220 void Perl_OS2_init3(char **envp, void **excH, int flags); 221 void Perl_OS2_term(void **excH, int exitstatus, int flags); 222 223 /* The code without INIT3 hideously puts env inside: */ 224 225 /* These ones should be in the same block as PERL_SYS_TERM() */ 226 #ifdef PERL_CORE 227 228 # define PERL_SYS_INIT3(argcp, argvp, envp) \ 229 { void *xreg[2]; \ 230 MALLOC_CHECK_TAINT(*argcp, *argvp, *envp) \ 231 _response(argcp, argvp); \ 232 _wildcard(argcp, argvp); \ 233 Perl_OS2_init3(*envp, xreg, 0) 234 235 # define PERL_SYS_INIT(argcp, argvp) { \ 236 { void *xreg[2]; \ 237 _response(argcp, argvp); \ 238 _wildcard(argcp, argvp); \ 239 Perl_OS2_init3(NULL, xreg, 0) 240 241 #else /* Compiling embedded Perl or Perl extension */ 242 243 # define PERL_SYS_INIT3(argcp, argvp, envp) \ 244 { void *xreg[2]; \ 245 Perl_OS2_init3(*envp, xreg, 0) 246 # define PERL_SYS_INIT(argcp, argvp) { \ 247 { void *xreg[2]; \ 248 Perl_OS2_init3(NULL, xreg, 0) 249 #endif 250 251 #define FORCE_EMX_DEINIT_EXIT 1 252 #define FORCE_EMX_DEINIT_CRT_TERM 2 253 #define FORCE_EMX_DEINIT_RUN_ATEXIT 4 254 255 #define PERL_SYS_TERM2(xreg,flags) \ 256 Perl_OS2_term(xreg, 0, flags); \ 257 MALLOC_TERM 258 259 #define PERL_SYS_TERM1(xreg) \ 260 Perl_OS2_term(xreg, 0, FORCE_EMX_DEINIT_RUN_ATEXIT) 261 262 /* This one should come in pair with PERL_SYS_INIT() and in the same block */ 263 #define PERL_SYS_TERM() \ 264 PERL_SYS_TERM1(xreg); \ 265 } 266 267 #ifndef __EMX__ 268 # define PERL_CALLCONV _System 269 #endif 270 271 /* #define PERL_SYS_TERM() STMT_START { \ 272 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */ 273 274 #define dXSUB_SYS OS2_XS_init() 275 276 #ifdef PERL_IS_AOUT 277 /* # define HAS_FORK */ 278 /* # define HIDEMYMALLOC */ 279 /* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */ 280 #else /* !PERL_IS_AOUT */ 281 # ifndef PERL_FOR_X2P 282 # ifdef EMX_BAD_SBRK 283 # define USE_PERL_SBRK 284 # endif 285 # else 286 # define PerlIO FILE 287 # endif 288 # define SYSTEM_ALLOC(a) sys_alloc(a) 289 290 void *sys_alloc(int size); 291 292 #endif /* !PERL_IS_AOUT */ 293 #if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */ 294 # define PerlIO FILE 295 #endif 296 297 /* os2ish is used from a2p/a2p.h without pTHX/pTHX_ first being 298 * defined. Hack around this to get us to compile. 299 */ 300 #ifdef PTHX_UNUSED 301 # ifndef pTHX 302 # define pTHX 303 # endif 304 # ifndef pTHX_ 305 # define pTHX_ 306 # endif 307 #endif 308 309 #define TMPPATH1 "plXXXXXX" 310 extern const char *tmppath; 311 PerlIO *my_syspopen(pTHX_ char *cmd, char *mode); 312 /* Cannot prototype with I32 at this point. */ 313 int my_syspclose(PerlIO *f); 314 FILE *my_tmpfile (void); 315 char *my_tmpnam (char *); 316 int my_mkdir (__const__ char *, long); 317 int my_rmdir (__const__ char *); 318 struct passwd *my_getpwent (void); 319 void my_setpwent (void); 320 void my_endpwent (void); 321 char *gcvt_os2(double value, int digits, char *buffer); 322 323 #define MAX_SLEEP (((1<30) / (1000/4))-1) /* 1<32 msec */ 324 325 static __inline__ unsigned 326 my_sleep(unsigned sec) 327 { 328 int remain; 329 while (sec > MAX_SLEEP) { 330 sec -= MAX_SLEEP; 331 remain = sleep(MAX_SLEEP); 332 if (remain) 333 return remain + sec; 334 } 335 return sleep(sec); 336 } 337 338 #define sleep my_sleep 339 340 #ifndef INCL_DOS 341 unsigned long DosSleep(unsigned long); 342 unsigned long DosAllocThreadLocalMemory (unsigned long cb, unsigned long **p); 343 #endif 344 345 struct group *getgrent (void); 346 void setgrent (void); 347 void endgrent (void); 348 349 struct passwd *my_getpwuid (uid_t); 350 struct passwd *my_getpwnam (__const__ char *); 351 352 #undef L_tmpnam 353 #define L_tmpnam MAXPATHLEN 354 355 #define tmpfile my_tmpfile 356 #define tmpnam my_tmpnam 357 #define isatty _isterm 358 #define rand random 359 #define srand srandom 360 #define strtoll _strtoll 361 #define strtoull _strtoull 362 363 #define usleep(usec) ((void)_sleep2(((usec)+500)/1000)) 364 365 366 /* 367 * fwrite1() should be a routine with the same calling sequence as fwrite(), 368 * but which outputs all of the bytes requested as a single stream (unlike 369 * fwrite() itself, which on some systems outputs several distinct records 370 * if the number_of_items parameter is >1). 371 */ 372 #define fwrite1 fwrite 373 374 #define my_getenv(var) getenv(var) 375 #define flock my_flock 376 #define rmdir my_rmdir 377 #define mkdir my_mkdir 378 #define setpwent my_setpwent 379 #define getpwent my_getpwent 380 #define endpwent my_endpwent 381 #define getpwuid my_getpwuid 382 #define getpwnam my_getpwnam 383 384 void *emx_calloc (size_t, size_t); 385 void emx_free (void *); 386 void *emx_malloc (size_t); 387 void *emx_realloc (void *, size_t); 388 389 /*****************************************************************************/ 390 391 #include <stdlib.h> /* before the following definitions */ 392 #include <unistd.h> /* before the following definitions */ 393 #include <fcntl.h> 394 #include <sys/stat.h> 395 396 #define chdir _chdir2 397 #define getcwd _getcwd2 398 399 /* This guy is needed for quick stdstd */ 400 401 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE) 402 /* Perl uses ungetc only with successful return */ 403 # define ungetc(c,fp) \ 404 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \ 405 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp)) 406 #endif 407 408 #define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd) 409 410 #ifdef __GNUG__ 411 # define HAS_BOOL 412 #endif 413 #ifndef HAS_BOOL 414 # define bool char 415 # define HAS_BOOL 1 416 #endif 417 418 #include <emx/io.h> /* for _fd_flags() prototype */ 419 420 static inline bool 421 _PERLIO_IS_BINMODE_FD(int fd) 422 { 423 int *pflags = _fd_flags(fd); 424 425 return pflags && (*pflags) & O_BINARY; 426 } 427 428 /* ctermid is missing from emx0.9d */ 429 char *ctermid(char *s); 430 431 #define OP_BINARY O_BINARY 432 433 #define OS2_STAT_HACK 1 434 #if OS2_STAT_HACK 435 436 #define Stat(fname,bufptr) os2_stat((fname),(bufptr)) 437 #define Fstat(fd,bufptr) os2_fstat((fd),(bufptr)) 438 #define Fflush(fp) fflush(fp) 439 #define Mkdir(path,mode) mkdir((path),(mode)) 440 #define chmod(path,mode) os2_chmod((path),(mode)) 441 442 #undef S_IFBLK 443 #undef S_ISBLK 444 #define S_IFBLK 0120000 /* Hacks to make things compile... */ 445 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 446 447 int os2_chmod(const char *name, int pmode); 448 int os2_fstat(int handle, struct stat *st); 449 450 #else 451 452 #define Stat(fname,bufptr) stat((fname),(bufptr)) 453 #define Fstat(fd,bufptr) fstat((fd),(bufptr)) 454 #define Fflush(fp) fflush(fp) 455 #define Mkdir(path,mode) mkdir((path),(mode)) 456 457 #endif 458 459 /* With SD386 it is impossible to debug register variables. */ 460 #if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register) 461 # define register 462 #endif 463 464 /* Our private OS/2 specific data. */ 465 466 typedef struct OS2_Perl_data { 467 unsigned long flags; 468 unsigned long phab; 469 int (*xs_init)(); 470 unsigned long rc; 471 unsigned long severity; 472 unsigned long phmq; /* Handle to message queue */ 473 unsigned long phmq_refcnt; 474 unsigned long phmq_servers; 475 unsigned long initial_mode; /* VIO etc. mode we were started in */ 476 unsigned long morph_refcnt; 477 } OS2_Perl_data_t; 478 479 extern OS2_Perl_data_t OS2_Perl_data; 480 481 #define Perl_hab ((HAB)OS2_Perl_data.phab) 482 #define Perl_rc (OS2_Perl_data.rc) 483 #define Perl_severity (OS2_Perl_data.severity) 484 #define errno_isOS2 12345678 485 #define errno_isOS2_set 12345679 486 #define OS2_Perl_flags (OS2_Perl_data.flags) 487 #define Perl_HAB_set_f 1 488 #define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f) 489 #define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f) 490 #define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h) 491 #define _obtain_Perl_HAB (init_PMWIN_entries(), \ 492 Perl_hab = (*PMWIN_entries.Initialize)(0), \ 493 set_Perl_HAB_f, Perl_hab) 494 #define perl_hab_GET() (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB) 495 #define Acquire_hab() perl_hab_GET() 496 #define Perl_hmq ((HMQ)OS2_Perl_data.phmq) 497 #define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt) 498 #define Perl_hmq_servers (OS2_Perl_data.phmq_servers) 499 #define Perl_os2_initial_mode (OS2_Perl_data.initial_mode) 500 #define Perl_morph_refcnt (OS2_Perl_data.morph_refcnt) 501 502 unsigned long Perl_hab_GET(); 503 unsigned long Perl_Register_MQ(int serve); 504 void Perl_Deregister_MQ(int serve); 505 int Perl_Serve_Messages(int force); 506 /* Cannot prototype with I32 at this point. */ 507 int Perl_Process_Messages(int force, long *cntp); 508 char *os2_execname(pTHX); 509 510 struct _QMSG; 511 struct PMWIN_entries_t { 512 unsigned long (*Initialize)( unsigned long fsOptions ); 513 unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg); 514 int (*DestroyMsgQueue)(unsigned long hmq); 515 int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg, 516 unsigned long hwndFilter, unsigned long msgFilterFirst, 517 unsigned long msgFilterLast, unsigned long fl); 518 int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg, 519 unsigned long hwndFilter, unsigned long msgFilterFirst, 520 unsigned long msgFilterLast); 521 void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg); 522 unsigned long (*GetLastError)(unsigned long hab); 523 unsigned long (*CancelShutdown)(unsigned long hmq, unsigned long fCancelAlways); 524 }; 525 extern struct PMWIN_entries_t PMWIN_entries; 526 void init_PMWIN_entries(void); 527 528 #define perl_hmq_GET(serve) Perl_Register_MQ(serve) 529 #define perl_hmq_UNSET(serve) Perl_Deregister_MQ(serve) 530 531 #define OS2_XS_init() (*OS2_Perl_data.xs_init)(aTHX) 532 533 #if _EMX_CRT_REV_ >= 60 534 # define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2_set, \ 535 _setsyserrno(rc)) 536 #else 537 # define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2) 538 #endif 539 540 /* The expressions below return true on error. */ 541 /* INCL_DOSERRORS needed. rc should be declared outside. */ 542 #define CheckOSError(expr) ((rc = (expr)) ? (FillOSError(rc), rc) : 0) 543 /* INCL_WINERRORS needed. */ 544 #define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1)) 545 546 /* This form propagates the return value, setting $^E if needed */ 547 #define SaveWinError(expr) ((expr) ? : (FillWinError, 0)) 548 549 /* This form propagates the return value, dieing with $^E if needed */ 550 #define SaveCroakWinError(expr,die,name1,name2) \ 551 ((expr) ? : (CroakWinError(die,name1 name2), 0)) 552 553 #define FillOSError(rc) (os2_setsyserrno(rc), \ 554 Perl_severity = SEVERITY_ERROR) 555 556 #define WinError_2_Perl_rc \ 557 ( init_PMWIN_entries(), \ 558 Perl_rc=(*PMWIN_entries.GetLastError)(perl_hab_GET()) ) 559 560 /* Calling WinGetLastError() resets the error code of the current thread. 561 Since for some Win* API return value 0 is normal, one needs to call 562 this before calling them to distinguish normal and anomalous returns. */ 563 /*#define ResetWinError() WinError_2_Perl_rc */ 564 565 /* At this moment init_PMWIN_entries() should be a nop (WinInitialize should 566 be called already, right?), so we do not risk stepping over our own error */ 567 #define FillWinError ( WinError_2_Perl_rc, \ 568 Perl_severity = ERRORIDSEV(Perl_rc), \ 569 Perl_rc = ERRORIDERROR(Perl_rc), \ 570 os2_setsyserrno(Perl_rc)) 571 572 #define STATIC_FILE_LENGTH 127 573 574 /* This should match loadOrdinals[] array in os2.c */ 575 enum entries_ordinals { 576 ORD_DosQueryExtLibpath, 577 ORD_DosSetExtLibpath, 578 ORD_DosVerifyPidTid, 579 ORD_SETHOSTENT, 580 ORD_SETNETENT, 581 ORD_SETPROTOENT, 582 ORD_SETSERVENT, 583 ORD_GETHOSTENT, 584 ORD_GETNETENT, 585 ORD_GETPROTOENT, 586 ORD_GETSERVENT, 587 ORD_ENDHOSTENT, 588 ORD_ENDNETENT, 589 ORD_ENDPROTOENT, 590 ORD_ENDSERVENT, 591 ORD_WinInitialize, 592 ORD_WinCreateMsgQueue, 593 ORD_WinDestroyMsgQueue, 594 ORD_WinPeekMsg, 595 ORD_WinGetMsg, 596 ORD_WinDispatchMsg, 597 ORD_WinGetLastError, 598 ORD_WinCancelShutdown, 599 ORD_RexxStart, 600 ORD_RexxVariablePool, 601 ORD_RexxRegisterFunctionExe, 602 ORD_RexxDeregisterFunction, 603 ORD_DOSSMSETTITLE, 604 ORD_PRF32QUERYPROFILESIZE, 605 ORD_PRF32OPENPROFILE, 606 ORD_PRF32CLOSEPROFILE, 607 ORD_PRF32QUERYPROFILE, 608 ORD_PRF32RESET, 609 ORD_PRF32QUERYPROFILEDATA, 610 ORD_PRF32WRITEPROFILEDATA, 611 612 ORD_WinChangeSwitchEntry, 613 ORD_WinQuerySwitchEntry, 614 ORD_WinQuerySwitchHandle, 615 ORD_WinQuerySwitchList, 616 ORD_WinSwitchToProgram, 617 ORD_WinBeginEnumWindows, 618 ORD_WinEndEnumWindows, 619 ORD_WinEnumDlgItem, 620 ORD_WinGetNextWindow, 621 ORD_WinIsChild, 622 ORD_WinQueryActiveWindow, 623 ORD_WinQueryClassName, 624 ORD_WinQueryFocus, 625 ORD_WinQueryWindow, 626 ORD_WinQueryWindowPos, 627 ORD_WinQueryWindowProcess, 628 ORD_WinQueryWindowText, 629 ORD_WinQueryWindowTextLength, 630 ORD_WinSetFocus, 631 ORD_WinSetWindowPos, 632 ORD_WinSetWindowText, 633 ORD_WinShowWindow, 634 ORD_WinIsWindow, 635 ORD_WinWindowFromId, 636 ORD_WinWindowFromPoint, 637 ORD_WinPostMsg, 638 ORD_WinEnableWindow, 639 ORD_WinEnableWindowUpdate, 640 ORD_WinIsWindowEnabled, 641 ORD_WinIsWindowShowing, 642 ORD_WinIsWindowVisible, 643 ORD_WinQueryWindowPtr, 644 ORD_WinQueryWindowULong, 645 ORD_WinQueryWindowUShort, 646 ORD_WinSetWindowBits, 647 ORD_WinSetWindowPtr, 648 ORD_WinSetWindowULong, 649 ORD_WinSetWindowUShort, 650 ORD_WinQueryDesktopWindow, 651 ORD_WinSetActiveWindow, 652 ORD_DosQueryModFromEIP, 653 ORD_Dos32QueryHeaderInfo, 654 ORD_DosTmrQueryFreq, 655 ORD_DosTmrQueryTime, 656 ORD_WinQueryActiveDesktopPathname, 657 ORD_WinInvalidateRect, 658 ORD_WinCreateFrameControls, 659 ORD_WinQueryClipbrdFmtInfo, 660 ORD_WinQueryClipbrdOwner, 661 ORD_WinQueryClipbrdViewer, 662 ORD_WinQueryClipbrdData, 663 ORD_WinOpenClipbrd, 664 ORD_WinCloseClipbrd, 665 ORD_WinSetClipbrdData, 666 ORD_WinSetClipbrdOwner, 667 ORD_WinSetClipbrdViewer, 668 ORD_WinEnumClipbrdFmts, 669 ORD_WinEmptyClipbrd, 670 ORD_WinAddAtom, 671 ORD_WinFindAtom, 672 ORD_WinDeleteAtom, 673 ORD_WinQueryAtomUsage, 674 ORD_WinQueryAtomName, 675 ORD_WinQueryAtomLength, 676 ORD_WinQuerySystemAtomTable, 677 ORD_WinCreateAtomTable, 678 ORD_WinDestroyAtomTable, 679 ORD_WinOpenWindowDC, 680 ORD_DevOpenDC, 681 ORD_DevQueryCaps, 682 ORD_DevCloseDC, 683 ORD_WinMessageBox, 684 ORD_WinMessageBox2, 685 ORD_WinQuerySysValue, 686 ORD_WinSetSysValue, 687 ORD_WinAlarm, 688 ORD_WinFlashWindow, 689 ORD_WinLoadPointer, 690 ORD_WinQuerySysPointer, 691 ORD_DosReplaceModule, 692 ORD_DosPerfSysCall, 693 ORD_RexxRegisterSubcomExe, 694 ORD_NENTRIES 695 }; 696 697 /* RET: return type, AT: argument signature in (), ARGS: should be in () */ 698 #define CallORD(ret,o,at,args) (((ret (*)at) loadByOrdinal(o, 1))args) 699 #define DeclFuncByORD(ret,name,o,at,args) \ 700 ret name at { return CallORD(ret,o,at,args); } 701 #define DeclVoidFuncByORD(name,o,at,args) \ 702 void name at { CallORD(void,o,at,args); } 703 704 /* This function returns error code on error, and saves the error info in $^E and Perl_rc */ 705 #define DeclOSFuncByORD_native(ret,name,o,at,args) \ 706 ret name at { unsigned long rc; return CheckOSError(CallORD(ret,o,at,args)); } 707 708 /* These functions return false on error, and save the error info in $^E and Perl_rc */ 709 #define DeclOSFuncByORD(ret,name,o,at,args) \ 710 ret name at { unsigned long rc; return !CheckOSError(CallORD(ret,o,at,args)); } 711 #define DeclWinFuncByORD(ret,name,o,at,args) \ 712 ret name at { return SaveWinError(CallORD(ret,o,at,args)); } 713 714 #define AssignFuncPByORD(p,o) (*(Perl_PFN*)&(p) = (loadByOrdinal(o, 1))) 715 716 /* This flavor caches the procedure pointer (named as p__Win#name) locally */ 717 #define DeclWinFuncByORD_CACHE(ret,name,o,at,args) \ 718 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,1) 719 720 /* This flavor may reset the last error before the call (if ret=0 may be OK) */ 721 #define DeclWinFuncByORD_CACHE_resetError(ret,name,o,at,args) \ 722 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,1) 723 724 /* Two flavors below do the same as above, but do not auto-croak */ 725 /* This flavor caches the procedure pointer (named as p__Win#name) locally */ 726 #define DeclWinFuncByORD_CACHE_survive(ret,name,o,at,args) \ 727 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,0) 728 729 /* This flavor may reset the last error before the call (if ret=0 may be OK) */ 730 #define DeclWinFuncByORD_CACHE_resetError_survive(ret,name,o,at,args) \ 731 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,0) 732 733 #define DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,r,die) \ 734 static ret (*CAT2(p__Win,name)) at; \ 735 static ret name at { \ 736 if (!CAT2(p__Win,name)) \ 737 AssignFuncPByORD(CAT2(p__Win,name), o); \ 738 if (r) ResetWinError(); \ 739 return SaveCroakWinError(CAT2(p__Win,name) args, die, "[Win]", STRINGIFY(name)); } 740 741 /* These flavors additionally assume ORD is name with prepended ORD_Win */ 742 #define DeclWinFunc_CACHE(ret,name,at,args) \ 743 DeclWinFuncByORD_CACHE(ret,name,CAT2(ORD_Win,name),at,args) 744 #define DeclWinFunc_CACHE_resetError(ret,name,at,args) \ 745 DeclWinFuncByORD_CACHE_resetError(ret,name,CAT2(ORD_Win,name),at,args) 746 #define DeclWinFunc_CACHE_survive(ret,name,at,args) \ 747 DeclWinFuncByORD_CACHE_survive(ret,name,CAT2(ORD_Win,name),at,args) 748 #define DeclWinFunc_CACHE_resetError_survive(ret,name,at,args) \ 749 DeclWinFuncByORD_CACHE_resetError_survive(ret,name,CAT2(ORD_Win,name),at,args) 750 751 void ResetWinError(void); 752 void CroakWinError(int die, char *name); 753 754 #define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n)) 755 char *perllib_mangle(char *, unsigned int); 756 757 #define fork fork_with_resources 758 759 #ifdef EINTR /* x2p do not include perl.h!!! */ 760 static __inline__ int 761 my_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) 762 { 763 if (nfds == 0 && timeout && (_emx_env & 0x200)) { 764 if (DosSleep(1000 * timeout->tv_sec + (timeout->tv_usec + 500)/1000) == 0) 765 return 0; 766 errno = EINTR; 767 return -1; 768 } 769 return select(nfds, readfds, writefds, exceptfds, timeout); 770 } 771 772 #define select my_select 773 #endif 774 775 776 typedef int (*Perl_PFN)(); 777 Perl_PFN loadByOrdinal(enum entries_ordinals ord, int fail); 778 extern const Perl_PFN * const pExtFCN; 779 char *os2error(int rc); 780 int os2_stat(const char *name, struct stat *st); 781 int fork_with_resources(); 782 int setpriority(int which, int pid, int val); 783 int getpriority(int which /* ignored */, int pid); 784 785 void croak_with_os2error(char *s) __attribute__((noreturn)); 786 787 #ifdef PERL_CORE 788 int os2_do_spawn(pTHX_ char *cmd); 789 int os2_do_aspawn(pTHX_ SV *really, SV **vmark, SV **vsp); 790 #endif 791 792 #ifndef LOG_DAEMON 793 794 /* Replacement for syslog.h */ 795 # define LOG_EMERG 0 /* system is unusable */ 796 # define LOG_ALERT 1 /* action must be taken immediately */ 797 # define LOG_CRIT 2 /* critical conditions */ 798 # define LOG_ERR 3 /* error conditions */ 799 # define LOG_WARNING 4 /* warning conditions */ 800 # define LOG_NOTICE 5 /* normal but significant condition */ 801 # define LOG_INFO 6 /* informational */ 802 # define LOG_DEBUG 7 /* debug-level messages */ 803 804 # define LOG_PRIMASK 0x007 /* mask to extract priority part (internal) */ 805 /* extract priority */ 806 # define LOG_PRI(p) ((p) & LOG_PRIMASK) 807 # define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) 808 809 /* facility codes */ 810 # define LOG_KERN (0<<3) /* kernel messages */ 811 # define LOG_USER (1<<3) /* random user-level messages */ 812 # define LOG_MAIL (2<<3) /* mail system */ 813 # define LOG_DAEMON (3<<3) /* system daemons */ 814 # define LOG_AUTH (4<<3) /* security/authorization messages */ 815 # define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ 816 # define LOG_LPR (6<<3) /* line printer subsystem */ 817 # define LOG_NEWS (7<<3) /* network news subsystem */ 818 # define LOG_UUCP (8<<3) /* UUCP subsystem */ 819 # define LOG_CRON (15<<3) /* clock daemon */ 820 /* other codes through 15 reserved for system use */ 821 # define LOG_LOCAL0 (16<<3) /* reserved for local use */ 822 # define LOG_LOCAL1 (17<<3) /* reserved for local use */ 823 # define LOG_LOCAL2 (18<<3) /* reserved for local use */ 824 # define LOG_LOCAL3 (19<<3) /* reserved for local use */ 825 # define LOG_LOCAL4 (20<<3) /* reserved for local use */ 826 # define LOG_LOCAL5 (21<<3) /* reserved for local use */ 827 # define LOG_LOCAL6 (22<<3) /* reserved for local use */ 828 # define LOG_LOCAL7 (23<<3) /* reserved for local use */ 829 830 # define LOG_NFACILITIES 24 /* current number of facilities */ 831 # define LOG_FACMASK 0x03f8 /* mask to extract facility part */ 832 /* facility of pri */ 833 # define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) 834 835 /* 836 * arguments to setlogmask. 837 */ 838 # define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ 839 # define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ 840 841 /* 842 * Option flags for openlog. 843 * 844 * LOG_ODELAY no longer does anything. 845 * LOG_NDELAY is the inverse of what it used to be. 846 */ 847 # define LOG_PID 0x01 /* log the pid with each message */ 848 # define LOG_CONS 0x02 /* log on the console if errors in sending */ 849 # define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ 850 # define LOG_NDELAY 0x08 /* don't delay open */ 851 # define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ 852 # define LOG_PERROR 0x20 /* log to stderr as well */ 853 854 #endif 855 856 /* ************************************************************ */ 857 #define Dos32QuerySysState DosQuerySysState 858 #define QuerySysState(flags, pid, buf, bufsz) \ 859 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz) 860 861 #define QSS_PROCESS 1 862 #define QSS_MODULE 4 863 #define QSS_SEMAPHORES 2 864 #define QSS_FILE 8 /* Buggy until fixpack18 */ 865 #define QSS_SHARED 16 866 867 #ifdef _OS2_H 868 869 APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid, 870 ULONG _res_,PVOID buf,ULONG bufsz); 871 typedef struct { 872 ULONG threadcnt; 873 ULONG proccnt; 874 ULONG modulecnt; 875 } QGLOBAL, *PQGLOBAL; 876 877 typedef struct { 878 ULONG rectype; 879 USHORT threadid; 880 USHORT slotid; 881 ULONG sleepid; 882 ULONG priority; 883 ULONG systime; 884 ULONG usertime; 885 UCHAR state; 886 UCHAR _reserved1_; /* padding to ULONG */ 887 USHORT _reserved2_; /* padding to ULONG */ 888 } QTHREAD, *PQTHREAD; 889 890 typedef struct { 891 USHORT sfn; 892 USHORT refcnt; 893 USHORT flags1; 894 USHORT flags2; 895 USHORT accmode1; 896 USHORT accmode2; 897 ULONG filesize; 898 USHORT volhnd; 899 USHORT attrib; 900 USHORT _reserved_; 901 } QFDS, *PQFDS; 902 903 typedef struct qfile { 904 ULONG rectype; 905 struct qfile *next; 906 ULONG opencnt; 907 PQFDS filedata; 908 char name[1]; 909 } QFILE, *PQFILE; 910 911 typedef struct { 912 ULONG rectype; 913 PQTHREAD threads; 914 USHORT pid; 915 USHORT ppid; 916 ULONG type; 917 ULONG state; 918 ULONG sessid; 919 USHORT hndmod; 920 USHORT threadcnt; 921 ULONG privsem32cnt; 922 ULONG _reserved2_; 923 USHORT sem16cnt; 924 USHORT dllcnt; 925 USHORT shrmemcnt; 926 USHORT fdscnt; 927 PUSHORT sem16s; 928 PUSHORT dlls; 929 PUSHORT shrmems; 930 PUSHORT fds; 931 } QPROCESS, *PQPROCESS; 932 933 typedef struct sema { 934 struct sema *next; 935 USHORT refcnt; 936 UCHAR sysflags; 937 UCHAR sysproccnt; 938 ULONG _reserved1_; 939 USHORT index; 940 CHAR name[1]; 941 } QSEMA, *PQSEMA; 942 943 typedef struct { 944 ULONG rectype; 945 ULONG _reserved1_; 946 USHORT _reserved2_; 947 USHORT syssemidx; 948 ULONG index; 949 QSEMA sema; 950 } QSEMSTRUC, *PQSEMSTRUC; 951 952 typedef struct { 953 USHORT pid; 954 USHORT opencnt; 955 } QSEMOWNER32, *PQSEMOWNER32; 956 957 typedef struct { 958 PQSEMOWNER32 own; 959 PCHAR name; 960 PVOID semrecs; /* array of associated sema's */ 961 USHORT flags; 962 USHORT semreccnt; 963 USHORT waitcnt; 964 USHORT _reserved_; /* padding to ULONG */ 965 } QSEMSMUX32, *PQSEMSMUX32; 966 967 typedef struct { 968 PQSEMOWNER32 own; 969 PCHAR name; 970 PQSEMSMUX32 mux; 971 USHORT flags; 972 USHORT postcnt; 973 } QSEMEV32, *PQSEMEV32; 974 975 typedef struct { 976 PQSEMOWNER32 own; 977 PCHAR name; 978 PQSEMSMUX32 mux; 979 USHORT flags; 980 USHORT refcnt; 981 USHORT thrdnum; 982 USHORT _reserved_; /* padding to ULONG */ 983 } QSEMMUX32, *PQSEMMUX32; 984 985 typedef struct semstr32 { 986 struct semstr *next; 987 QSEMEV32 evsem; 988 QSEMMUX32 muxsem; 989 QSEMSMUX32 smuxsem; 990 } QSEMSTRUC32, *PQSEMSTRUC32; 991 992 typedef struct shrmem { 993 struct shrmem *next; 994 USHORT hndshr; 995 USHORT selshr; 996 USHORT refcnt; 997 CHAR name[1]; 998 } QSHRMEM, *PQSHRMEM; 999 1000 typedef struct module { 1001 struct module *next; 1002 USHORT hndmod; 1003 USHORT type; 1004 ULONG refcnt; 1005 ULONG segcnt; 1006 PVOID _reserved_; 1007 PCHAR name; 1008 USHORT modref[1]; 1009 } QMODULE, *PQMODULE; 1010 1011 typedef struct { 1012 PQGLOBAL gbldata; 1013 PQPROCESS procdata; 1014 PQSEMSTRUC semadata; 1015 PQSEMSTRUC32 sem32data; 1016 PQSHRMEM shrmemdata; 1017 PQMODULE moddata; 1018 PVOID _reserved2_; 1019 PQFILE filedata; 1020 } QTOPLEVEL, *PQTOPLEVEL; 1021 /* ************************************************************ */ 1022 1023 PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags); 1024 1025 #endif /* _OS2_H */ 1026 1027