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