From: "Charles Sandmann" Newsgroups: comp.os.msdos.djgpp Subject: Re: Getting cr2 in exception handler Date: Mon, 8 Mar 1999 15:20:45 Organization: Aspen Technology, Inc. Lines: 26 Message-ID: <36e3eacd.sandmann@clio.rice.edu> References: <36E1D56E DOT ABB127DE AT cartsys DOT com> NNTP-Posting-Host: dmcap2.aco.aspentech.com X-NewsEditor: ED-1.5.8 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > I have an application where I need to set up an exception handler for > page faults and have access to the value of cr2 (linear address to which > access faulted). But: > * mov cr2 is a privileged instruction. > * There is a DPMI 1.0 exception handling function that passes it, but it > will be tricky to make it interoperate with DJGPP's exception handlers, > and anyway CWSDPMI doesn't support it. Yes, this is all correct. > I could, I suppose, use CWSDPR0 and read cr2 directly, but that's > difficult, since virtual memory will probably be required. (It's a > malloc debugger whose memory usage is extremely inefficient, and I want > it to run on small boxes if possible.) > So: Does anyone know of another way to find the value of cr2? I don't > care about it working in anything but CWSDPMI. There are some tricks that can probably be done to get the value: 1) Pull it out of the memory data structure using some tricks to find it. 2) Set up a ring-0 call gate and point it to some routine in your code. This is a hole in the CWSDPMI ring-3 security on purpose to allow such things. You will need to have an Intel reference manual and probably the CWSDPMI source to know what needs to be done, however.