@@ -65,7 +65,7 @@ static void module_parse_line_table(Module *mod, const uint8_t *data, size_t len
65
65
66
66
static enum ModuleLoadResult module_populate_atoms_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
67
67
{
68
- int atoms_count = READ_32_ALIGNED (table_data + 8 );
68
+ int atoms_count = READ_32_UNALIGNED (table_data + 8 );
69
69
70
70
enum EnsureAtomsOpt ensure_opts = EnsureAtomsNoOpts ;
71
71
if (atoms_count < 0 ) {
@@ -95,7 +95,7 @@ static enum ModuleLoadResult module_populate_atoms_table(Module *this_module, ui
95
95
96
96
static enum ModuleLoadResult module_build_imported_functions_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
97
97
{
98
- int functions_count = READ_32_ALIGNED (table_data + 8 );
98
+ int functions_count = READ_32_UNALIGNED (table_data + 8 );
99
99
100
100
this_module -> imported_funcs = calloc (functions_count , sizeof (struct ExportedFunction * ));
101
101
if (IS_NULL_PTR (this_module -> imported_funcs )) {
@@ -104,11 +104,11 @@ static enum ModuleLoadResult module_build_imported_functions_table(Module *this_
104
104
}
105
105
106
106
for (int i = 0 ; i < functions_count ; i ++ ) {
107
- int local_module_atom_index = READ_32_ALIGNED (table_data + i * 12 + 12 );
108
- int local_function_atom_index = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
107
+ int local_module_atom_index = READ_32_UNALIGNED (table_data + i * 12 + 12 );
108
+ int local_function_atom_index = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
109
109
AtomString module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
110
110
AtomString function_atom = module_get_atom_string_by_id (this_module , local_function_atom_index , glb );
111
- uint32_t arity = READ_32_ALIGNED (table_data + i * 12 + 8 + 12 );
111
+ uint32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 8 + 12 );
112
112
113
113
const struct ExportedFunction * bif = bif_registry_get_handler (module_atom , function_atom , arity );
114
114
@@ -140,13 +140,13 @@ static enum ModuleLoadResult module_build_imported_functions_table(Module *this_
140
140
void module_get_imported_function_module_and_name (const Module * this_module , int index , AtomString * module_atom , AtomString * function_atom , GlobalContext * glb )
141
141
{
142
142
const uint8_t * table_data = (const uint8_t * ) this_module -> import_table ;
143
- int functions_count = READ_32_ALIGNED (table_data + 8 );
143
+ int functions_count = READ_32_UNALIGNED (table_data + 8 );
144
144
145
145
if (UNLIKELY (index > functions_count )) {
146
146
AVM_ABORT ();
147
147
}
148
- int local_module_atom_index = READ_32_ALIGNED (table_data + index * 12 + 12 );
149
- int local_function_atom_index = READ_32_ALIGNED (table_data + index * 12 + 4 + 12 );
148
+ int local_module_atom_index = READ_32_UNALIGNED (table_data + index * 12 + 12 );
149
+ int local_function_atom_index = READ_32_UNALIGNED (table_data + index * 12 + 4 + 12 );
150
150
* module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
151
151
* function_atom = module_get_atom_string_by_id (this_module , local_function_atom_index , glb );
152
152
}
@@ -156,11 +156,11 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
156
156
{
157
157
int best_label = -1 ;
158
158
const uint8_t * export_table_data = (const uint8_t * ) this_module -> export_table ;
159
- int exports_count = READ_32_ALIGNED (export_table_data + 8 );
159
+ int exports_count = READ_32_UNALIGNED (export_table_data + 8 );
160
160
for (int export_index = exports_count - 1 ; export_index >= 0 ; export_index -- ) {
161
- int fun_atom_index = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 12 );
162
- int fun_arity = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 4 + 12 );
163
- int fun_label = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 8 + 12 );
161
+ int fun_atom_index = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 12 );
162
+ int fun_arity = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 4 + 12 );
163
+ int fun_label = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 8 + 12 );
164
164
if (fun_label <= label && best_label < fun_label ) {
165
165
best_label = fun_label ;
166
166
* arity = fun_arity ;
@@ -169,11 +169,11 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
169
169
}
170
170
171
171
const uint8_t * local_table_data = (const uint8_t * ) this_module -> local_table ;
172
- int locals_count = READ_32_ALIGNED (local_table_data + 8 );
172
+ int locals_count = READ_32_UNALIGNED (local_table_data + 8 );
173
173
for (int local_index = locals_count - 1 ; local_index >= 0 ; local_index -- ) {
174
- int fun_atom_index = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 12 );
175
- int fun_arity = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 4 + 12 );
176
- int fun_label = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 8 + 12 );
174
+ int fun_atom_index = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 12 );
175
+ int fun_arity = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 4 + 12 );
176
+ int fun_label = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 8 + 12 );
177
177
if (fun_label <= label && best_label < fun_label ) {
178
178
best_label = fun_label ;
179
179
* arity = fun_arity ;
@@ -190,7 +190,7 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
190
190
size_t module_get_exported_functions_count (Module * this_module )
191
191
{
192
192
const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
193
- size_t functions_count = READ_32_ALIGNED (table_data + 8 );
193
+ size_t functions_count = READ_32_UNALIGNED (table_data + 8 );
194
194
return functions_count ;
195
195
}
196
196
@@ -200,10 +200,10 @@ uint32_t module_search_exported_function(Module *this_module, AtomString func_na
200
200
201
201
const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
202
202
for (unsigned int i = 0 ; i < functions_count ; i ++ ) {
203
- AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_ALIGNED (table_data + i * 12 + 12 ), glb );
204
- int32_t arity = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
203
+ AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_UNALIGNED (table_data + i * 12 + 12 ), glb );
204
+ int32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
205
205
if ((func_arity == arity ) && atom_are_equals (func_name , function_atom )) {
206
- uint32_t label = READ_32_ALIGNED (table_data + i * 12 + 8 + 12 );
206
+ uint32_t label = READ_32_UNALIGNED (table_data + i * 12 + 8 + 12 );
207
207
return label ;
208
208
}
209
209
}
@@ -218,8 +218,8 @@ term module_get_exported_functions(Module *this_module, Heap *heap, GlobalContex
218
218
219
219
const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
220
220
for (unsigned int i = 0 ; i < functions_count ; i ++ ) {
221
- AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_ALIGNED (table_data + i * 12 + 12 ), glb );
222
- int32_t arity = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
221
+ AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_UNALIGNED (table_data + i * 12 + 12 ), glb );
222
+ int32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
223
223
term function_tuple = term_alloc_tuple (2 , heap );
224
224
term_put_tuple_element (function_tuple , 0 , globalcontext_existing_term_from_atom_string (glb , function_atom ));
225
225
term_put_tuple_element (function_tuple , 1 , term_from_int (arity ));
@@ -349,7 +349,7 @@ static bool module_are_literals_compressed(const uint8_t *litT)
349
349
#ifdef WITH_ZLIB
350
350
static void * module_uncompress_literals (const uint8_t * litT , int size )
351
351
{
352
- unsigned int required_buf_size = READ_32_ALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
352
+ unsigned int required_buf_size = READ_32_UNALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
353
353
354
354
uint8_t * outBuf = malloc (required_buf_size );
355
355
if (IS_NULL_PTR (outBuf )) {
@@ -384,7 +384,7 @@ static void *module_uncompress_literals(const uint8_t *litT, int size)
384
384
385
385
static struct LiteralEntry * module_build_literals_table (const void * literalsBuf )
386
386
{
387
- uint32_t terms_count = READ_32_ALIGNED (literalsBuf );
387
+ uint32_t terms_count = READ_32_UNALIGNED (literalsBuf );
388
388
389
389
const uint8_t * pos = (const uint8_t * ) literalsBuf + sizeof (uint32_t );
390
390
0 commit comments