File tree Expand file tree Collapse file tree 5 files changed +53
-1
lines changed Expand file tree Collapse file tree 5 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -1032,6 +1032,14 @@ CFI_STARTPROC
1032
1032
CFI_ENDPROC
1033
1033
ENDFUNCTION(G(caml_ml_array_bound_error))
1034
1034
1035
+ FUNCTION(G(caml_ml_array_align_error))
1036
+ CFI_STARTPROC
1037
+ ENTER_FUNCTION
1038
+ LEA_VAR(caml_array_align_error_asm, %rax )
1039
+ jmp LBL(caml_c_call)
1040
+ CFI_ENDPROC
1041
+ ENDFUNCTION(G(caml_ml_array_align_error))
1042
+
1035
1043
FUNCTION(G(caml_assert_stack_invariants))
1036
1044
CFI_STARTPROC
1037
1045
/* CHECK_STACK_ALIGNMENT */
Original file line number Diff line number Diff line change 25
25
EXTRN caml_apply3: NEAR
26
26
EXTRN caml_program: NEAR
27
27
EXTRN caml_array_bound_error_asm: NEAR
28
- EXTRN caml_stash_backtrace: NEAR
28
+ EXTRN caml_array_align_error: NEAR
29
+ EXTRN caml_stash_backtrace: NEAR
29
30
30
31
INCLUDE domain_state64. inc
31
32
@@ -423,6 +424,12 @@ caml_ml_array_bound_error:
423
424
lea rax , caml_array_bound_error_asm
424
425
jmp caml_c_call
425
426
427
+ PUBLIC caml_ml_array_align_error
428
+ ALIGN 16
429
+ caml_ml_array_align_error:
430
+ lea rax , caml_array_align_error_asm
431
+ jmp caml_c_call
432
+
426
433
PUBLIC caml_system__code_end
427
434
caml_system__code_end:
428
435
Original file line number Diff line number Diff line change @@ -145,6 +145,10 @@ CAMLnoreturn_start
145
145
CAMLextern void caml_array_bound_error (void )
146
146
CAMLnoreturn_end ;
147
147
148
+ CAMLnoreturn_start
149
+ CAMLextern void caml_array_align_error (void )
150
+ CAMLnoreturn_end ;
151
+
148
152
CAMLnoreturn_start
149
153
CAMLextern void caml_raise_sys_blocked_io (void )
150
154
CAMLnoreturn_end ;
Original file line number Diff line number Diff line change @@ -163,6 +163,11 @@ CAMLexport void caml_array_bound_error(void)
163
163
caml_invalid_argument ("index out of bounds" );
164
164
}
165
165
166
+ CAMLexport void caml_array_align_error (void )
167
+ {
168
+ caml_invalid_argument ("address was misaligned" );
169
+ }
170
+
166
171
CAMLexport void caml_raise_out_of_memory (void )
167
172
{
168
173
check_global_data ("Out_of_memory" );
Original file line number Diff line number Diff line change @@ -222,6 +222,34 @@ void caml_array_bound_error_asm(void)
222
222
caml_raise_exception (Caml_state , array_bound_exn ());
223
223
}
224
224
225
+ static value array_align_exn (void )
226
+ {
227
+ static atomic_uintnat exn_cache = ATOMIC_UINTNAT_INIT (0 );
228
+ const value * exn = (const value * )atomic_load_acquire (& exn_cache );
229
+ if (!exn ) {
230
+ exn = caml_named_value ("Pervasives.array_align_error" );
231
+ if (!exn ) {
232
+ fprintf (stderr , "Fatal error: exception "
233
+ "Invalid_argument(\"address was misaligned\")\n" );
234
+ exit (2 );
235
+ }
236
+ atomic_store_release (& exn_cache , (uintnat )exn );
237
+ }
238
+ return * exn ;
239
+ }
240
+
241
+ void caml_array_align_error (void )
242
+ {
243
+ caml_raise (array_align_exn ());
244
+ }
245
+
246
+ void caml_array_align_error_asm (void )
247
+ {
248
+ /* This exception is raised directly from ocamlopt-compiled OCaml,
249
+ not C, so we jump directly to the OCaml handler (and avoid GC) */
250
+ caml_raise_exception (Caml_state , array_align_exn ());
251
+ }
252
+
225
253
int caml_is_special_exception (value exn ) {
226
254
return exn == (value ) caml_exn_Match_failure
227
255
|| exn == (value ) caml_exn_Assert_failure
You can’t perform that action at this time.
0 commit comments