From 91fb6636f95f882b75170fb77c412ccc4a9b75f4 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 20 Apr 2015 15:52:27 +0200 Subject: erts,hipe: Fix bug in binary matching of writable binary Seen symptom: Hipe compiled code with <> = Bin does sometimes not match even though Bin contains a valid utf8 character. There might be other possible binary matching symptoms, as the problem is not utf8 specific. Problem: A writable binary was not "emasculated" when the matching started (as it should) by the hipe compiled code. Fix: Add a new primop emasculate_binary(Bin) that is called when a matchstate is created. ToDo: There are probably room for optimization. For example only call emasculate_binary if ProcBin.flags is set. --- erts/emulator/hipe/hipe_bif0.c | 8 ++++++++ erts/emulator/hipe/hipe_bif0.tab | 1 + erts/emulator/hipe/hipe_bif_list.m4 | 2 ++ erts/emulator/hipe/hipe_native_bif.h | 3 +++ erts/emulator/hipe/hipe_primops.h | 1 + 5 files changed, 15 insertions(+) (limited to 'erts/emulator/hipe') diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c index 8af174170d..de2ea0ecde 100644 --- a/erts/emulator/hipe/hipe_bif0.c +++ b/erts/emulator/hipe/hipe_bif0.c @@ -1028,6 +1028,14 @@ void hipe_emulate_fpe(Process* p) } #endif +void hipe_emasculate_binary(Eterm bin) +{ + ProcBin* pb = (ProcBin *) boxed_val(bin); + if (pb->thing_word == HEADER_PROC_BIN && pb->flags != 0) { + erts_emasculate_writable_binary(pb); + } +} + #if 0 /* XXX: unused */ /* * At least parts of this should be inlined in native code. diff --git a/erts/emulator/hipe/hipe_bif0.tab b/erts/emulator/hipe/hipe_bif0.tab index 2514b1c3a5..620749a511 100644 --- a/erts/emulator/hipe/hipe_bif0.tab +++ b/erts/emulator/hipe/hipe_bif0.tab @@ -142,4 +142,5 @@ atom bs_get_utf16 atom bs_validate_unicode atom bs_validate_unicode_retract atom emulate_fpe +atom emasculate_binary diff --git a/erts/emulator/hipe/hipe_bif_list.m4 b/erts/emulator/hipe/hipe_bif_list.m4 index 5f92b6bac4..58b20c7752 100644 --- a/erts/emulator/hipe/hipe_bif_list.m4 +++ b/erts/emulator/hipe/hipe_bif_list.m4 @@ -250,6 +250,8 @@ gc_bif_interface_0(nbif_check_get_msg, hipe_check_get_msg) nocons_nofail_primop_interface_0(nbif_emulate_fpe, hipe_emulate_fpe) #endif +noproc_primop_interface_1(nbif_emasculate_binary, hipe_emasculate_binary) + /* * SMP-specific stuff */ diff --git a/erts/emulator/hipe/hipe_native_bif.h b/erts/emulator/hipe/hipe_native_bif.h index 3f460a5a5c..574e20e2e4 100644 --- a/erts/emulator/hipe/hipe_native_bif.h +++ b/erts/emulator/hipe/hipe_native_bif.h @@ -98,6 +98,9 @@ AEXTERN(void,nbif_emulate_fpe,(Process*)); void hipe_emulate_fpe(Process*); #endif +AEXTERN(void,nbif_emasculate_binary,(Eterm)); +void hipe_emasculate_binary(Eterm); + /* * Stuff that is different in SMP and non-SMP. */ diff --git a/erts/emulator/hipe/hipe_primops.h b/erts/emulator/hipe/hipe_primops.h index 52b4681cfe..236f6d0a29 100644 --- a/erts/emulator/hipe/hipe_primops.h +++ b/erts/emulator/hipe/hipe_primops.h @@ -80,6 +80,7 @@ PRIMOP_LIST(am_fclearerror_error, &nbif_fclearerror_error) #ifdef NO_FPE_SIGNALS PRIMOP_LIST(am_emulate_fpe, &nbif_emulate_fpe) #endif +PRIMOP_LIST(am_emasculate_binary, &nbif_emasculate_binary) PRIMOP_LIST(am_debug_native_called, &nbif_hipe_bifs_debug_native_called) #if defined(__sparc__) -- cgit v1.2.3 From e40aab7e9fb9d622e9879efa43af2ce30b287450 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 21 Apr 2015 15:33:32 +0200 Subject: erts,hipe: Optimize away calls to emasculate_binary Only call emasculate_binary if ProcBin.flags is set, which means it's a writable binary. --- erts/emulator/hipe/hipe_bif0.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'erts/emulator/hipe') diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c index de2ea0ecde..bb61e71b14 100644 --- a/erts/emulator/hipe/hipe_bif0.c +++ b/erts/emulator/hipe/hipe_bif0.c @@ -1031,9 +1031,9 @@ void hipe_emulate_fpe(Process* p) void hipe_emasculate_binary(Eterm bin) { ProcBin* pb = (ProcBin *) boxed_val(bin); - if (pb->thing_word == HEADER_PROC_BIN && pb->flags != 0) { - erts_emasculate_writable_binary(pb); - } + ASSERT(pb->thing_word == HEADER_PROC_BIN); + ASSERT(pb->flags != 0); + erts_emasculate_writable_binary(pb); } #if 0 /* XXX: unused */ -- cgit v1.2.3