source: trunk/src/kernel32/dbglog.cpp@ 9938

Last change on this file since 9938 was 9938, checked in by sandervl, 22 years ago

WaitForSingleObject/(Msg)WaitForMultipleObject fixes to prevent thread priorities from being accidentally boosted to time critical

File size: 26.3 KB
Line 
1/* $Id: dbglog.cpp,v 1.9 2003-03-26 16:02:33 sandervl Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 * Debug Logging procedures
6 *
7 * Copyright 1998-2002 Sander van Leeuwen (sandervl@xs4all.nl)
8 * Copyright 1998 Joel Troster
9 * Copyright 1998 Peter FitzSimmons
10 *
11 */
12
13
14/*******************************************************************************
15* Internal Functions *
16*******************************************************************************/
17
18#define INCL_BASE
19#define INCL_WIN
20#define INCL_WINERRORS
21#define INCL_DOSFILEMGR
22#include <os2wrap.h> //Odin32 OS/2 api wrappers
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <stdarg.h>
27#include <win32type.h>
28#include <win32api.h>
29#include <dbglog.h>
30#include "initterm.h"
31#include "logging.h"
32#include "exceptutil.h"
33#include <wprocess.h>
34#include <versionos2.h>
35#include "odinbuild.h"
36#include <cpuhlp.h>
37
38/*****************************************************************************
39 * PMPRINTF Version *
40 *****************************************************************************/
41
42#ifdef PMPRINTF
43
44/* ----- Customization variables ----- */
45#define PRINTFID ""
46#define PRINTFMAXLEN 300
47#define PRINTFLINELEN 100
48#define PRINTFTHREADS 54
49#define PRINTFQNAME "\\QUEUES\\PRINTF32"
50
51/* ----- Includes and externals ----- */
52#include <stddef.h> /* .. */
53#include <time.h> /* .. */
54
55extern ULONG flAllocMem; /*Tue 03.03.1998: knut */
56
57/* ----- Local defines ----- */
58#define PRINTFIDSIZE sizeof(PRINTFID)
59#define PRINTFMAXBUF PRINTFIDSIZE+PRINTFLINELEN
60
61
62/*****************************************************************************
63 * Structures *
64 *****************************************************************************/
65
66/* ----- Per-thread output buffer and current indices into line ---- */
67struct perthread {
68 LONG lineindex; /* where next char */
69 LONG tidemark; /* rightmost char */
70 int bell; /* TRUE if line has bell */
71 UCHAR line[PRINTFMAXBUF]; /* accumulator */
72 };
73
74/* ----- Local static variables ----- */
75static ULONG ourpid=0; /* our process ID */
76static ULONG servepid=0; /* process IDs of the server */
77static HQUEUE qhandle=0; /* handle for the queue */
78static struct perthread *tps[PRINTFTHREADS+1]; /* -> per-thread data */
79
80/* ----- Local subroutine ----- */
81static int printf_(struct perthread *);
82
83
84/* ----------------------------------------------------------------- */
85/* The "printf" function. Note this has a variable number of */
86/* arguments. */
87/* ----------------------------------------------------------------- */
88int SYSTEM WriteLog(char *f, ...)
89 {
90 TIB *ptib; /* process/thread id structures */
91 PIB *ppib; /* .. */
92 TID ourtid; /* thread ID */
93 struct perthread *tp; /* pointer to per-thread data */
94 int rc; /* returncode */
95 ULONG urc; /* returncode */
96
97 urc=DosOpenQueue(&servepid, &qhandle, PRINTFQNAME); /* Open the Q */
98 /* Non-0 RC means Q does not exist or cannot be opened */
99 if (urc==343) return 0; /* queue does not exist, so quit */
100 if (urc!=0) return -1; /* report any other error */
101
102 /* First determine our thread ID (and hence get access to the */
103 /* correct per-thread data. If the per-thread data has not been */
104 /* allocated, then allocate it now. It is never freed, once */
105 /* allocated, as PRINTF is not notified of end-of-thread. */
106 DosGetInfoBlocks(&ptib,&ppib); /* get process/thread info */
107 ourtid=ptib->tib_ptib2->tib2_ultid; /* .. and copy TID */
108 if (ourtid>PRINTFTHREADS) /* too many threads .. */
109 return 0; /* .. so quit, quietly */
110 tp=tps[ourtid]; /* copy to local pointer */
111 if (tp==NULL) { /* uninitialized (NULL=0) */
112 /* allocate a per-thread structure */
113 tp=(struct perthread *)malloc(sizeof(struct perthread));
114 if (tp==NULL) return -1; /* out of memory -- return error */
115 tps[ourtid]=tp; /* save for future calls */
116 strcpy(tp->line,PRINTFID); /* initialize: line.. */
117 tp->lineindex=PRINTFIDSIZE-1; /* ..where next char */
118 tp->tidemark =PRINTFIDSIZE-2; /* ..rightmost char */
119 tp->bell=FALSE; /* ..if line has bell */
120 if (ourpid==0) ourpid=ppib->pib_ulpid; /* save PID for all to use */
121 }
122
123 { /* Block for declarations -- only needed if queue exists, etc. */
124 LONG count; /* count of characters formatted */
125 UCHAR buffer[PRINTFMAXLEN+1]; /* formatting area */
126 LONG i, newind; /* work */
127 UCHAR ch; /* .. */
128 va_list argptr; /* -> variable argument list */
129
130 va_start(argptr, f); /* get pointer to argument list */
131 count=vsprintf(buffer, f, argptr);
132 va_end(argptr); /* done with variable arguments */
133
134 if (count<0) return count-1000;/* bad start */
135
136 if (count>PRINTFMAXLEN) {
137 /* Disaster -- we are probably "dead", but just in case we */
138 /* are not, carry on with truncated data. */
139 count=PRINTFMAXLEN;
140 }
141 buffer[count]='\0'; /* ensure terminated */
142 /* OK, ready to go with the data now in BUFFER */
143 /* We copy from the formatted string to the output (line) buffer, */
144 /* taking note of certain control characters and sending a line */
145 /* the queue whenever we see a LF control, or when the line */
146 /* fills (causing a forced break). */
147 for (i=0; ; i++) {
148 ch=buffer[i]; if (!ch) break;
149 switch(ch) {
150 case '\r': /* carriage return */
151 tp->lineindex=PRINTFIDSIZE-1; /* back to start of line */
152 break;
153 case '\n': /* new line */
154 case '\f': /* form feed */
155 rc=printf_(tp); /* print a line */
156 if (rc!=0) return rc; /* error */
157 break;
158 case '\t': /* tab */
159 newind=tp->lineindex-PRINTFIDSIZE+1; /* offset into data */
160 newind=tp->lineindex+5-newind%5; /* new index requested */
161 if (newind>=PRINTFMAXBUF) newind=PRINTFMAXBUF; /* clamp */
162 for (; tp->lineindex<newind; tp->lineindex++) {
163 if (tp->lineindex>tp->tidemark) { /* beyond current end */
164 tp->line[tp->lineindex]=' '; /* add space */
165 tp->tidemark=tp->lineindex;
166 }
167 }
168 break;
169 case '\v': /* vertical tab */
170 /* ignore it */
171 break;
172 case '\b': /* backspace */
173 tp->lineindex=max(tp->lineindex-1,PRINTFIDSIZE);
174 break;
175 case '\a': /* alert (bell) */
176 tp->bell=TRUE;
177 break;
178 default: /* ordinary character */
179 tp->line[tp->lineindex]=ch;
180 if (tp->lineindex>tp->tidemark) /* is rightmost.. */
181 tp->tidemark=tp->lineindex;
182 tp->lineindex++; /* step for next */
183 } /* switch */
184 if (tp->lineindex>=PRINTFMAXBUF) {
185 rc=printf_(tp); /* print a line */
186 if (rc!=0) return rc; /* error */
187 }
188
189 } /* copy loop */
190 return count; /* all formatted data processed */
191 } /* block */
192 } /* printf */
193
194/* ----- printf_(tp) -- Local subroutine to send a line ------------ */
195/* A line has been completed (or overflowed): write it to the queue. */
196int printf_(struct perthread *tp) /* pointer to per-thread data */
197 {
198 ULONG urc; /* unsigned returncode */
199 PSZ pszTo, pszFrom; /* character pointers */
200 PVOID addr; /* address of output data */
201 long size; /* total size of output data */
202 time_t timenow; /* holds current time */
203
204 tp->line[tp->tidemark+1]='\0'; /* add terminator */
205 size=tp->tidemark+2; /* total length of data */
206
207 /* Get some shared memory that can be given away */
208 urc=DosAllocSharedMem(&addr, NULL, (unsigned)size,
209 OBJ_GIVEABLE|PAG_WRITE|PAG_COMMIT|flAllocMem);
210 /*knut: added flAllocMem */
211
212 if (urc!=0) return -2; /* error */
213
214 pszTo=addr; /* copy for clarity */
215 pszFrom=&(tp->line[0]); /* pointer to source */
216 strcpy(pszTo,pszFrom); /* copy the string to shared memory */
217
218 if (ourpid!=servepid) { /* (no giveaway needed if to self) */
219 urc=DosGiveSharedMem(addr, servepid, PAG_READ); /* give access */
220 if (urc!=0) return -3;} /* error */
221
222 /* Write the selector, size, and timestamp to the queue */
223 if (tp->bell) size=-size; /* BELL passed by negation */
224 time(&timenow); /* optional - else use 0 */
225 urc=DosWriteQueue(qhandle, /* handle */
226 (unsigned)timenow, /* 'request' (timestamp) */
227 (unsigned)size, /* 'length' (length/bell) */
228 addr, /* 'address' (address) */
229 0); /* priority (FIFO if enabled) */
230 if (urc!=0) return -4; /* error */
231 if (ourpid!=servepid) { /* if given away.. */
232 urc=DosFreeMem(addr); /* .. *we* are done with it */
233 if (urc!=0) return -5;} /* error */
234 /* Reset the line buffer and indices */
235 tp->lineindex=PRINTFIDSIZE-1; /* where next char */
236 tp->tidemark =PRINTFIDSIZE-2; /* rightmost char */
237 tp->bell =FALSE; /* true if line has bell */
238 return 0; /* success! */
239 } /* printf_ */
240#endif
241
242
243
244/*****************************************************************************
245 * Standard Version *
246 *****************************************************************************/
247
248static FILE *flog = NULL; /*PLF Mon 97-09-08 20:00:15*/
249static BOOL init = FALSE;
250static BOOL fLogging = TRUE;
251static int dwEnableLogging = 1;
252static int oldcrtmsghandle = 0;
253
254static BOOL fDisableThread[5] = {0};
255static BOOL fFlushLines = FALSE;
256
257static char *pszLastLogEntry = NULL;
258
259//#define CHECK_ODINHEAP
260#if defined(DEBUG) && defined(CHECK_ODINHEAP)
261int checkOdinHeap = 1;
262int checkingheap = 0;
263#define ODIN_HEAPCHECK() \
264 if(checkingheap) checkOdinHeap = 0; \
265 checkingheap++; \
266 if(checkOdinHeap) _heap_check(); \
267 checkingheap--;
268#else
269#define ODIN_HEAPCHECK()
270#endif
271
272//#define LOG_TIME
273//#define SHOW_FPU_CONTROLREG
274#define WIN32_IP_LOGGING
275#define WIN32_IP_LOG_PORT 5001
276
277#ifdef WIN32_IP_LOGGING
278#include <types.h>
279#include <netinet/in.h>
280#include <sys/socket.h>
281
282static int logSocket = -1;
283static struct sockaddr_in servername;
284#endif
285
286int SYSTEM WriteLog(char *tekst, ...)
287{
288 USHORT sel = RestoreOS2FS();
289 va_list argptr;
290 TEB *teb = GetThreadTEB();
291
292 pszLastLogEntry = tekst;
293
294 ODIN_HEAPCHECK();
295
296 if(!init)
297 {
298 init = TRUE;
299
300 if(getenv("WIN32LOG_FLUSHLINES")) {
301 fFlushLines = TRUE;
302 }
303#ifdef DEFAULT_LOGGING_OFF
304 if(getenv("WIN32LOG_ENABLED")) {
305#else
306 if(!getenv("NOWIN32LOG")) {
307#endif
308
309#ifdef WIN32_IP_LOGGING
310 char *logserver = getenv("WIN32LOG_IPSERVER");
311 if(logserver && loadNr == 0) {
312 sock_init();
313
314 memset(&servername, 0, sizeof(servername));
315 servername.sin_family = AF_INET;
316 servername.sin_addr.s_addr = inet_addr(logserver);
317 servername.sin_port = WIN32_IP_LOG_PORT;
318
319 logSocket = socket(PF_INET, SOCK_DGRAM, 0);
320 }
321#endif
322 char szLogFile[CCHMAXPATH];
323 const char *pszLogBase = getenv("WIN32LOG_FILEBASE");
324 if (!pszLogBase)
325 pszLogBase = "odin32_";
326
327 sprintf(szLogFile, "%s%d.log", pszLogBase, loadNr);
328 flog = fopen(szLogFile, "w");
329 if(flog == NULL)
330 {//probably running exe on readonly device
331 sprintf(szLogFile, "%sodin32_%d.log", kernel32Path, loadNr);
332 flog = fopen(szLogFile, "w");
333 }
334 oldcrtmsghandle = _set_crt_msg_handle(fileno(flog));
335 }
336 else
337 fLogging = FALSE;
338
339 fDisableThread[0] = getenv("DISABLE_THREAD1") != NULL;
340 fDisableThread[1] = getenv("DISABLE_THREAD2") != NULL;
341 fDisableThread[2] = getenv("DISABLE_THREAD3") != NULL;
342 fDisableThread[3] = getenv("DISABLE_THREAD4") != NULL;
343 fDisableThread[4] = getenv("DISABLE_THREAD5") != NULL;
344 }
345
346 if(teb) {
347 if(teb->o.odin.threadId < 5 && fDisableThread[teb->o.odin.threadId-1] == 1) {
348 SetFS(sel);
349 return 1;
350 }
351 }
352
353 if(!tekst) {
354 if(flog) fflush( flog);
355 SetFS(sel);
356 return 1;
357 }
358
359 if(fLogging && flog && (dwEnableLogging > 0))
360 {
361 va_start(argptr, tekst);
362
363#ifdef WIN32_IP_LOGGING
364 if(logSocket == -1) {
365#endif
366 if(teb)
367 {
368 ULONG ulCallDepth;
369#ifdef DEBUG
370 ulCallDepth = teb->o.odin.dbgCallDepth;
371#else
372 ulCallDepth = 0;
373#endif
374
375 teb->o.odin.logfile = (DWORD)flog;
376
377#ifdef LOG_TIME
378 if(sel == 0x150b && fSwitchTIBSel)
379 fprintf(flog,
380 "t%02d (%3d): (%x) (FS=150B) ",
381 LOWORD(teb->o.odin.threadId),
382 ulCallDepth,
383 GetTickCount());
384 else
385 fprintf(flog,
386 "t%02d (%3d): (%x) ",
387 LOWORD(teb->o.odin.threadId),
388 ulCallDepth,
389 GetTickCount());
390#else
391 if(sel == 0x150b && fSwitchTIBSel)
392 fprintf(flog,
393#ifdef SHOW_FPU_CONTROLREG
394 "t%02d (%3d)(%3x): ",
395 LOWORD(teb->o.odin.threadId),
396 ulCallDepth,
397 CONTROL87(0,0));
398#else
399 "t%02d (%3d): (FS=150B) ",
400 LOWORD(teb->o.odin.threadId),
401 ulCallDepth);
402#endif
403 else
404 fprintf(flog,
405#ifdef SHOW_FPU_CONTROLREG
406 "t%02d (%3d)(%3x): ",
407 LOWORD(teb->o.odin.threadId),
408 ulCallDepth,
409 CONTROL87(0,0));
410#else
411 "t%02d (%3d): ",
412 LOWORD(teb->o.odin.threadId),
413 ulCallDepth);
414#endif
415#endif
416 }
417#ifdef LOG_TIME
418 else {
419 fprintf(flog, "tX: (%x) ", GetTickCount());
420 }
421#endif
422#ifdef WIN32_IP_LOGGING
423 }
424#endif
425
426#ifdef WIN32_IP_LOGGING
427 if(logSocket != -1) {
428 char logbuffer[1024];
429 int prefixlen = 0;
430
431 if(teb)
432 {
433 ULONG ulCallDepth;
434#ifdef DEBUG
435 ulCallDepth = teb->o.odin.dbgCallDepth;
436#else
437 ulCallDepth = 0;
438#endif
439#ifdef LOG_TIME
440 if(sel == 0x150b && fSwitchTIBSel)
441 sprintf(logbuffer, "t%02d (%3d): %x (FS=150B) ",
442 LOWORD(teb->o.odin.threadId), ulCallDepth, GetTickCount());
443 else
444 sprintf(logbuffer, "t%02d (%3d): %x ",
445 LOWORD(teb->o.odin.threadId), ulCallDepth, GetTickCount());
446#else
447 if(sel == 0x150b && fSwitchTIBSel)
448 sprintf(logbuffer, "t%02d (%3d): (FS=150B) ",
449 LOWORD(teb->o.odin.threadId), ulCallDepth);
450 else
451 sprintf(logbuffer, "t%02d (%3d): ",
452 LOWORD(teb->o.odin.threadId), ulCallDepth);
453#endif
454 prefixlen = strlen(logbuffer);
455 }
456
457 vsprintf(&logbuffer[prefixlen], tekst, argptr);
458
459 int rc;
460
461 servername.sin_family = AF_INET;
462 servername.sin_port = WIN32_IP_LOG_PORT;
463
464 rc = sendto(logSocket, logbuffer, strlen(logbuffer)+1, 0, (struct sockaddr *)&servername, sizeof(servername));
465 if(rc == -1) {
466 rc = sock_errno();
467 }
468 if(teb) teb->o.odin.logfile = 0;
469 va_end(argptr);
470 }
471 else {
472 vfprintf(flog, tekst, argptr);
473 if(teb) teb->o.odin.logfile = 0;
474 va_end(argptr);
475
476 if(tekst[strlen(tekst)-1] != '\n')
477 fprintf(flog, "\n");
478
479 if(fFlushLines)
480 fflush(flog);
481 }
482#else
483 vfprintf(flog, tekst, argptr);
484 if(teb) teb->o.odin.logfile = 0;
485 va_end(argptr);
486
487 if(tekst[strlen(tekst)-1] != '\n')
488 fprintf(flog, "\n");
489
490 if(fFlushLines)
491 fflush(flog);
492#endif
493 }
494 SetFS(sel);
495 return 1;
496}
497//******************************************************************************
498//******************************************************************************
499int SYSTEM WriteLogNoEOL(char *tekst, ...)
500{
501 USHORT sel = RestoreOS2FS();
502 va_list argptr;
503
504 ODIN_HEAPCHECK();
505
506 if(!init)
507 {
508 init = TRUE;
509
510#ifdef DEFAULT_LOGGING_OFF
511 if(getenv("WIN32LOG_ENABLED")) {
512#else
513 if(!getenv("NOWIN32LOG")) {
514#endif
515 char logname[CCHMAXPATH];
516
517 sprintf(logname, "odin32_%d.log", loadNr);
518 flog = fopen(logname, "w");
519 if(flog == NULL) {//probably running exe on readonly device
520 sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr);
521 flog = fopen(logname, "w");
522 }
523 }
524 else
525 fLogging = FALSE;
526 }
527
528 if(fLogging && flog && (dwEnableLogging > 0))
529 {
530 TEB *teb = GetThreadTEB();
531
532 va_start(argptr, tekst);
533 if(teb) {
534 teb->o.odin.logfile = (DWORD)flog;
535 }
536 vfprintf(flog, tekst, argptr);
537 if(teb) teb->o.odin.logfile = 0;
538 va_end(argptr);
539 }
540 SetFS(sel);
541 return 1;
542}
543//******************************************************************************
544//******************************************************************************
545void SYSTEM DecreaseLogCount()
546{
547 dwEnableLogging--;
548}
549//******************************************************************************
550//******************************************************************************
551void SYSTEM IncreaseLogCount()
552{
553 dwEnableLogging++;
554}
555//******************************************************************************
556//******************************************************************************
557int SYSTEM WritePrivateLog(void *logfile, char *tekst, ...)
558{
559 USHORT sel = RestoreOS2FS();
560 va_list argptr;
561
562 if(fLogging && logfile)
563 {
564 TEB *teb = GetThreadTEB();
565
566 va_start(argptr, tekst);
567 if(teb) {
568 teb->o.odin.logfile = (DWORD)flog;
569 }
570 vfprintf((FILE *)logfile, tekst, argptr);
571 if(teb) teb->o.odin.logfile = 0;
572 va_end(argptr);
573
574 if(tekst[strlen(tekst)-1] != '\n')
575 fprintf((FILE *)logfile, "\n");
576 }
577
578 SetFS(sel);
579 return 1;
580}
581//******************************************************************************
582//WriteLog has to take special care to handle dprintfs inside our os/2 exception
583//handler; if an exception occurs inside a dprintf, using dprintf in the exception
584//handler will hang the process
585//******************************************************************************
586int LogException(int state, int prevlock)
587{
588 TEB *teb = GetThreadTEB();
589 int ret = 0;
590
591 if (!teb) return 0;
592
593#if !defined(__EMX__)
594 if (teb->o.odin.logfile)
595 {
596#if (__IBMCPP__ == 300) || (__IBMC__ == 300)
597 PUSHORT lock = (USHORT *)(teb->o.odin.logfile+0x1C);
598#else
599#if __IBMC__ >= 360 || __IBMCPP__ >= 360
600//TODO: test this!!!!!!!
601 PUSHORT lock = (USHORT *)(teb->o.odin.logfile+0x1C);
602#else
603#error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!!
604#endif
605#endif
606 ret = (*lock);
607 if (state == ENTER_EXCEPTION)
608 {
609 if((*lock) > 0) (*lock)--;
610 }
611 else
612 { //LEAVE_EXCEPTION
613 if(prevlock) (*lock)++;
614 }
615 }
616#else
617//kso 2001-01-29: EMX/GCC
618// we maybe should do something with the _more->rsem (_rmutex) structure but
619// I wanna have this compile, so we'll address problems later.
620#endif
621 return ret;
622}
623//******************************************************************************
624//Check if the exception occurred inside a fprintf (logging THDB member set)
625//If true, decrease the lock count for that file stream
626//NOTE: HACK: DEPENDS ON COMPILER VERSION!!!!
627//******************************************************************************
628void CheckLogException()
629{
630 TEB *teb = GetThreadTEB();
631 PUSHORT lock;
632
633 if(!teb) return;
634
635#if !defined(__EMX__)
636 if(teb->o.odin.logfile) {
637 //oops, exception in vfprintf; let's clear the lock count
638#if (__IBMCPP__ == 300) || (__IBMC__ == 300)
639 lock = (PUSHORT)(teb->o.odin.logfile+0x1C);
640#else
641#if __IBMC__ >= 360 || __IBMCPP__ >= 360
642//TODO: test this!!!!!!!
643 PUSHORT lock = (USHORT *)(teb->o.odin.logfile+0x1C);
644#else
645#error Check the offset of the lock count word in the file stream structure for this compiler revision!!!!!
646#endif
647#endif
648 (*lock)--;
649 }
650#else
651//kso 2001-01-29: EMX/GCC
652// we maybe should do something with the _more->rsem (_rmutex) structure but
653// I wanna have this compile, so we'll address problems later.
654#endif
655}
656//******************************************************************************
657//NOTE: No need to save/restore FS, as our FS selectors have already been
658// destroyed and FS == 0x150B.
659//******************************************************************************
660void CloseLogFile()
661{
662 if(oldcrtmsghandle)
663 _set_crt_msg_handle(oldcrtmsghandle);
664
665#ifdef WIN32_IP_LOGGING
666 if(logSocket != -1) {
667 soclose(logSocket);
668 }
669#endif
670
671 if(flog) fclose(flog);
672 flog = 0;
673}
674//******************************************************************************
675//Used to open any private logfiles used in kernel32 (for now only in winimagepeldr.cpp)
676//******************************************************************************
677void OpenPrivateLogFiles()
678{
679#ifdef DEFAULT_LOGGING_OFF
680 if(getenv("WIN32LOG_ENABLED")) {
681#else
682 if(!getenv("NOWIN32LOG")) {
683#endif
684 OpenPrivateLogFilePE();
685 }
686}
687//******************************************************************************
688//Used to close all private logfiles used in kernel32 (for now only in winimagepeldr.cpp)
689//******************************************************************************
690void ClosePrivateLogFiles()
691{
692#ifdef DEFAULT_LOGGING_OFF
693 if(getenv("WIN32LOG_ENABLED")) {
694#else
695 if(!getenv("NOWIN32LOG")) {
696#endif
697 ClosePrivateLogFilePE();
698 }
699}
700//******************************************************************************
701//******************************************************************************
702void SYSTEM CheckVersion(ULONG version, char *modname)
703{
704 dprintf(("CheckVersion of %s, %d\n", modname, version));
705 if(version != PE2LX_VERSION){
706 static char msg[300];
707 int r;
708 dprintf(("Version mismatch! %d, %d: %s\n", version, PE2LX_VERSION, modname));
709 sprintf(msg, "%s is intended for use with a different release of Odin.\n", modname);
710 do{
711 r = WinMessageBox(HWND_DESKTOP, NULLHANDLE, msg, "Version Mismatch!", 0, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_MOVEABLE);
712 }while(r == MBID_RETRY); // giggle
713 if( r != MBID_IGNORE )
714 exit(987);
715 }
716}
717//******************************************************************************
718//******************************************************************************
719void SYSTEM CheckVersionFromHMOD(ULONG version, HMODULE hModule)
720{
721 char name[_MAX_PATH];
722
723 // query name of dll.
724 if(!DosQueryModuleName(hModule, sizeof(name), name))
725 CheckVersion(version, name);
726}
727//******************************************************************************
728//******************************************************************************
729#ifdef __WATCOMC__ /*PLF Sat 97-06-21 17:12:36*/
730 extern void interrupt3( void );
731 #pragma aux interrupt3= \
732 "int 3"
733#endif
734void WIN32API DebugBreak()
735{
736 dprintf(("DebugBreak\n"));
737
738 LPSTR lpstrEnv = getenv("WIN32.DEBUGBREAK"); /* query environment */
739 if (lpstrEnv == NULL) /* if environment is not set, don't call debugger ! */
740 return;
741
742#ifdef __WATCOMC__
743 interrupt3();
744#else
745 _interrupt(3);
746#endif
747}
748//******************************************************************************
749//******************************************************************************
750
751
752/*****************************************************************************
753 * Name : DebugErrorBox
754 * Purpose : display an apprioriate error box with detailed information
755 * about the error cause
756 * Parameters: APIRET iErrorCode - OS/2 error code
757 * PSZ pszFormat - printf-format string
758 * ...
759 * Variables :
760 * Result : return code of the message box
761 * Remark :
762 * Status :
763 *
764 * Author : Patrick Haller [Tue, 1999/09/13 19:55]
765 *****************************************************************************/
766
767int SYSTEM DebugErrorBox(ULONG iErrorCode,
768 char* pszFormat,
769 ...)
770{
771 char szMessageBuffer[1024]; /* buffer for the text message */
772 char szErrorBuffer[1024]; /* buffer for the operating system text */
773 ULONG bc; /* dummy */
774 APIRET rc2; /* API returncode */
775 int iRC; /* message box return code */
776
777 USHORT sel = RestoreOS2FS();
778 va_list argptr;
779
780 // clear memory
781 memset (szMessageBuffer, 0, sizeof(szMessageBuffer));
782 memset (szErrorBuffer, 0, sizeof(szErrorBuffer));
783
784 // build message string
785 va_start(argptr, pszFormat);
786 vsprintf(szMessageBuffer, pszFormat, argptr);
787 va_end(argptr);
788
789 // query error string
790 rc2 = DosGetMessage(NULL,
791 0,
792 szErrorBuffer,
793 sizeof(szErrorBuffer),
794 iErrorCode,
795 "OSO001.MSG",
796 &bc);
797
798 // display message box
799 iRC = WinMessageBox(HWND_DESKTOP,
800 NULLHANDLE,
801 szMessageBuffer,
802 szErrorBuffer,
803 0,
804 MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
805 SetFS(sel);
806 return iRC;
807}
808
809
810/**
811 * Query Odin32 build number.
812 * @returns Build number.
813 * @status Completely implemented.
814 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
815 */
816int WIN32API Odin32GetBuildNumber(void)
817{
818 dprintf(("Odin32GetBuildNumber returned %d\n", ODIN32_BUILD_NR));
819 return ODIN32_BUILD_NR;
820}
821
Note: See TracBrowser for help on using the repository browser.