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