diff options
author | Björn Gustavsson <[email protected]> | 2016-04-29 15:50:19 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-05-04 10:21:30 +0200 |
commit | f8e4ac533d388b39d5980092e5dd7a9d4ffee60b (patch) | |
tree | 87552c7a77d2dcefdf30dbb65bdfee0041b13628 /lib/kernel/test | |
parent | eb7c5e3fa1f2d2bac21c4714b3a627a5517f797d (diff) | |
download | otp-f8e4ac533d388b39d5980092e5dd7a9d4ffee60b.tar.gz otp-f8e4ac533d388b39d5980092e5dd7a9d4ffee60b.tar.bz2 otp-f8e4ac533d388b39d5980092e5dd7a9d4ffee60b.zip |
Avoid deadlock when an on_load function makes an external call to the module itself
Diffstat (limited to 'lib/kernel/test')
-rw-r--r-- | lib/kernel/test/code_SUITE.erl | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl index 547881f3b2..e238eea2de 100644 --- a/lib/kernel/test/code_SUITE.erl +++ b/lib/kernel/test/code_SUITE.erl @@ -35,7 +35,7 @@ purge_stacktrace/1, mult_lib_roots/1, bad_erl_libs/1, code_archive/1, code_archive2/1, on_load/1, on_load_binary/1, on_load_embedded/1, on_load_errors/1, on_load_update/1, - on_load_purge/1, + on_load_purge/1, on_load_self_call/1, big_boot_embedded/1, native_early_modules/1, get_mode/1, normalized_paths/1]). @@ -65,7 +65,7 @@ all() -> purge_stacktrace, mult_lib_roots, bad_erl_libs, code_archive, code_archive2, on_load, on_load_binary, on_load_embedded, on_load_errors, on_load_update, - on_load_purge, + on_load_purge, on_load_self_call, big_boot_embedded, native_early_modules, get_mode, normalized_paths]. groups() -> @@ -1523,6 +1523,32 @@ on_load_purge(_Config) -> end end. +on_load_self_call(_Config) -> + Mod = ?FUNCTION_NAME, + register(Mod, self()), + Tree = ?Q(["-module('@Mod@').\n", + "-export([ext/0]).\n", + "-on_load(f/0).\n", + "f() ->\n", + " '@Mod@' ! (catch '@Mod@':ext()),\n", + " ok.\n", + "ext() -> good_work.\n"]), + merl:print(Tree), + {ok,Mod,Code} = merl:compile(Tree), + + {'EXIT',{undef,_}} = on_load_do_load(Mod, Code), + good_work = on_load_do_load(Mod, Code), + + ok. + +on_load_do_load(Mod, Code) -> + spawn(fun() -> + {module,Mod} = code:load_binary(Mod, "", Code) + end), + receive + Any -> Any + end. + %% Test that the native code of early loaded modules is loaded. native_early_modules(Config) when is_list(Config) -> case erlang:system_info(hipe_architecture) of |