diff options
Diffstat (limited to 'asmrun')
-rw-r--r-- | asmrun/.depend | 21 | ||||
-rw-r--r-- | asmrun/Makefile | 9 | ||||
-rw-r--r-- | asmrun/Makefile.nt | 11 | ||||
-rw-r--r-- | asmrun/amd64.S | 182 | ||||
-rw-r--r-- | asmrun/amd64nt.asm | 62 | ||||
-rw-r--r-- | asmrun/arm.S | 111 | ||||
-rw-r--r-- | asmrun/backtrace.c | 50 | ||||
-rw-r--r-- | asmrun/fail.c | 2 | ||||
-rw-r--r-- | asmrun/i386.S | 18 | ||||
-rw-r--r-- | asmrun/i386nt.asm | 170 | ||||
-rw-r--r-- | asmrun/natdynlink.c | 1 | ||||
-rw-r--r-- | asmrun/natdynlink.h | 0 | ||||
-rw-r--r-- | asmrun/power-elf.S | 4 | ||||
-rw-r--r-- | asmrun/power-rhapsody.S | 10 | ||||
-rw-r--r-- | asmrun/roots.c | 4 | ||||
-rw-r--r-- | asmrun/signals_asm.c | 37 | ||||
-rw-r--r-- | asmrun/signals_osdep.h | 34 | ||||
-rw-r--r-- | asmrun/sparc.S | 8 | ||||
-rw-r--r-- | asmrun/stack.h | 5 | ||||
-rw-r--r-- | asmrun/startup.c | 18 |
20 files changed, 464 insertions, 293 deletions
diff --git a/asmrun/.depend b/asmrun/.depend index 92536795da..7ed867f54e 100644 --- a/asmrun/.depend +++ b/asmrun/.depend @@ -175,7 +175,7 @@ natdynlink.o: natdynlink.c ../byterun/misc.h ../byterun/config.h \ ../byterun/misc.h ../byterun/memory.h ../byterun/gc.h \ ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ ../byterun/minor_gc.h stack.h ../byterun/callback.h ../byterun/alloc.h \ - ../byterun/intext.h ../byterun/io.h natdynlink.h ../byterun/osdeps.h \ + ../byterun/intext.h ../byterun/io.h ../byterun/osdeps.h \ ../byterun/fail.h obj.o: obj.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ @@ -223,10 +223,11 @@ startup.o: startup.c ../byterun/callback.h ../byterun/mlvalues.h \ ../byterun/memory.h ../byterun/gc.h ../byterun/major_gc.h \ ../byterun/freelist.h ../byterun/minor_gc.h ../byterun/misc.h \ ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/printexc.h stack.h \ - ../byterun/sys.h natdynlink.h + ../byterun/sys.h str.o: str.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ - ../byterun/fail.h ../byterun/mlvalues.h ../byterun/misc.h + ../byterun/fail.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/int64_native.h sys.o: sys.c ../byterun/config.h ../byterun/../config/m.h \ ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ ../byterun/config.h ../byterun/mlvalues.h ../byterun/debugger.h \ @@ -425,7 +426,7 @@ natdynlink.d.o: natdynlink.c ../byterun/misc.h ../byterun/config.h \ ../byterun/misc.h ../byterun/memory.h ../byterun/gc.h \ ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ ../byterun/minor_gc.h stack.h ../byterun/callback.h ../byterun/alloc.h \ - ../byterun/intext.h ../byterun/io.h natdynlink.h ../byterun/osdeps.h \ + ../byterun/intext.h ../byterun/io.h ../byterun/osdeps.h \ ../byterun/fail.h obj.d.o: obj.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ @@ -473,10 +474,11 @@ startup.d.o: startup.c ../byterun/callback.h ../byterun/mlvalues.h \ ../byterun/memory.h ../byterun/gc.h ../byterun/major_gc.h \ ../byterun/freelist.h ../byterun/minor_gc.h ../byterun/misc.h \ ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/printexc.h stack.h \ - ../byterun/sys.h natdynlink.h + ../byterun/sys.h str.d.o: str.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ - ../byterun/fail.h ../byterun/mlvalues.h ../byterun/misc.h + ../byterun/fail.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/int64_native.h sys.d.o: sys.c ../byterun/config.h ../byterun/../config/m.h \ ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ ../byterun/config.h ../byterun/mlvalues.h ../byterun/debugger.h \ @@ -675,7 +677,7 @@ natdynlink.p.o: natdynlink.c ../byterun/misc.h ../byterun/config.h \ ../byterun/misc.h ../byterun/memory.h ../byterun/gc.h \ ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ ../byterun/minor_gc.h stack.h ../byterun/callback.h ../byterun/alloc.h \ - ../byterun/intext.h ../byterun/io.h natdynlink.h ../byterun/osdeps.h \ + ../byterun/intext.h ../byterun/io.h ../byterun/osdeps.h \ ../byterun/fail.h obj.p.o: obj.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ @@ -723,10 +725,11 @@ startup.p.o: startup.c ../byterun/callback.h ../byterun/mlvalues.h \ ../byterun/memory.h ../byterun/gc.h ../byterun/major_gc.h \ ../byterun/freelist.h ../byterun/minor_gc.h ../byterun/misc.h \ ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/printexc.h stack.h \ - ../byterun/sys.h natdynlink.h + ../byterun/sys.h str.p.o: str.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ - ../byterun/fail.h ../byterun/mlvalues.h ../byterun/misc.h + ../byterun/fail.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/int64_native.h sys.p.o: sys.c ../byterun/config.h ../byterun/../config/m.h \ ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ ../byterun/config.h ../byterun/mlvalues.h ../byterun/debugger.h \ diff --git a/asmrun/Makefile b/asmrun/Makefile index a41b5cf8d7..89adaa2e0c 100644 --- a/asmrun/Makefile +++ b/asmrun/Makefile @@ -11,8 +11,6 @@ # # ######################################################################### -# $Id: Makefile 12959 2012-09-27 13:12:51Z maranget $ - include ../config/Makefile CC=$(NATIVECC) @@ -172,8 +170,11 @@ clean:: .SUFFIXES: .S .d.o .p.o .S.o: - $(ASPP) -DSYS_$(SYSTEM) -o $*.o $*.S || \ - { echo "If your assembler produced syntax errors, it is probably unhappy with the"; echo "preprocessor. Check your assembler, or try producing $*.o by hand."; exit 2; } + $(ASPP) -DSYS_$(SYSTEM) -DMODEL_$(MODEL) -o $*.o $*.S || \ + { echo "If your assembler produced syntax errors, it is probably";\ + echo "unhappy with the preprocessor. Check your assembler, or";\ + echo "try producing $*.o by hand.";\ + exit 2; } .S.p.o: $(ASPP) -DSYS_$(SYSTEM) $(ASPPPROFFLAGS) -o $*.p.o $*.S diff --git a/asmrun/Makefile.nt b/asmrun/Makefile.nt index e5cdde16de..876fe60244 100644 --- a/asmrun/Makefile.nt +++ b/asmrun/Makefile.nt @@ -11,14 +11,13 @@ # # ######################################################################### -# $Id: Makefile.nt 12959 2012-09-27 13:12:51Z maranget $ - include ../config/Makefile CC=$(NATIVECC) -CFLAGS=-I../byterun -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) $(NATIVECCCOMPOPTS) +CFLAGS=-I../byterun -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) \ + $(NATIVECCCOMPOPTS) -COBJS=startup.$(O) main.$(O) fail.$(O) roots.$(O) signals.$(O) signals_asm.$(O) \ +COBJS=startup.$(O) main.$(O) fail.$(O) roots.$(O) signals.$(O) signals_asm.$(O)\ misc.$(O) freelist.$(O) major_gc.$(O) minor_gc.$(O) memory.$(O) alloc.$(O) \ compare.$(O) ints.$(O) floats.$(O) str.$(O) array.$(O) io.$(O) extern.$(O) \ intern.$(O) hash.$(O) sys.$(O) parsing.$(O) gc_ctrl.$(O) terminfo.$(O) \ @@ -52,10 +51,10 @@ amd64nt.obj: amd64nt.asm $(ASM)amd64nt.obj amd64nt.asm i386.o: i386.S - $(CC) -c -DSYS_$(SYSTEM) i386.S + $(ASPP) -DSYS_$(SYSTEM) i386.S amd64.o: amd64.S - $(CC) -c -DSYS_$(SYSTEM) amd64.S + $(ASPP) -DSYS_$(SYSTEM) amd64.S install: cp libasmrun.$(A) $(LIBDIR) diff --git a/asmrun/amd64.S b/asmrun/amd64.S index 2a1eeca662..4a5218f269 100644 --- a/asmrun/amd64.S +++ b/asmrun/amd64.S @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id$ */ - /* Asm part of the runtime system, AMD64 processor */ /* Must be preprocessed by cpp */ @@ -75,6 +73,23 @@ #define CFI_ADJUST(n) #endif +#ifdef WITH_FRAME_POINTERS + +#define ENTER_FUNCTION \ + pushq %rbp; CFI_ADJUST(8); \ + movq %rsp, %rbp +#define LEAVE_FUNCTION \ + popq %rbp; CFI_ADJUST(-8); + +#else + +#define ENTER_FUNCTION \ + subq $8, %rsp; CFI_ADJUST (8); +#define LEAVE_FUNCTION \ + addq $8, %rsp; CFI_ADJUST (-8); + +#endif + #if defined(__PIC__) && !defined(SYS_mingw64) /* Position-independent operations on global variables. */ @@ -111,12 +126,16 @@ /* Record lowest stack address and return address. Clobbers %rax. */ #define RECORD_STACK_FRAME(OFFSET) \ - pushq %r11 ; CFI_ADJUST(8); \ + pushq %r11 ; CFI_ADJUST(8); \ movq 8+OFFSET(%rsp), %rax ; \ - STORE_VAR(%rax,caml_last_return_address) ; \ + STORE_VAR(%rax,caml_last_return_address) ; \ leaq 16+OFFSET(%rsp), %rax ; \ - STORE_VAR(%rax,caml_bottom_of_stack) ; \ - popq %r11; CFI_ADJUST(-8) + STORE_VAR(%rax,caml_bottom_of_stack) ; \ + popq %r11; CFI_ADJUST(-8) + +/* Load address of global [label] in register [dst]. */ +#define LEA_VAR(label,dst) \ + movq GREL(label)(%rip), dst #else @@ -142,10 +161,12 @@ #define RECORD_STACK_FRAME(OFFSET) \ movq OFFSET(%rsp), %rax ; \ - STORE_VAR(%rax,caml_last_return_address) ; \ + STORE_VAR(%rax,caml_last_return_address) ; \ leaq 8+OFFSET(%rsp), %rax ; \ - STORE_VAR(%rax,caml_bottom_of_stack) + STORE_VAR(%rax,caml_bottom_of_stack) +#define LEA_VAR(label,dst) \ + leaq G(label)(%rip), dst #endif /* Save and restore all callee-save registers on stack. @@ -164,8 +185,8 @@ pushq %r13; CFI_ADJUST (8); \ pushq %r14; CFI_ADJUST (8); \ pushq %r15; CFI_ADJUST (8); \ - subq $(8+10*16), %rsp; CFI_ADJUST (8+10*16); \ - movupd %xmm6, 0*16(%rsp); \ + subq $(8+10*16), %rsp; CFI_ADJUST (8+10*16); \ + movupd %xmm6, 0*16(%rsp); \ movupd %xmm7, 1*16(%rsp); \ movupd %xmm8, 2*16(%rsp); \ movupd %xmm9, 3*16(%rsp); \ @@ -208,16 +229,16 @@ pushq %r13; CFI_ADJUST(8); \ pushq %r14; CFI_ADJUST(8); \ pushq %r15; CFI_ADJUST(8); \ - subq $8, %rsp; CFI_ADJUST(8) + subq $8, %rsp; CFI_ADJUST(8) #define POP_CALLEE_SAVE_REGS \ - addq $8, %rsp; CFI_ADJUST(-8); \ + addq $8, %rsp; CFI_ADJUST(-8); \ popq %r15; CFI_ADJUST(-8); \ popq %r14; CFI_ADJUST(-8); \ popq %r13; CFI_ADJUST(-8); \ popq %r12; CFI_ADJUST(-8); \ popq %rbp; CFI_ADJUST(-8); \ - popq %rbx; CFI_ADJUST(-8) + popq %rbx; CFI_ADJUST(-8); #endif @@ -234,6 +255,8 @@ .globl G(caml_system__code_begin) G(caml_system__code_begin): + ret /* just one instruction, so that debuggers don't display + caml_system__code_begin instead of caml_call_gc */ /* Allocation */ @@ -249,11 +272,15 @@ LBL(caml_call_gc): addq $32768, %rsp #endif /* Build array of registers, save it into caml_gc_regs */ - pushq %r13; CFI_ADJUST (8); - pushq %r12; CFI_ADJUST (8); - pushq %rbp; CFI_ADJUST (8); +#ifdef WITH_FRAME_POINTERS + ENTER_FUNCTION ; +#else + pushq %rbp; CFI_ADJUST(8); +#endif pushq %r11; CFI_ADJUST (8); pushq %r10; CFI_ADJUST (8); + pushq %r13; CFI_ADJUST (8); + pushq %r12; CFI_ADJUST (8); pushq %r9; CFI_ADJUST (8); pushq %r8; CFI_ADJUST (8); pushq %rcx; CFI_ADJUST (8); @@ -264,8 +291,8 @@ LBL(caml_call_gc): pushq %rax; CFI_ADJUST (8); STORE_VAR(%rsp, caml_gc_regs) /* Save caml_young_ptr, caml_exception_pointer */ - STORE_VAR(%r15, caml_young_ptr) - STORE_VAR(%r14, caml_exception_pointer) + STORE_VAR(%r15, caml_young_ptr) + STORE_VAR(%r14, caml_exception_pointer) /* Save floating-point registers */ subq $(16*8), %rsp; CFI_ADJUST (16*8); movsd %xmm0, 0*8(%rsp) @@ -285,12 +312,12 @@ LBL(caml_call_gc): movsd %xmm14, 14*8(%rsp) movsd %xmm15, 15*8(%rsp) /* Call the garbage collector */ - PREPARE_FOR_C_CALL + PREPARE_FOR_C_CALL call GCALL(caml_garbage_collection) - CLEANUP_AFTER_C_CALL + CLEANUP_AFTER_C_CALL /* Restore caml_young_ptr, caml_exception_pointer */ - LOAD_VAR(caml_young_ptr, %r15) - LOAD_VAR(caml_exception_pointer, %r14) + LOAD_VAR(caml_young_ptr, %r15) + LOAD_VAR(caml_exception_pointer, %r14) /* Restore all regs used by the code generator */ movsd 0*8(%rsp), %xmm0 movsd 1*8(%rsp), %xmm1 @@ -317,11 +344,15 @@ LBL(caml_call_gc): popq %rcx; CFI_ADJUST(-8) popq %r8; CFI_ADJUST(-8) popq %r9; CFI_ADJUST(-8) - popq %r10; CFI_ADJUST(-8) - popq %r11; CFI_ADJUST(-8) - popq %rbp; CFI_ADJUST(-8) popq %r12; CFI_ADJUST(-8) popq %r13; CFI_ADJUST(-8) + popq %r10; CFI_ADJUST(-8) + popq %r11; CFI_ADJUST(-8) +#ifdef WITH_FRAME_POINTERS + LEAVE_FUNCTION +#else + popq %rbp; CFI_ADJUST(-8); +#endif /* Return to caller */ ret CFI_ENDPROC @@ -335,9 +366,11 @@ LBL(caml_alloc1): ret LBL(100): RECORD_STACK_FRAME(0) - subq $8, %rsp; CFI_ADJUST (8); + ENTER_FUNCTION +/* subq $8, %rsp; CFI_ADJUST (8); */ call LBL(caml_call_gc) - addq $8, %rsp; CFI_ADJUST (-8); +/* addq $8, %rsp; CFI_ADJUST (-8); */ + LEAVE_FUNCTION jmp LBL(caml_alloc1) CFI_ENDPROC @@ -350,9 +383,11 @@ LBL(caml_alloc2): ret LBL(101): RECORD_STACK_FRAME(0) - subq $8, %rsp; CFI_ADJUST (8); + ENTER_FUNCTION +/* subq $8, %rsp; CFI_ADJUST (8); */ call LBL(caml_call_gc) - addq $8, %rsp; CFI_ADJUST (-8); +/* addq $8, %rsp; CFI_ADJUST (-8); */ + LEAVE_FUNCTION jmp LBL(caml_alloc2) CFI_ENDPROC @@ -365,9 +400,11 @@ LBL(caml_alloc3): ret LBL(102): RECORD_STACK_FRAME(0) - subq $8, %rsp; CFI_ADJUST (8) + ENTER_FUNCTION +/* subq $8, %rsp; CFI_ADJUST (8) */ call LBL(caml_call_gc) - addq $8, %rsp; CFI_ADJUST (-8) +/* addq $8, %rsp; CFI_ADJUST (-8) */ + LEAVE_FUNCTION jmp LBL(caml_alloc3) CFI_ENDPROC @@ -382,7 +419,14 @@ LBL(caml_allocN): ret LBL(103): RECORD_STACK_FRAME(8) +#ifdef WITH_FRAME_POINTERS + /* Do we need 16-byte alignment here ? */ + ENTER_FUNCTION +#endif call LBL(caml_call_gc) +#ifdef WITH_FRAME_POINTERS + LEAVE_FUNCTION +#endif popq %rax; CFI_ADJUST(-8) /* recover desired size */ jmp LBL(caml_allocN) CFI_ENDPROC @@ -405,8 +449,8 @@ LBL(caml_c_call): addq $32768, %rsp #endif /* Make the exception handler and alloc ptr available to the C code */ - STORE_VAR(%r15, caml_young_ptr) - STORE_VAR(%r14, caml_exception_pointer) + STORE_VAR(%r15, caml_young_ptr) + STORE_VAR(%r14, caml_exception_pointer) /* Call the function (address in %rax) */ /* No need to PREPARE_FOR_C_CALL since the caller already reserved the stack space if needed (cf. amd64/proc.ml) */ @@ -424,13 +468,13 @@ FUNCTION(G(caml_start_program)) /* Common code for caml_start_program and caml_callback* */ LBL(caml_start_program): /* Build a callback link */ - subq $8, %rsp; CFI_ADJUST (8) /* stack 16-aligned */ + subq $8, %rsp; CFI_ADJUST (8) /* stack 16-aligned */ PUSH_VAR(caml_gc_regs) PUSH_VAR(caml_last_return_address) PUSH_VAR(caml_bottom_of_stack) /* Setup alloc ptr and exception ptr */ - LOAD_VAR(caml_young_ptr, %r15) - LOAD_VAR(caml_exception_pointer, %r14) + LOAD_VAR(caml_young_ptr, %r15) + LOAD_VAR(caml_exception_pointer, %r14) /* Build an exception handler */ lea LBL(108)(%rip), %r13 pushq %r13; CFI_ADJUST(8) @@ -446,13 +490,13 @@ LBL(107): CFI_ADJUST(-16) LBL(109): /* Update alloc ptr and exception ptr */ - STORE_VAR(%r15,caml_young_ptr) - STORE_VAR(%r14,caml_exception_pointer) + STORE_VAR(%r15,caml_young_ptr) + STORE_VAR(%r14,caml_exception_pointer) /* Pop the callback link, restoring the global variables */ - POP_VAR(caml_bottom_of_stack) + POP_VAR(caml_bottom_of_stack) POP_VAR(caml_last_return_address) POP_VAR(caml_gc_regs) - addq $8, %rsp; CFI_ADJUST (-8); + addq $8, %rsp; CFI_ADJUST (-8); /* Restore callee-save registers. */ POP_CALLEE_SAVE_REGS /* Return to caller. */ @@ -485,19 +529,27 @@ CFI_STARTPROC TESTL_VAR($1, caml_backtrace_active) jne LBL(110) movq %r14, %rsp - popq %r14; CFI_ADJUST(-8) + popq %r14 ret LBL(110): movq %rax, %r12 /* Save exception bucket */ movq %rax, C_ARG_1 /* arg 1: exception bucket */ - movq 0(%rsp), C_ARG_2 /* arg 2: pc of raise */ - leaq 8(%rsp), C_ARG_3 /* arg 3: sp of raise */ +#ifdef WITH_FRAME_POINTERS + ENTER_FUNCTION + movq 8(%rsp), C_ARG_2 /* arg 2: pc of raise */ + leaq 16(%rsp), C_ARG_3 /* arg 3: sp at raise */ +#else + popq C_ARG_2 /* arg 2: pc of raise */ + movq %rsp, C_ARG_3 /* arg 3: sp at raise */ +#endif movq %r14, C_ARG_4 /* arg 4: sp of handler */ - PREPARE_FOR_C_CALL /* no need to cleanup after */ + /* PR#5700: thanks to popq above, stack is now 16-aligned */ + /* Thanks to ENTER_FUNCTION, stack is now 16-aligned */ + PREPARE_FOR_C_CALL /* no need to cleanup after */ call GCALL(caml_stash_backtrace) movq %r12, %rax /* Recover exception bucket */ movq %r14, %rsp - popq %r14; CFI_ADJUST(-8) + popq %r14 ret CFI_ENDPROC @@ -509,24 +561,42 @@ CFI_STARTPROC jne LBL(111) movq C_ARG_1, %rax LOAD_VAR(caml_exception_pointer, %rsp) /* Cut stack */ - popq %r14; CFI_ADJUST(-8) /* Recover previous exception handler */ + popq %r14 /* Recover previous exception handler */ LOAD_VAR(caml_young_ptr, %r15) /* Reload alloc ptr */ ret LBL(111): +#ifdef WITH_FRAME_POINTERS + ENTER_FUNCTION ; +#endif movq C_ARG_1, %r12 /* Save exception bucket */ /* arg 1: exception bucket */ - LOAD_VAR(caml_last_return_address,C_ARG_2) /* arg 2: pc of raise */ + LOAD_VAR(caml_last_return_address,C_ARG_2) /* arg 2: pc of raise */ LOAD_VAR(caml_bottom_of_stack,C_ARG_3) /* arg 3: sp of raise */ LOAD_VAR(caml_exception_pointer,C_ARG_4) /* arg 4: sp of handler */ - PREPARE_FOR_C_CALL /* no need to cleanup after */ +#ifndef WITH_FRAME_POINTERS + subq $8, %rsp /* PR#5700: maintain stack alignment */ +#endif + PREPARE_FOR_C_CALL /* no need to cleanup after */ call GCALL(caml_stash_backtrace) movq %r12, %rax /* Recover exception bucket */ - LOAD_VAR(caml_exception_pointer,%rsp) - popq %r14; CFI_ADJUST(-8) /* Recover previous exception handler */ - LOAD_VAR(caml_young_ptr,%r15) /* Reload alloc ptr */ + LOAD_VAR(caml_exception_pointer,%rsp) + popq %r14 /* Recover previous exception handler */ + LOAD_VAR(caml_young_ptr,%r15) /* Reload alloc ptr */ ret CFI_ENDPROC +/* Raise a Stack_overflow exception on return from segv_handler() + (in asmrun/signals_asm.c). On entry, the stack is full, so we + cannot record a backtrace. + No CFI information here since this function disrupts the stack + backtrace anyway. */ + +FUNCTION(G(caml_stack_overflow)) + LEA_VAR(caml_bucket_Stack_overflow, %rax) + movq %r14, %rsp /* cut the stack */ + popq %r14 /* recover previous exn handler */ + ret /* jump to handler's code */ + /* Callback from C to OCaml */ FUNCTION(G(caml_callback_exn)) @@ -585,20 +655,20 @@ G(caml_system__frametable): .align EIGHT_ALIGN #if defined(SYS_macosx) - .literal16 + .literal16 #elif defined(SYS_mingw64) - .section .rdata,"dr" + .section .rdata,"dr" #else - .section .rodata.cst8,"a",@progbits + .section .rodata.cst8,"a",@progbits #endif .globl G(caml_negf_mask) .align SIXTEEN_ALIGN G(caml_negf_mask): - .quad 0x8000000000000000, 0 + .quad 0x8000000000000000, 0 .globl G(caml_absf_mask) .align SIXTEEN_ALIGN G(caml_absf_mask): - .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF + .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF #if defined(SYS_linux) /* Mark stack as non-executable, PR#4564 */ diff --git a/asmrun/amd64nt.asm b/asmrun/amd64nt.asm index d96f83970e..e86ee72ced 100644 --- a/asmrun/amd64nt.asm +++ b/asmrun/amd64nt.asm @@ -11,8 +11,6 @@ ;* * ;*********************************************************************** -; $Id: amd64nt.asm 12858 2012-08-10 14:45:51Z maranget $ - ; Asm part of the runtime system, AMD64 processor, Intel syntax ; Notes on Win64 calling conventions: @@ -30,7 +28,7 @@ EXTRN caml_bottom_of_stack: QWORD EXTRN caml_last_return_address: QWORD EXTRN caml_gc_regs: QWORD - EXTRN caml_exception_pointer: QWORD + EXTRN caml_exception_pointer: QWORD EXTRN caml_backtrace_active: DWORD EXTRN caml_stash_backtrace: NEAR @@ -48,14 +46,14 @@ caml_call_gc: mov caml_bottom_of_stack, rax L105: ; Save caml_young_ptr, caml_exception_pointer - mov caml_young_ptr, r15 - mov caml_exception_pointer, r14 + mov caml_young_ptr, r15 + mov caml_exception_pointer, r14 ; Build array of registers, save it into caml_gc_regs - push r13 - push r12 push rbp push r11 push r10 + push r13 + push r12 push r9 push r8 push rcx @@ -113,14 +111,14 @@ L105: pop rcx pop r8 pop r9 + pop r12 + pop r13 pop r10 pop r11 pop rbp - pop r12 - pop r13 ; Restore caml_young_ptr, caml_exception_pointer - mov r15, caml_young_ptr - mov r14, caml_exception_pointer + mov r15, caml_young_ptr + mov r14, caml_exception_pointer ; Return to caller ret @@ -136,9 +134,9 @@ L100: mov caml_last_return_address, rax lea rax, [rsp + 8] mov caml_bottom_of_stack, rax - sub rsp, 8 + sub rsp, 8 call L105 - add rsp, 8 + add rsp, 8 jmp caml_alloc1 PUBLIC caml_alloc2 @@ -153,9 +151,9 @@ L101: mov caml_last_return_address, rax lea rax, [rsp + 8] mov caml_bottom_of_stack, rax - sub rsp, 8 + sub rsp, 8 call L105 - add rsp, 8 + add rsp, 8 jmp caml_alloc2 PUBLIC caml_alloc3 @@ -170,9 +168,9 @@ L102: mov caml_last_return_address, rax lea rax, [rsp + 8] mov caml_bottom_of_stack, rax - sub rsp, 8 + sub rsp, 8 call L105 - add rsp, 8 + add rsp, 8 jmp caml_alloc3 PUBLIC caml_allocN @@ -202,15 +200,15 @@ caml_c_call: mov caml_last_return_address, r12 mov caml_bottom_of_stack, rsp ; Make the exception handler and alloc ptr available to the C code - mov caml_young_ptr, r15 - mov caml_exception_pointer, r14 + mov caml_young_ptr, r15 + mov caml_exception_pointer, r14 ; Call the function (address in rax) call rax ; Reload alloc ptr - mov r15, caml_young_ptr + mov r15, caml_young_ptr ; Return to caller - push r12 - ret + push r12 + ret ; Start the OCaml program @@ -242,13 +240,13 @@ caml_start_program: ; Common code for caml_start_program and caml_callback* L106: ; Build a callback link - sub rsp, 8 ; stack 16-aligned + sub rsp, 8 ; stack 16-aligned push caml_gc_regs push caml_last_return_address push caml_bottom_of_stack ; Setup alloc ptr and exception ptr - mov r15, caml_young_ptr - mov r14, caml_exception_pointer + mov r15, caml_young_ptr + mov r14, caml_exception_pointer ; Build an exception handler lea r13, L108 push r13 @@ -262,13 +260,13 @@ L107: pop r12 ; dummy register L109: ; Update alloc ptr and exception ptr - mov caml_young_ptr, r15 - mov caml_exception_pointer, r14 + mov caml_young_ptr, r15 + mov caml_exception_pointer, r14 ; Pop the callback restoring, link the global variables pop caml_bottom_of_stack pop caml_last_return_address pop caml_gc_regs - add rsp, 8 + add rsp, 8 ; Restore callee-save registers. movapd xmm6, OWORD PTR [rsp + 0*16] movapd xmm7, OWORD PTR [rsp + 1*16] @@ -441,8 +439,8 @@ caml_callback3_exn: PUBLIC caml_ml_array_bound_error ALIGN 16 caml_ml_array_bound_error: - lea rax, caml_array_bound_error - jmp caml_c_call + lea rax, caml_array_bound_error + jmp caml_c_call .DATA PUBLIC caml_system__frametable @@ -456,11 +454,11 @@ caml_system__frametable LABEL QWORD PUBLIC caml_negf_mask ALIGN 16 caml_negf_mask LABEL QWORD - QWORD 8000000000000000H, 0 + QWORD 8000000000000000H, 0 PUBLIC caml_absf_mask ALIGN 16 caml_absf_mask LABEL QWORD - QWORD 7FFFFFFFFFFFFFFFH, 0FFFFFFFFFFFFFFFFH + QWORD 7FFFFFFFFFFFFFFFH, 0FFFFFFFFFFFFFFFFH END diff --git a/asmrun/arm.S b/asmrun/arm.S index a2dd318dec..2ce244a1a5 100644 --- a/asmrun/arm.S +++ b/asmrun/arm.S @@ -12,14 +12,22 @@ /* */ /***********************************************************************/ -/* $Id: arm.S 12858 2012-08-10 14:45:51Z maranget $ */ - /* Asm part of the runtime system, ARM processor */ /* Must be preprocessed by cpp */ .syntax unified .text -#if defined(SYS_linux_eabihf) +#if defined(SYS_linux_eabihf) && defined(MODEL_armv6) + .arch armv6 + .fpu vfpv2 + .arm + + /* Compatibility macros */ + .macro cbz reg, lbl + cmp \reg, #0 + beq \lbl + .endm +#elif defined(SYS_linux_eabihf) .arch armv7-a .fpu vfpv3-d16 .thumb @@ -36,22 +44,30 @@ cmp \reg, #0 beq \lbl .endm - .macro vpop regs - .endm - .macro vpush regs - .endm #endif trap_ptr .req r8 alloc_ptr .req r10 alloc_limit .req r11 +/* Support for CFI directives */ + +#if defined(ASM_CFI_SUPPORTED) +#define CFI_STARTPROC .cfi_startproc +#define CFI_ENDPROC .cfi_endproc +#define CFI_ADJUST(n) .cfi_adjust_cfa_offset n +#else +#define CFI_STARTPROC +#define CFI_ENDPROC +#define CFI_ADJUST(n) +#endif + /* Support for profiling with gprof */ #if defined(PROFILING) && (defined(SYS_linux_eabihf) || defined(SYS_linux_eabi)) #define PROFILE \ - push {lr}; \ - bl __gnu_mcount_nc + push {lr}; CFI_ADJUST(4); \ + bl __gnu_mcount_nc; CFI_ADJUST(-4) #else #define PROFILE #endif @@ -60,11 +76,11 @@ alloc_limit .req r11 .globl caml_system__code_begin caml_system__code_begin: - + .align 2 .globl caml_call_gc - .type caml_call_gc, %function caml_call_gc: + CFI_STARTPROC PROFILE /* Record return address */ ldr r12, =caml_last_return_address @@ -73,10 +89,12 @@ caml_call_gc: /* Record lowest stack address */ ldr r12, =caml_bottom_of_stack str sp, [r12] +#if defined(SYS_linux_eabihf) /* Save caller floating-point registers on the stack */ - vpush {d0-d7} + vpush {d0-d7}; CFI_ADJUST(64) +#endif /* Save integer registers and return address on the stack */ - push {r0-r7,r12,lr} + push {r0-r7,r12,lr}; CFI_ADJUST(40) /* Store pointer to saved integer registers in caml_gc_regs */ ldr r12, =caml_gc_regs str sp, [r12] @@ -89,9 +107,11 @@ caml_call_gc: /* Call the garbage collector */ bl caml_garbage_collection /* Restore integer registers and return address from the stack */ - pop {r0-r7,r12,lr} + pop {r0-r7,r12,lr}; CFI_ADJUST(-40) +#if defined(SYS_linux_eabihf) /* Restore floating-point registers from the stack */ - vpop {d0-d7} + vpop {d0-d7}; CFI_ADJUST(-64) +#endif /* Reload new allocation pointer and limit */ /* alloc_limit still points to caml_young_ptr */ ldr r12, =caml_young_limit @@ -99,13 +119,14 @@ caml_call_gc: ldr alloc_limit, [r12] /* Return to caller */ bx lr + CFI_ENDPROC .type caml_call_gc, %function .size caml_call_gc, .-caml_call_gc .align 2 .globl caml_alloc1 - .type caml_alloc1, %function caml_alloc1: + CFI_STARTPROC PROFILE .Lcaml_alloc1: sub alloc_ptr, alloc_ptr, 8 @@ -121,13 +142,14 @@ caml_alloc1: ldr lr, [r7] /* Try again */ b .Lcaml_alloc1 + CFI_ENDPROC .type caml_alloc1, %function .size caml_alloc1, .-caml_alloc1 .align 2 .globl caml_alloc2 - .type caml_alloc2, %function caml_alloc2: + CFI_STARTPROC PROFILE .Lcaml_alloc2: sub alloc_ptr, alloc_ptr, 12 @@ -143,6 +165,7 @@ caml_alloc2: ldr lr, [r7] /* Try again */ b .Lcaml_alloc2 + CFI_ENDPROC .type caml_alloc2, %function .size caml_alloc2, .-caml_alloc2 @@ -150,6 +173,7 @@ caml_alloc2: .globl caml_alloc3 .type caml_alloc3, %function caml_alloc3: + CFI_STARTPROC PROFILE .Lcaml_alloc3: sub alloc_ptr, alloc_ptr, 16 @@ -165,13 +189,14 @@ caml_alloc3: ldr lr, [r7] /* Try again */ b .Lcaml_alloc3 + CFI_ENDPROC .type caml_alloc3, %function .size caml_alloc3, .-caml_alloc3 .align 2 .globl caml_allocN - .type caml_allocN, %function caml_allocN: + CFI_STARTPROC PROFILE .Lcaml_allocN: sub alloc_ptr, alloc_ptr, r7 @@ -188,6 +213,7 @@ caml_allocN: ldr lr, [r12] /* Try again */ b .Lcaml_allocN + CFI_ENDPROC .type caml_allocN, %function .size caml_allocN, .-caml_allocN @@ -196,8 +222,8 @@ caml_allocN: .align 2 .globl caml_c_call - .type caml_c_call, %function caml_c_call: + CFI_STARTPROC PROFILE /* Record lowest stack address and return address */ ldr r5, =caml_last_return_address @@ -219,6 +245,7 @@ caml_c_call: ldr alloc_limit, [r6] /* Return */ bx r4 + CFI_ENDPROC .type caml_c_call, %function .size caml_c_call, .-caml_c_call @@ -226,8 +253,8 @@ caml_c_call: .align 2 .globl caml_start_program - .type caml_start_program, %function caml_start_program: + CFI_STARTPROC PROFILE ldr r12, =caml_program @@ -236,11 +263,14 @@ caml_start_program: /* Arguments to the OCaml code are in r0...r3 */ .Ljump_to_caml: +#if defined(SYS_linux_eabihf) + /* Save callee-save floating-point registers */ + vpush {d8-d15}; CFI_ADJUST(64) +#endif /* Save return address and callee-save registers */ - vpush {d8-d15} - push {r4-r8,r10,r11,lr} /* 8-byte alignment */ + push {r4-r8,r10,r11,lr}; CFI_ADJUST(32) /* 8-byte alignment */ /* Setup a callback link on the stack */ - sub sp, sp, 4*4 /* 8-byte alignment */ + sub sp, sp, 16; CFI_ADJUST(16) /* 8-byte alignment */ ldr r4, =caml_bottom_of_stack ldr r5, =caml_last_return_address ldr r6, =caml_gc_regs @@ -251,7 +281,7 @@ caml_start_program: str r5, [sp, 4] str r6, [sp, 8] /* Setup a trap frame to catch exceptions escaping the OCaml code */ - sub sp, sp, 2*4 + sub sp, sp, 8; CFI_ADJUST(8) ldr r6, =caml_exception_pointer ldr r5, =.Ltrap_handler ldr r4, [r6] @@ -270,7 +300,7 @@ caml_start_program: ldr r4, =caml_exception_pointer ldr r5, [sp, 0] str r5, [r4] - add sp, sp, 2*4 + add sp, sp, 8; CFI_ADJUST(-8) /* Pop the callback link, restoring the global variables */ .Lreturn_result: ldr r4, =caml_bottom_of_stack @@ -282,14 +312,18 @@ caml_start_program: ldr r4, =caml_gc_regs ldr r5, [sp, 8] str r5, [r4] - add sp, sp, 4*4 + add sp, sp, 16; CFI_ADJUST(-16) /* Update allocation pointer */ ldr r4, =caml_young_ptr str alloc_ptr, [r4] - /* Reload callee-save registers and return */ - pop {r4-r8,r10,r11,lr} - vpop {d8-d15} + /* Reload callee-save registers and return address */ + pop {r4-r8,r10,r11,lr}; CFI_ADJUST(-32) +#if defined(SYS_linux_eabihf) + /* Reload callee-save floating-point registers */ + vpop {d8-d15}; CFI_ADJUST(-64) +#endif bx lr + CFI_ENDPROC .type .Lcaml_retaddr, %function .size .Lcaml_retaddr, .-.Lcaml_retaddr .type caml_start_program, %function @@ -299,6 +333,7 @@ caml_start_program: .align 2 .Ltrap_handler: + CFI_STARTPROC /* Save exception pointer */ ldr r12, =caml_exception_pointer str trap_ptr, [r12] @@ -306,6 +341,7 @@ caml_start_program: orr r0, r0, 2 /* Return it */ b .Lreturn_result + CFI_ENDPROC .type .Ltrap_handler, %function .size .Ltrap_handler, .-.Ltrap_handler @@ -314,6 +350,7 @@ caml_start_program: .align 2 .globl caml_raise_exn caml_raise_exn: + CFI_STARTPROC PROFILE /* Test if backtrace is active */ ldr r1, =caml_backtrace_active @@ -332,6 +369,7 @@ caml_raise_exn: mov sp, trap_ptr /* Pop previous handler and addr of trap, and jump to it */ pop {trap_ptr, pc} + CFI_ENDPROC .type caml_raise_exn, %function .size caml_raise_exn, .-caml_raise_exn @@ -339,8 +377,8 @@ caml_raise_exn: .align 2 .globl caml_raise_exception - .type caml_raise_exception, %function caml_raise_exception: + CFI_STARTPROC PROFILE /* Reload trap ptr, alloc ptr and alloc limit */ ldr trap_ptr, =caml_exception_pointer @@ -367,6 +405,7 @@ caml_raise_exception: mov sp, trap_ptr /* Pop previous handler and addr of trap, and jump to it */ pop {trap_ptr, pc} + CFI_ENDPROC .type caml_raise_exception, %function .size caml_raise_exception, .-caml_raise_exception @@ -374,8 +413,8 @@ caml_raise_exception: .align 2 .globl caml_callback_exn - .type caml_callback_exn, %function caml_callback_exn: + CFI_STARTPROC PROFILE /* Initial shuffling of arguments (r0 = closure, r1 = first arg) */ mov r12, r0 @@ -383,13 +422,14 @@ caml_callback_exn: mov r1, r12 /* r1 = closure environment */ ldr r12, [r12] /* code pointer */ b .Ljump_to_caml + CFI_ENDPROC .type caml_callback_exn, %function .size caml_callback_exn, .-caml_callback_exn .align 2 .globl caml_callback2_exn - .type caml_callback2_exn, %function caml_callback2_exn: + CFI_STARTPROC PROFILE /* Initial shuffling of arguments (r0 = closure, r1 = arg1, r2 = arg2) */ mov r12, r0 @@ -398,13 +438,14 @@ caml_callback2_exn: mov r2, r12 /* r2 = closure environment */ ldr r12, =caml_apply2 b .Ljump_to_caml + CFI_ENDPROC .type caml_callback2_exn, %function .size caml_callback2_exn, .-caml_callback2_exn .align 2 .globl caml_callback3_exn - .type caml_callback3_exn, %function caml_callback3_exn: + CFI_STARTPROC PROFILE /* Initial shuffling of arguments */ /* (r0 = closure, r1 = arg1, r2 = arg2, r3 = arg3) */ @@ -415,18 +456,20 @@ caml_callback3_exn: mov r3, r12 /* r3 = closure environment */ ldr r12, =caml_apply3 b .Ljump_to_caml + CFI_ENDPROC .type caml_callback3_exn, %function .size caml_callback3_exn, .-caml_callback3_exn .align 2 .globl caml_ml_array_bound_error - .type caml_ml_array_bound_error, %function caml_ml_array_bound_error: + CFI_STARTPROC PROFILE /* Load address of [caml_array_bound_error] in r7 */ ldr r7, =caml_array_bound_error /* Call that function */ b caml_c_call + CFI_ENDPROC .type caml_ml_array_bound_error, %function .size caml_ml_array_bound_error, .-caml_ml_array_bound_error diff --git a/asmrun/backtrace.c b/asmrun/backtrace.c index 68043a9dd2..3ca182413f 100644 --- a/asmrun/backtrace.c +++ b/asmrun/backtrace.c @@ -11,11 +11,12 @@ /* */ /***********************************************************************/ -/* $Id: backtrace.c 12858 2012-08-10 14:45:51Z maranget $ */ - /* Stack backtrace for uncaught exceptions */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> + #include "alloc.h" #include "backtrace.h" #include "memory.h" @@ -193,18 +194,17 @@ void caml_print_exception_backtrace(void) } } -/* Convert the backtrace to a data structure usable from OCaml */ +/* Convert the raw backtrace to a data structure usable from OCaml */ -CAMLprim value caml_get_exception_backtrace(value unit) -{ - CAMLparam0(); +CAMLprim value caml_convert_raw_backtrace(value backtrace) { + CAMLparam1(backtrace); CAMLlocal4(res, arr, p, fname); int i; struct loc_info li; - arr = caml_alloc(caml_backtrace_pos, 0); - for (i = 0; i < caml_backtrace_pos; i++) { - extract_location_info((frame_descr *) (caml_backtrace_buffer[i]), &li); + arr = caml_alloc(Wosize_val(backtrace), 0); + for (i = 0; i < Wosize_val(backtrace); i++) { + extract_location_info((frame_descr *) Field(backtrace, i), &li); if (li.loc_valid) { fname = caml_copy_string(li.loc_filename); p = caml_alloc_small(5, 0); @@ -222,3 +222,35 @@ CAMLprim value caml_get_exception_backtrace(value unit) res = caml_alloc_small(1, 0); Field(res, 0) = arr; /* Some */ CAMLreturn(res); } + +/* Get a copy of the latest backtrace */ + +CAMLprim value caml_get_exception_raw_backtrace(value unit) +{ + CAMLparam0(); + CAMLlocal1(res); + res = caml_alloc(caml_backtrace_pos, Abstract_tag); + if(caml_backtrace_buffer != NULL) + memcpy(&Field(res, 0), caml_backtrace_buffer, + caml_backtrace_pos * sizeof(code_t)); + CAMLreturn(res); +} + +/* the function below is deprecated: we previously returned directly + the OCaml-usable representation, instead of the raw backtrace as an + abstract type, but this has a large performance overhead if you + store a lot of backtraces and print only some of them. + + It is not used by the Printexc library anymore, or anywhere else in + the compiler, but we have kept it in case some user still depends + on it as an external. +*/ + +CAMLprim value caml_get_exception_backtrace(value unit) +{ + CAMLparam0(); + CAMLlocal2(raw,res); + raw = caml_get_exception_raw_backtrace(unit); + res = caml_convert_raw_backtrace(raw); + CAMLreturn(res); +} diff --git a/asmrun/fail.c b/asmrun/fail.c index 70ff6413b3..09a9af9668 100644 --- a/asmrun/fail.c +++ b/asmrun/fail.c @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: fail.c 12858 2012-08-10 14:45:51Z maranget $ */ - /* Raising exceptions from C. */ #include <signal.h> diff --git a/asmrun/i386.S b/asmrun/i386.S index 169b76b28f..306c9a5885 100644 --- a/asmrun/i386.S +++ b/asmrun/i386.S @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: i386.S 12858 2012-08-10 14:45:51Z maranget $ */ - /* Asm part of the runtime system, Intel 386 processor */ /* Must be preprocessed by cpp */ @@ -307,9 +305,9 @@ LBL(107): /* Pop the exception handler */ popl G(caml_exception_pointer); CFI_ADJUST(-4) #ifdef SYS_macosx - addl $12, %esp ; CFI_ADJUST(-12) + addl $12, %esp ; CFI_ADJUST(-12) #else - addl $4, %esp ; CFI_ADJUST(-4) + addl $4, %esp ; CFI_ADJUST(-4) #endif LBL(109): /* Pop the callback link, restoring the global variables */ @@ -363,7 +361,7 @@ LBL(110): FUNCTION(caml_raise_exception) CFI_STARTPROC PROFILE_C - testl $1, G(caml_backtrace_active) + testl $1, G(caml_backtrace_active) jne LBL(111) movl 4(%esp), %eax movl G(caml_exception_pointer), %esp @@ -373,10 +371,10 @@ FUNCTION(caml_raise_exception) LBL(111): movl 4(%esp), %esi /* Save exception bucket in esi */ ALIGN_STACK(12) - pushl G(caml_exception_pointer); CFI_ADJUST(4) /* arg 4: sp of handler */ - pushl G(caml_bottom_of_stack); CFI_ADJUST(4) /* arg 3: sp of raise */ - pushl G(caml_last_return_address); CFI_ADJUST(4) /* arg 2: pc of raise */ - pushl %esi; CFI_ADJUST(4) /* arg 1: exception bucket */ + pushl G(caml_exception_pointer); CFI_ADJUST(4) /* 4: sp of handler */ + pushl G(caml_bottom_of_stack); CFI_ADJUST(4) /* 3: sp of raise */ + pushl G(caml_last_return_address); CFI_ADJUST(4)/* 2: pc of raise */ + pushl %esi; CFI_ADJUST(4) /* 1: exception bucket */ call G(caml_stash_backtrace) movl %esi, %eax /* Recover exception bucket */ movl G(caml_exception_pointer), %esp @@ -453,7 +451,7 @@ FUNCTION(caml_ml_array_bound_error) movl %edx, G(caml_bottom_of_stack) /* For MacOS X: re-align the stack */ #ifdef SYS_macosx - andl $-16, %esp + andl $-16, %esp #endif /* Branch to [caml_array_bound_error] (never returns) */ call G(caml_array_bound_error) diff --git a/asmrun/i386nt.asm b/asmrun/i386nt.asm index d45720ff9d..d74497413f 100644 --- a/asmrun/i386nt.asm +++ b/asmrun/i386nt.asm @@ -11,12 +11,10 @@ ;* * ;*********************************************************************** -; $Id: i386nt.asm 12858 2012-08-10 14:45:51Z maranget $ - ; Asm part of the runtime system, Intel 386 processor, Intel syntax - .386 - .MODEL FLAT + .386 + .MODEL FLAT EXTERN _caml_garbage_collection: PROC EXTERN _caml_apply2: PROC @@ -25,10 +23,10 @@ EXTERN _caml_array_bound_error: PROC EXTERN _caml_young_limit: DWORD EXTERN _caml_young_ptr: DWORD - EXTERN _caml_bottom_of_stack: DWORD - EXTERN _caml_last_return_address: DWORD - EXTERN _caml_gc_regs: DWORD - EXTERN _caml_exception_pointer: DWORD + EXTERN _caml_bottom_of_stack: DWORD + EXTERN _caml_last_return_address: DWORD + EXTERN _caml_gc_regs: DWORD + EXTERN _caml_exception_pointer: DWORD EXTERN _caml_backtrace_active: DWORD EXTERN _caml_stash_backtrace: PROC @@ -39,11 +37,11 @@ PUBLIC _caml_alloc2 PUBLIC _caml_alloc3 PUBLIC _caml_allocN - PUBLIC _caml_call_gc + PUBLIC _caml_call_gc _caml_call_gc: ; Record lowest stack address and return address - mov eax, [esp] + mov eax, [esp] mov _caml_last_return_address, eax lea eax, [esp+4] mov _caml_bottom_of_stack, eax @@ -57,9 +55,9 @@ L105: push ebp push eax mov _caml_gc_regs, esp ; Call the garbage collector - call _caml_garbage_collection + call _caml_garbage_collection ; Restore all regs used by the code generator - pop eax + pop eax pop ebx pop ecx pop edx @@ -71,13 +69,13 @@ L105: push ebp ALIGN 4 _caml_alloc1: - mov eax, _caml_young_ptr - sub eax, 8 - mov _caml_young_ptr, eax - cmp eax, _caml_young_limit - jb L100 + mov eax, _caml_young_ptr + sub eax, 8 + mov _caml_young_ptr, eax + cmp eax, _caml_young_limit + jb L100 ret -L100: mov eax, [esp] +L100: mov eax, [esp] mov _caml_last_return_address, eax lea eax, [esp+4] mov _caml_bottom_of_stack, eax @@ -86,13 +84,13 @@ L100: mov eax, [esp] ALIGN 4 _caml_alloc2: - mov eax, _caml_young_ptr - sub eax, 12 - mov _caml_young_ptr, eax - cmp eax, _caml_young_limit - jb L101 + mov eax, _caml_young_ptr + sub eax, 12 + mov _caml_young_ptr, eax + cmp eax, _caml_young_limit + jb L101 ret -L101: mov eax, [esp] +L101: mov eax, [esp] mov _caml_last_return_address, eax lea eax, [esp+4] mov _caml_bottom_of_stack, eax @@ -101,13 +99,13 @@ L101: mov eax, [esp] ALIGN 4 _caml_alloc3: - mov eax, _caml_young_ptr - sub eax, 16 - mov _caml_young_ptr, eax - cmp eax, _caml_young_limit - jb L102 + mov eax, _caml_young_ptr + sub eax, 16 + mov _caml_young_ptr, eax + cmp eax, _caml_young_limit + jb L102 ret -L102: mov eax, [esp] +L102: mov eax, [esp] mov _caml_last_return_address, eax lea eax, [esp+4] mov _caml_bottom_of_stack, eax @@ -126,7 +124,7 @@ L103: sub eax, _caml_young_ptr ; eax = - size neg eax ; eax = size push eax ; save desired size sub _caml_young_ptr, eax ; must update young_ptr - mov eax, [esp+4] + mov eax, [esp+4] mov _caml_last_return_address, eax lea eax, [esp+8] mov _caml_bottom_of_stack, eax @@ -140,12 +138,12 @@ L103: sub eax, _caml_young_ptr ; eax = - size ALIGN 4 _caml_c_call: ; Record lowest stack address and return address - mov edx, [esp] - mov _caml_last_return_address, edx - lea edx, [esp+4] - mov _caml_bottom_of_stack, edx + mov edx, [esp] + mov _caml_last_return_address, edx + lea edx, [esp+4] + mov _caml_bottom_of_stack, edx ; Call the function (address in %eax) - jmp eax + jmp eax ; Start the OCaml program @@ -153,10 +151,10 @@ _caml_c_call: ALIGN 4 _caml_start_program: ; Save callee-save registers - push ebx - push esi - push edi - push ebp + push ebx + push esi + push edi + push ebp ; Initial code pointer is caml_program mov esi, offset _caml_program @@ -165,29 +163,29 @@ _caml_start_program: L106: ; Build a callback link push _caml_gc_regs - push _caml_last_return_address - push _caml_bottom_of_stack + push _caml_last_return_address + push _caml_bottom_of_stack ; Build an exception handler - push L108 - push _caml_exception_pointer - mov _caml_exception_pointer, esp + push L108 + push _caml_exception_pointer + mov _caml_exception_pointer, esp ; Call the OCaml code - call esi + call esi L107: ; Pop the exception handler - pop _caml_exception_pointer - pop esi ; dummy register + pop _caml_exception_pointer + pop esi ; dummy register L109: ; Pop the callback link, restoring the global variables ; used by caml_c_call - pop _caml_bottom_of_stack - pop _caml_last_return_address + pop _caml_bottom_of_stack + pop _caml_last_return_address pop _caml_gc_regs ; Restore callee-save registers. - pop ebp - pop edi - pop esi - pop ebx + pop ebp + pop edi + pop esi + pop ebx ; Return to caller. ret L108: @@ -203,8 +201,8 @@ L108: _caml_raise_exn: test _caml_backtrace_active, 1 jne L110 - mov esp, _caml_exception_pointer - pop _caml_exception_pointer + mov esp, _caml_exception_pointer + pop _caml_exception_pointer ret L110: mov esi, eax ; Save exception bucket in esi @@ -228,9 +226,9 @@ L110: _caml_raise_exception: test _caml_backtrace_active, 1 jne L111 - mov eax, [esp+4] - mov esp, _caml_exception_pointer - pop _caml_exception_pointer + mov eax, [esp+4] + mov esp, _caml_exception_pointer + pop _caml_exception_pointer ret L111: mov esi, [esp+4] ; Save exception bucket in esi @@ -250,46 +248,46 @@ L111: ALIGN 4 _caml_callback_exn: ; Save callee-save registers - push ebx - push esi - push edi - push ebp + push ebx + push esi + push edi + push ebp ; Initial loading of arguments - mov ebx, [esp+20] ; closure - mov eax, [esp+24] ; argument - mov esi, [ebx] ; code pointer + mov ebx, [esp+20] ; closure + mov eax, [esp+24] ; argument + mov esi, [ebx] ; code pointer jmp L106 PUBLIC _caml_callback2_exn ALIGN 4 _caml_callback2_exn: ; Save callee-save registers - push ebx - push esi - push edi - push ebp + push ebx + push esi + push edi + push ebp ; Initial loading of arguments - mov ecx, [esp+20] ; closure - mov eax, [esp+24] ; first argument - mov ebx, [esp+28] ; second argument - mov esi, offset _caml_apply2 ; code pointer - jmp L106 + mov ecx, [esp+20] ; closure + mov eax, [esp+24] ; first argument + mov ebx, [esp+28] ; second argument + mov esi, offset _caml_apply2 ; code pointer + jmp L106 PUBLIC _caml_callback3_exn - ALIGN 4 + ALIGN 4 _caml_callback3_exn: ; Save callee-save registers - push ebx - push esi - push edi - push ebp + push ebx + push esi + push edi + push ebp ; Initial loading of arguments - mov edx, [esp+20] ; closure - mov eax, [esp+24] ; first argument - mov ebx, [esp+28] ; second argument - mov ecx, [esp+32] ; third argument - mov esi, offset _caml_apply3 ; code pointer - jmp L106 + mov edx, [esp+20] ; closure + mov eax, [esp+24] ; first argument + mov ebx, [esp+28] ; second argument + mov ecx, [esp+32] ; third argument + mov esi, offset _caml_apply3 ; code pointer + jmp L106 PUBLIC _caml_ml_array_bound_error ALIGN 4 diff --git a/asmrun/natdynlink.c b/asmrun/natdynlink.c index 8625c545c8..edb389dbb0 100644 --- a/asmrun/natdynlink.c +++ b/asmrun/natdynlink.c @@ -18,7 +18,6 @@ #include "callback.h" #include "alloc.h" #include "intext.h" -#include "natdynlink.h" #include "osdeps.h" #include "fail.h" diff --git a/asmrun/natdynlink.h b/asmrun/natdynlink.h deleted file mode 100644 index e69de29bb2..0000000000 --- a/asmrun/natdynlink.h +++ /dev/null diff --git a/asmrun/power-elf.S b/asmrun/power-elf.S index 03c4090f68..94f4a29d4c 100644 --- a/asmrun/power-elf.S +++ b/asmrun/power-elf.S @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: power-elf.S 12858 2012-08-10 14:45:51Z maranget $ */ - #define Addrglobal(reg,glob) \ addis reg, 0, glob@ha; \ addi reg, reg, glob@l @@ -29,7 +27,7 @@ .globl caml_system__code_begin caml_system__code_begin: - + .globl caml_call_gc .type caml_call_gc, @function caml_call_gc: diff --git a/asmrun/power-rhapsody.S b/asmrun/power-rhapsody.S index 85f534ae02..309c955b19 100644 --- a/asmrun/power-rhapsody.S +++ b/asmrun/power-rhapsody.S @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: power-rhapsody.S 12858 2012-08-10 14:45:51Z maranget $ */ - #ifdef __ppc64__ #define X(a,b) b #else @@ -43,7 +41,7 @@ .globl _caml_system__code_begin _caml_system__code_begin: - + /* Invoke the garbage collector. */ .globl _caml_call_gc @@ -287,8 +285,8 @@ L113: L112: mr r28, r3 /* preserve exn bucket in callee-save */ /* arg 1: exception bucket (already in r3) */ - Loadglobal r4, _caml_last_return_address, r11 /* arg 2: PC of raise */ - Loadglobal r5, _caml_bottom_of_stack, r11 /* arg 3: SP of raise */ + Loadglobal r4, _caml_last_return_address, r11 /* arg 2: PC of raise */ + Loadglobal r5, _caml_bottom_of_stack, r11 /* arg 3: SP of raise */ Loadglobal r6, _caml_exception_pointer, r11 /* arg 4: SP of handler */ addi r1, r1, -(16*WORD) /* reserve stack space for C call */ bl _caml_stash_backtrace @@ -487,4 +485,4 @@ _caml_system__frametable: gdata L105 + 4 /* return address into callback */ .short -1 /* negative size count => use callback link */ .short 0 /* no roots here */ - .align X(2,3) + .align X(2,3) diff --git a/asmrun/roots.c b/asmrun/roots.c index 79a2422f24..93e7a655cd 100644 --- a/asmrun/roots.c +++ b/asmrun/roots.c @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: roots.c 12858 2012-08-10 14:45:51Z maranget $ */ - /* To walk the memory roots for garbage collection */ #include "finalise.h" @@ -369,5 +367,3 @@ uintnat caml_stack_usage (void) sz += (*caml_stack_usage_hook)(); return sz; } - - diff --git a/asmrun/signals_asm.c b/asmrun/signals_asm.c index 2a9fb7fa6f..9bc86cfdc5 100644 --- a/asmrun/signals_asm.c +++ b/asmrun/signals_asm.c @@ -11,14 +11,13 @@ /* */ /***********************************************************************/ -/* $Id: signals_asm.c 12858 2012-08-10 14:45:51Z maranget $ */ - /* Signal handling, code specific to the native-code compiler */ #if defined(TARGET_amd64) && defined (SYS_linux) #define _GNU_SOURCE #endif #include <signal.h> +#include <errno.h> #include <stdio.h> #include "fail.h" #include "memory.h" @@ -75,6 +74,9 @@ void caml_garbage_collection(void) DECLARE_SIGNAL_HANDLER(handle_signal) { + int saved_errno; + /* Save the value of errno (PR#5982). */ + saved_errno = errno; #if !defined(POSIX_SIGNALS) && !defined(BSD_SIGNALS) signal(sig, handle_signal); #endif @@ -92,6 +94,7 @@ DECLARE_SIGNAL_HANDLER(handle_signal) CONTEXT_YOUNG_LIMIT = (context_reg) caml_young_limit; #endif } + errno = saved_errno; } int caml_set_signal_action(int signo, int action) @@ -187,6 +190,10 @@ static char sig_alt_stack[SIGSTKSZ]; #define EXTRA_STACK 0x2000 #endif +#ifdef RETURN_AFTER_STACK_OVERFLOW +extern void caml_stack_overflow(void); +#endif + DECLARE_SIGNAL_HANDLER(segv_handler) { struct rlimit limit; @@ -206,19 +213,31 @@ DECLARE_SIGNAL_HANDLER(segv_handler) && Is_in_code_area(CONTEXT_PC) #endif ) { - /* Turn this into a Stack_overflow exception */ +#ifdef RETURN_AFTER_STACK_OVERFLOW + /* Tweak the PC part of the context so that on return from this + handler, we jump to the asm function [caml_stack_overflow] + (from $ARCH.S). */ +#ifdef CONTEXT_PC + CONTEXT_PC = (context_reg) &caml_stack_overflow; +#else +#error "CONTEXT_PC must be defined if RETURN_AFTER_STACK_OVERFLOW is" +#endif +#else + /* Raise a Stack_overflow exception straight from this signal handler */ #if defined(CONTEXT_YOUNG_PTR) && defined(CONTEXT_EXCEPTION_POINTER) caml_exception_pointer = (char *) CONTEXT_EXCEPTION_POINTER; caml_young_ptr = (char *) CONTEXT_YOUNG_PTR; #endif caml_raise_stack_overflow(); +#endif + } else { + /* Otherwise, deactivate our exception handler and return, + causing fatal signal to be generated at point of error. */ + act.sa_handler = SIG_DFL; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGSEGV, &act, NULL); } - /* Otherwise, deactivate our exception handler and return, - causing fatal signal to be generated at point of error. */ - act.sa_handler = SIG_DFL; - act.sa_flags = 0; - sigemptyset(&act.sa_mask); - sigaction(SIGSEGV, &act, NULL); } #endif diff --git a/asmrun/signals_osdep.h b/asmrun/signals_osdep.h index bbc39f3c6d..5e07b2c2df 100644 --- a/asmrun/signals_osdep.h +++ b/asmrun/signals_osdep.h @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: signals_osdep.h 12858 2012-08-10 14:45:51Z maranget $ */ - /* Processor- and OS-dependent signal interface */ /****************** AMD64, Linux */ @@ -30,7 +28,7 @@ #define CONTEXT_PC (context->uc_mcontext.gregs[REG_RIP]) #define CONTEXT_EXCEPTION_POINTER (context->uc_mcontext.gregs[REG_R14]) #define CONTEXT_YOUNG_PTR (context->uc_mcontext.gregs[REG_R15]) - #define CONTEXT_FAULTING_ADDRESS ((char *) context->uc_mcontext.gregs[REG_CR2]) + #define CONTEXT_FAULTING_ADDRESS ((char *)context->uc_mcontext.gregs[REG_CR2]) /****************** AMD64, MacOSX */ @@ -46,12 +44,14 @@ #include <sys/ucontext.h> #include <AvailabilityMacros.h> -#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #if !defined(MAC_OS_X_VERSION_10_5) \ + || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 #define CONTEXT_REG(r) r #else #define CONTEXT_REG(r) __##r #endif + typedef unsigned long long context_reg; #define CONTEXT_STATE (((ucontext_t *)context)->uc_mcontext->CONTEXT_REG(ss)) #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(rip)) #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.CONTEXT_REG(r14)) @@ -59,11 +59,25 @@ #define CONTEXT_SP (CONTEXT_STATE.CONTEXT_REG(rsp)) #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) -/****************** ARM, Linux */ + #define RETURN_AFTER_STACK_OVERFLOW -#elif defined(TARGET_arm) && (defined(SYS_linux_eabi) || defined(SYS_linux_eabihf)) +/****************** ARM, Linux */ - #include <sys/ucontext.h> +#elif defined(TARGET_arm) && (defined(SYS_linux_eabi) \ + || defined(SYS_linux_eabihf)) + + #if defined(__ANDROID__) + // The Android NDK does not have sys/ucontext.h yet. + typedef struct ucontext { + uint32_t uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + struct sigcontext uc_mcontext; + // Other fields omitted... + } ucontext_t; + #else + #include <sys/ucontext.h> + #endif #define DECLARE_SIGNAL_HANDLER(name) \ static void name(int sig, siginfo_t * info, ucontext_t * context) @@ -137,7 +151,8 @@ #include <sys/ucontext.h> #include <AvailabilityMacros.h> -#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #if !defined(MAC_OS_X_VERSION_10_5) \ + || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 #define CONTEXT_REG(r) r #else #define CONTEXT_REG(r) __##r @@ -188,7 +203,8 @@ #define CONTEXT_MCONTEXT (((ucontext_t *)context)->uc_mcontext) #endif -#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #if !defined(MAC_OS_X_VERSION_10_5) \ + || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 #define CONTEXT_REG(r) r #else #define CONTEXT_REG(r) __##r diff --git a/asmrun/sparc.S b/asmrun/sparc.S index 0847b3b919..7f24b4b42d 100644 --- a/asmrun/sparc.S +++ b/asmrun/sparc.S @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: sparc.S 12858 2012-08-10 14:45:51Z maranget $ */ - /* Asm part of the runtime system for the Sparc processor. */ /* Must be preprocessed by cpp */ @@ -351,10 +349,10 @@ caml_system__frametable: .half 0 /* no roots */ #ifdef SYS_solaris - .type caml_allocN, #function - .type caml_call_gc, #function + .type caml_allocN, #function + .type caml_call_gc, #function .type caml_c_call, #function .type caml_start_program, #function .type caml_raise_exception, #function - .type caml_system__frametable, #object + .type caml_system__frametable, #object #endif diff --git a/asmrun/stack.h b/asmrun/stack.h index 3f430c8f7b..57c87fa9c9 100644 --- a/asmrun/stack.h +++ b/asmrun/stack.h @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: stack.h 12858 2012-08-10 14:45:51Z maranget $ */ - /* Machine-dependent interface with the asm code */ #ifndef CAML_STACK_H @@ -37,7 +35,8 @@ #ifdef TARGET_power #define Saved_return_address(sp) *((intnat *)((sp) - SIZEOF_PTR)) #define Already_scanned(sp, retaddr) ((retaddr) & 1) -#define Mark_scanned(sp, retaddr) (*((intnat *)((sp) - SIZEOF_PTR)) = (retaddr) | 1) +#define Mark_scanned(sp, retaddr) \ + (*((intnat *)((sp) - SIZEOF_PTR)) = (retaddr) | 1) #define Mask_already_scanned(retaddr) ((retaddr) & ~1) #ifdef SYS_aix #define Trap_frame_size 32 diff --git a/asmrun/startup.c b/asmrun/startup.c index 4070579af5..1ccd4eca94 100644 --- a/asmrun/startup.c +++ b/asmrun/startup.c @@ -11,8 +11,6 @@ /* */ /***********************************************************************/ -/* $Id: startup.c 12959 2012-09-27 13:12:51Z maranget $ */ - /* Start-up code */ #include <stdio.h> @@ -33,7 +31,6 @@ #include "printexc.h" #include "stack.h" #include "sys.h" -#include "natdynlink.h" #ifdef HAS_UI #include "ui.h" #endif @@ -57,7 +54,7 @@ static void init_atoms(void) } if (caml_page_table_add(In_static_data, caml_atom_table, caml_atom_table + 256) != 0) - caml_fatal_error("Fatal error: not enough memory for the initial page table"); + caml_fatal_error("Fatal error: not enough memory for initial page table"); for (i = 0; caml_data_segments[i].begin != 0; i++) { /* PR#5509: we must include the zero word at end of data segment, @@ -65,7 +62,7 @@ static void init_atoms(void) if (caml_page_table_add(In_static_data, caml_data_segments[i].begin, caml_data_segments[i].end + sizeof(value)) != 0) - caml_fatal_error("Fatal error: not enough memory for the initial page table"); + caml_fatal_error("Fatal error: not enough memory for initial page table"); } caml_code_area_start = caml_code_segments[0].begin; @@ -150,6 +147,14 @@ extern value caml_start_program (void); extern void caml_init_ieee_floats (void); extern void caml_init_signals (void); +#ifdef _MSC_VER + +/* PR 4887: avoid crash box of windows runtime on some system calls */ +extern void caml_install_invalid_parameter_handler(); + +#endif + + void caml_main(char **argv) { char * exe_name; @@ -160,6 +165,9 @@ void caml_main(char **argv) char tos; caml_init_ieee_floats(); +#ifdef _MSC_VER + caml_install_invalid_parameter_handler(); +#endif caml_init_custom_operations(); #ifdef DEBUG caml_verb_gc = 63; |