Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Nullpointererror with makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
deadalnix committed Nov 18, 2012
1 parent 34412a3 commit 38f8698
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions posix.mak
Expand Up @@ -71,6 +71,7 @@ MANIFEST= \
src/core/exception.d \
src/core/math.d \
src/core/memory.d \
src/core/nullpointererror.d \
src/core/runtime.d \
src/core/simd.d \
src/core/thread.d \
Expand Down Expand Up @@ -281,6 +282,7 @@ SRC_D_MODULES = \
core/exception \
core/math \
core/memory \
core/nullpointererror \
core/runtime \
core/simd \
core/thread \
Expand Down Expand Up @@ -416,6 +418,7 @@ DOCS=\
$(DOCDIR)/core_exception.html \
$(DOCDIR)/core_math.html \
$(DOCDIR)/core_memory.html \
$(DOCDIR)/core_nullpointererror.html \
$(DOCDIR)/core_runtime.html \
$(DOCDIR)/core_simd.html \
$(DOCDIR)/core_thread.html \
Expand Down
42 changes: 27 additions & 15 deletions src/core/nullpointererror.d
Expand Up @@ -14,6 +14,7 @@ module core.nullpointererror;

version(linux) {

private :
import core.sys.posix.signal;
import core.sys.posix.ucontext;

Expand Down Expand Up @@ -221,8 +222,28 @@ version(X86_64) {
}
}

// This should be calculated by druntime.
enum PAGE_SIZE = 4096;

// The first 64Kb are reserved for detecting null pointer deferences.
enum MEMORY_RESERVED_FOR_NULL_DEFERENCE = 4096 * 16;

// User space handler

void sigsegv_userspace_process(void* address) {
// The first page is protected to detect null deference.
if((cast(size_t) address) < MEMORY_RESERVED_FOR_NULL_DEFERENCE) {
throw new NullPointerError();
}

throw new SignalError(SIGSEGV);
}

public :

/**
* Thrown on posix system when a signal is recieved. Is only throw for SIGSEGV.
*/
class SignalError : Error {
private int _signum;

Expand All @@ -236,12 +257,18 @@ class SignalError : Error {
super("", file, line, next);
}

/**
* Property that returns the signal number.
*/
@property
int signum() const {
return _signum;
}
}

/**
* Throw on null pointer deference.
*/
class NullPointerError : SignalError {
this(string file = __FILE__, size_t line = __LINE__, Throwable next = null) {
super(SIGSEGV, file, line, next);
Expand All @@ -252,20 +279,5 @@ class NullPointerError : SignalError {
}
}

// This should be calculated by druntime.
enum PAGE_SIZE = 4096;

// The first 64Kb are reserved for detecting null pointer deferences.
enum MEMORY_RESERVED_FOR_NULL_DEFERENCE = 4096 * 16;

void sigsegv_userspace_process(void* address) {
// The first page is protected to detect null deference.
if((cast(size_t) address) < MEMORY_RESERVED_FOR_NULL_DEFERENCE) {
throw new NullPointerError();
}

throw new SignalError(SIGSEGV);
}

}

0 comments on commit 38f8698

Please sign in to comment.