Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jq/memcatch'
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jun 12, 2015
2 parents 22ecc91 + a2b6943 commit 84f14d1
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export
# string types
Char, ASCIIString, ByteString, DirectIndexString, AbstractString, UTF8String,
# errors
BoundsError, DivideError, DomainError, Exception,
InexactError, InterruptException, OutOfMemoryError, OverflowError,
BoundsError, DivideError, DomainError, Exception, InexactError,
InterruptException, OutOfMemoryError, ReadOnlyMemoryError, OverflowError,
StackOverflowError, SegmentationFault, UndefRefError, UndefVarError,
# AST representation
Expr, GotoNode, LabelNode, LineNumberNode, QuoteNode, SymbolNode, TopNode,
Expand Down Expand Up @@ -223,6 +223,7 @@ immutable DomainError <: Exception end
immutable OverflowError <: Exception end
immutable InexactError <: Exception end
immutable OutOfMemoryError <: Exception end
immutable ReadOnlyMemoryError<: Exception end
immutable SegmentationFault <: Exception end
immutable StackOverflowError <: Exception end
immutable UndefRefError <: Exception end
Expand Down
1 change: 1 addition & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ call(T::Type{DomainError}) = Core.call(T)
call(T::Type{OverflowError}) = Core.call(T)
call(T::Type{InexactError}) = Core.call(T)
call(T::Type{OutOfMemoryError}) = Core.call(T)
call(T::Type{ReadOnlyMemoryError}) = Core.call(T)
call(T::Type{StackOverflowError}) = Core.call(T)
call(T::Type{SegmentationFault}) = Core.call(T)
call(T::Type{UndefRefError}) = Core.call(T)
Expand Down
2 changes: 2 additions & 0 deletions doc/manual/control-flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ built-in :exc:`Exception`\ s listed below all interrupt the normal flow of contr
+---------------------------+
| :exc:`OutOfMemoryError` |
+---------------------------+
| :exc:`ReadOnlyMemoryError`|
+---------------------------+
| :exc:`MethodError` |
+---------------------------+
| :exc:`OverflowError` |
Expand Down
4 changes: 4 additions & 0 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ Errors

An operation allocated too much memory for either the system or the garbage collector to handle properly.

.. function:: ReadOnlyMemoryError()

An operation tried to write to memory that is read-only.

.. function:: OverflowError()

The result of an expression is too large for the specified type and will cause a wraparound.
Expand Down
1 change: 1 addition & 0 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jl_value_t *jl_undefref_exception;
jl_value_t *jl_interrupt_exception;
jl_datatype_t *jl_boundserror_type;
jl_value_t *jl_memory_exception;
jl_value_t *jl_readonlymemory_exception;

jl_sym_t *call_sym; jl_sym_t *dots_sym;
jl_sym_t *call1_sym; jl_sym_t *module_sym;
Expand Down
10 changes: 8 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void segv_handler(int sig, siginfo_t *info, void *context)
sigemptyset(&sset);
sigaddset(&sset, SIGSEGV);
sigprocmask(SIG_UNBLOCK, &sset, NULL);
jl_throw(jl_memory_exception);
jl_throw(jl_readonlymemory_exception);
}
#ifdef SEGV_EXCEPTION
else if (sig == SIGSEGV) {
Expand Down Expand Up @@ -396,6 +396,11 @@ static LONG WINAPI _exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo,
case EXCEPTION_STACK_OVERFLOW:
jl_throw_in_ctx(jl_stackovf_exception, ExceptionInfo->ContextRecord,in_ctx&&pSetThreadStackGuarantee);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_ACCESS_VIOLATION:
if (ExceptionInfo->ExceptionRecord->ExceptionInformation[0] == 1) { // writing to read-only memory (e.g. mmap)
jl_throw_in_ctx(jl_readonlymemory_exception, ExceptionInfo->ContextRecord,in_ctx);
return EXCEPTION_CONTINUE_EXECUTION;
}
}
jl_safe_printf("\nPlease submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.\nException: ");
switch (ExceptionInfo->ExceptionRecord->ExceptionCode) {
Expand Down Expand Up @@ -775,7 +780,7 @@ void darwin_stack_overflow_handler(unw_context_t *uc)
void darwin_accerr_handler(unw_context_t *uc)
{
bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, uc);
jl_exception_in_transit = jl_memory_exception;
jl_exception_in_transit = jl_readonlymemory_exception;
jl_rethrow();
}

Expand Down Expand Up @@ -1366,6 +1371,7 @@ void jl_get_builtin_hooks(void)
jl_interrupt_exception = jl_new_struct_uninit((jl_datatype_t*)core("InterruptException"));
jl_boundserror_type = (jl_datatype_t*)core("BoundsError");
jl_memory_exception = jl_new_struct_uninit((jl_datatype_t*)core("OutOfMemoryError"));
jl_readonlymemory_exception = jl_new_struct_uninit((jl_datatype_t*)core("ReadOnlyMemoryError"));

#ifdef SEGV_EXCEPTION
jl_segv_exception = jl_new_struct_uninit((jl_datatype_t*)core("SegmentationFault"));
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ extern DLLEXPORT jl_datatype_t *jl_methoderror_type;
extern DLLEXPORT jl_datatype_t *jl_undefvarerror_type;
extern DLLEXPORT jl_value_t *jl_stackovf_exception;
extern DLLEXPORT jl_value_t *jl_memory_exception;
extern DLLEXPORT jl_value_t *jl_readonlymemory_exception;
extern DLLEXPORT jl_value_t *jl_diverror_exception;
extern DLLEXPORT jl_value_t *jl_domain_exception;
extern DLLEXPORT jl_value_t *jl_overflow_exception;
Expand Down
2 changes: 2 additions & 0 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ c[5] = UInt8('x')
Libc.msync(c)
close(s)
s = open(file, "r")
c = mmap_array(UInt8, (11,), s)
@test_throws ReadOnlyMemoryError c[5] = UInt8('x')
str = readline(s)
close(s)
@test startswith(str, "Hellx World")
Expand Down

0 comments on commit 84f14d1

Please sign in to comment.