diff options
author | John Högberg <john@erlang.org> | 2020-06-12 11:11:17 +0200 |
---|---|---|
committer | Lukas Larsson <lukas@erlang.org> | 2020-09-21 16:40:30 +0200 |
commit | 8c3b8f05798ba6feca3804a6b54c328e75db89d7 (patch) | |
tree | 315ae8fa0c9ad3608af066596fcb248eef858da3 /erts/emulator | |
parent | e5cd42063d7d3e65ffd4efe0c301171df4400b9f (diff) | |
download | erlang-8c3b8f05798ba6feca3804a6b54c328e75db89d7.tar.gz |
erts: Decompress module binaries before passing them to BIFs
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/beam/beam_bif_load.c | 29 | ||||
-rw-r--r-- | erts/emulator/beam/beam_file.c | 24 | ||||
-rw-r--r-- | erts/emulator/beam/beam_file.h | 3 | ||||
-rw-r--r-- | erts/emulator/beam/bif.tab | 10 |
4 files changed, 31 insertions, 35 deletions
diff --git a/erts/emulator/beam/beam_bif_load.c b/erts/emulator/beam/beam_bif_load.c index 76c25c4f2a..9dadc07c36 100644 --- a/erts/emulator/beam/beam_bif_load.c +++ b/erts/emulator/beam/beam_bif_load.c @@ -160,7 +160,7 @@ static int read_iff_list(Eterm iff_list, Uint *res) { } BIF_RETTYPE -code_get_chunk_2(BIF_ALIST_2) +erts_internal_beamfile_chunk_2(BIF_ALIST_2) { Uint search_iff; IFF_Chunk chunk; @@ -185,10 +185,27 @@ code_get_chunk_2(BIF_ALIST_2) if (iff_init(start, binary_size(Bin), &iff)) { if (iff_read_chunk(&iff, search_iff, &chunk) && chunk.size > 0) { - res = new_binary(BIF_P, (byte*)chunk.data, chunk.size); - } + Sint offset, bitoffs, bitsize; + Eterm real_bin; + + ERTS_GET_REAL_BIN(Bin, real_bin, offset, bitoffs, bitsize); + + if (bitoffs) { + res = new_binary(BIF_P, (byte*)chunk.data, chunk.size); + } else { + ErlSubBin *sb = (ErlSubBin*)HAlloc(BIF_P, ERL_SUB_BIN_SIZE); - iff_dtor(&iff); + sb->thing_word = HEADER_SUB_BIN; + sb->orig = real_bin; + sb->size = chunk.size; + sb->bitsize = 0; + sb->bitoffs = 0; + sb->offs = offset + (chunk.data - start); + sb->is_writable = 0; + + res = make_binary(sb); + } + } } erts_free_aligned_binary_bytes(temp_alloc); @@ -198,7 +215,7 @@ code_get_chunk_2(BIF_ALIST_2) /* Calculate the MD5 for a module. */ BIF_RETTYPE -code_module_md5_1(BIF_ALIST_1) +erts_internal_beamfile_module_md5_1(BIF_ALIST_1) { byte* temp_alloc; byte* bytes; @@ -280,7 +297,7 @@ BIF_RETTYPE code_make_stub_module_3(BIF_ALIST_3) } BIF_RETTYPE -prepare_loading_2(BIF_ALIST_2) +erts_internal_prepare_loading_2(BIF_ALIST_2) { byte* temp_alloc = NULL; byte* code; diff --git a/erts/emulator/beam/beam_file.c b/erts/emulator/beam/beam_file.c index 2e408b78e2..cbf9e23f23 100644 --- a/erts/emulator/beam/beam_file.c +++ b/erts/emulator/beam/beam_file.c @@ -669,8 +669,6 @@ static int parse_code_chunk(BeamFile *beam, IFF_Chunk *chunk) { return 1; } -ErlDrvBinary *erts_gzinflate_buffer(char*, int); - static int read_beam_chunks(const IFF_File *file, int count, const Uint *ids, IFF_Chunk *chunks) { @@ -960,8 +958,6 @@ void beamfile_free(BeamFile *beam) { if (beam->dynamic_literals.entries) { beamfile_literal_dtor(&beam->dynamic_literals); } - - iff_dtor(&beam->iff); } Sint beamfile_add_literal(BeamFile *beam, Eterm term) { @@ -1085,18 +1081,7 @@ int iff_init(const byte *data, size_t size, IFF_File *iff) { beamreader_init(data, size, &reader); LoadAssert(beamreader_read_i32(&reader, &form_id)); - - /* Decompress the module if necessary. */ - if (form_id != MakeIffId('F', 'O', 'R', '1')) { - ErlDrvBinary *bin = erts_gzinflate_buffer((char*)data, size); - - LoadAssert(bin); - iff->decompressed_data = bin; - - beamreader_init((const byte*)bin->orig_bytes, bin->orig_size, &reader); - LoadAssert(beamreader_read_i32(&reader, &form_id)); - LoadAssert(form_id == MakeIffId('F', 'O', 'R', '1')); - } + LoadAssert(form_id == MakeIffId('F', 'O', 'R', '1')); LoadAssert(beamreader_read_i32(&reader, &form_size)); LoadAssert(beamreader_read_bytes(&reader, form_size, &real_data)); @@ -1107,13 +1092,6 @@ int iff_init(const byte *data, size_t size, IFF_File *iff) { return 1; } -void iff_dtor(IFF_File *iff) { - if (iff->decompressed_data) { - driver_free_binary(iff->decompressed_data); - iff->decompressed_data = NULL; - } -} - int iff_read_chunk(IFF_File *iff, Uint id, IFF_Chunk *chunk) { return read_beam_chunks(iff, 1, &id, chunk); diff --git a/erts/emulator/beam/beam_file.h b/erts/emulator/beam/beam_file.h index 3c49db41ea..fe68447b8e 100644 --- a/erts/emulator/beam/beam_file.h +++ b/erts/emulator/beam/beam_file.h @@ -32,8 +32,6 @@ (((Uint) (a) << 24) | ((Uint) (b) << 16) | ((Uint) (c) << 8) | (Uint) (d)) typedef struct { - struct erl_drv_binary *decompressed_data; - Sint32 form_id; Sint32 size; @@ -54,7 +52,6 @@ int iff_init(const byte *data, size_t size, IFF_File *iff); * * @return 1 on success, 0 on failure */ int iff_read_chunk(IFF_File *iff, Uint id, IFF_Chunk *chunk); -void iff_dtor(IFF_File *iff); typedef struct { /* The encoding that was used to create this table. This is only used for diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab index c55189f8a7..d1920bd072 100644 --- a/erts/emulator/beam/bif.tab +++ b/erts/emulator/beam/bif.tab @@ -462,8 +462,6 @@ bif erts_debug:lcnt_clear/0 # New Bifs in R8. # -bif code:get_chunk/2 -bif code:module_md5/1 bif code:make_stub_module/3 bif code:is_module_native/1 @@ -613,7 +611,6 @@ bif erlang:dt_append_vm_tag_data/1 # # New in R16B. # -bif erlang:prepare_loading/2 bif erlang:finish_loading/1 bif erlang:insert_element/3 bif erlang:delete_element/2 @@ -769,3 +766,10 @@ bif erts_internal:abort_pending_connection/2 # bif erts_internal:get_creation/0 + +# +# New in 24 +# +bif erts_internal:prepare_loading/2 +bif erts_internal:beamfile_chunk/2 +bif erts_internal:beamfile_module_md5/1 |