NotNull pointers
Steven Schveighoffer
schveiguy at yahoo.com
Wed Aug 31 14:40:53 PDT 2011
On Wed, 31 Aug 2011 17:20:04 -0400, Robert Clipsham
<robert at octarineparrot.com> wrote:
> On 31/08/2011 22:01, Steven Schveighoffer wrote:
>> You can catch sigsegv on linux. It takes one call to signal to register
>> a handler.
>
> Are you sure? I could have sworn it didn't work? If it does work, what
> is the purpose of this library:
>
> http://libsigsegv.sourceforge.net/
I think that may be a way to override the OS's page fault handling.
Here's how a page fault (which is *NOT* a segmentation fault necessarily)
works (this might be really badly described, it's been a while since I had
to know this):
The cpu requests a certain memory address.
If the memory isn't in the CPU's cache, it requests the page from the MMU
(memory management unit).
If the page isn't in memory, it triggers an interrupt to the OS for a page
fault.
If the OS sees the page is cached on disk in the swap file, it loads the
page from disk, and then gets it from the MMU.
If the page is not on disk, then the process is sent the SIGSEGV signal.
Maybe the library hooks the signal to do it's own retrieval of memory from
some other cache. No clue.
But this program works swimmingly:
import core.stdc.signal;
import std.stdio;
extern(C) void sigsegvhandler(int sig)
{
writeln("in signal handler!");
assert(0);
}
void main()
{
signal(SIGSEGV, &sigsegvhandler);
int * i;
*i = 5;
}
output:
in signal handler!
core.exception.AssertError at testsignal(7): Assertion failure
----------------
./testsignal(onAssertError+0x2e) [0x8086b9e]
./testsignal(_d_assertm+0x16) [0x80844b6]
./testsignal() [0x8081e96]
./testsignal(sigsegvhandler+0x1e) [0x8081de2]
[0x8bf400]
./testsignal(_D2rt6dmain24mainUiPPaZi7runMainMFZv+0x1a) [0x808495e]
./testsignal(_D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv+0x20) [0x80845f8]
./testsignal(_D2rt6dmain24mainUiPPaZi6runAllMFZv+0x32) [0x80849a2]
./testsignal(_D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv+0x20) [0x80845f8]
./testsignal(main+0x94) [0x80845a4]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0xa79e37]
./testsignal() [0x8081d11]
----------------
-Steve
More information about the Digitalmars-d
mailing list