Tasks create a general protection fault... tear

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
VoidLogic

Tasks create a general protection fault... tear

Post by VoidLogic »

My OS runs on top of DOS using DOS/4G for PMODE. I use open Watcom C/C++.
I use the ANSI standard SetJmp.h for stack saving.

Here is how the task is loaded:
---------------------------------
1. A task class is allowcated.
2. The memory address is of this class, as well as the memory address of a jump buffer is put in a file.
3. The OS starts the exe, the exe uses the class pointer to setup its task class (pointing to the same memory address).
3. the exe sets up the jump buffer in the task class
4. it uses the jump buffer to return control to the OS
5. as soon as the OS starting multitasking <CRASH>

-----------------------------------------------\

now this all works fine and dandy under real mode, but DOS 4/G gives me a general protection fault under PMODE. Is there anyway to disable this general protection checking or.. help :)

Thanks in advance
-VoidLogic
VoidLogic

RE: Can't anyone help me?

Post by VoidLogic »

please
Anton

RE: Can't anyone help me?

Post by Anton »

Why do you use DOS/4G? How do you plan to use it? I don't think it is a good idea, because you don't have sources, and if problems hapen(like in your case), you would't know what to do.
Second, are you shure that DOS/4G is threadable(you say that problems hapen when you do multitasking)?
Anton
VoidLogic

RE: Can't anyone help me?

Post by VoidLogic »

I use SetJmp.h to multitask (its ANSI Std), it works under real mode becuase DOS dosn't care if programs acess memory from one another. The multitasking works fine under DOS and DOS 4/G when the multitasking code comoes from the same exe file. put when memory starts being shared between exes, thats when I get a General exeption fault. I need to turn off checking for this, becuase i', doing it on purpose.

-VoidLogic

P.S. This is for an independent study, it must be 95% C/C++ code
Anton

RE: Can't anyone help me?

Post by Anton »

Are you shure that this General exception fault is generated by the DOS/4G itself, and not by the CPU(in which case you are probably doing something wrong), where this exception is beeing handled by DOS/4G and reported.
Anton.

P.S.
Nobody wants to use a lot of asm in there code, so like 99.99999% of the code is C(or C++).
VoidLogic

RE: Can't anyone help me?

Post by VoidLogic »

the same code works under realmode with no crash.

it happends when i longjmp(*Buf,0);
the Buf is in local memory but the stack saved in it is the stack of another exe. So under real mode it lets me multitask. setjmp.h is part of the ANSI C standard.

VoidLogic
jamethiel

RE: Can't anyone help me?

Post by jamethiel »

A couple possibilities spring to mind. Foremost amongst them are designs for DOS extenders that would prevent this from working at all, no matter what.

If memory serves, DPMI programs usually allocate selectors from the LDT. If multiple DPMI clients are started, they may be given different LDTs, in which case you either put your task switcher in a GDT segment and save/restore the LDT along with the rest of the machine state, or you kick down to real mode to do the task switch.

One option might be to implement your own DPMI server which either implements a setjmp()/longjmp() type taskswitch interface, an easier taskswitch interface, or takes certain liberties with the DPMI spec in order to make your existing code work.

Another possibility, which requires that you be on one of the windows DPMI servers, is to use the backdoor to get direct LDT access and add a segment with the exact same selector in all tasks and put the task switcher in that segment and have it switch LDTs for you.

Another possibility is that if you're compiling 32-bit code under DOS4GW, setjmp() may not be saving the segment registers (since flat-model code doesn't need to change them), which could also be the problem.

I don't think it'll be easy, and it may not be doable in 95% C/C++, and you may need to use something other than setjmp()/longjmp() for your taskswitching, but there are some plausible solutions to this problem.

--Jamethiel
Post Reply