@@ -64,7 +64,8 @@ static void module_parse_line_table(Module *mod, const uint8_t *data, size_t len
64
64
65
65
static enum ModuleLoadResult module_populate_atoms_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
66
66
{
67
- int atoms_count = READ_32_ALIGNED (table_data + 8 );
67
+ int atoms_count = READ_32_UNALIGNED (table_data + 8 );
68
+
68
69
const char * current_atom = (const char * ) table_data + 12 ;
69
70
70
71
this_module -> local_atoms_to_global_table = calloc (atoms_count + 1 , sizeof (int ));
@@ -85,7 +86,7 @@ static enum ModuleLoadResult module_populate_atoms_table(Module *this_module, ui
85
86
86
87
static enum ModuleLoadResult module_build_imported_functions_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
87
88
{
88
- int functions_count = READ_32_ALIGNED (table_data + 8 );
89
+ int functions_count = READ_32_UNALIGNED (table_data + 8 );
89
90
90
91
this_module -> imported_funcs = calloc (functions_count , sizeof (struct ExportedFunction * ));
91
92
if (IS_NULL_PTR (this_module -> imported_funcs )) {
@@ -94,11 +95,11 @@ static enum ModuleLoadResult module_build_imported_functions_table(Module *this_
94
95
}
95
96
96
97
for (int i = 0 ; i < functions_count ; i ++ ) {
97
- int local_module_atom_index = READ_32_ALIGNED (table_data + i * 12 + 12 );
98
- int local_function_atom_index = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
98
+ int local_module_atom_index = READ_32_UNALIGNED (table_data + i * 12 + 12 );
99
+ int local_function_atom_index = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
99
100
AtomString module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
100
101
AtomString function_atom = module_get_atom_string_by_id (this_module , local_function_atom_index , glb );
101
- uint32_t arity = READ_32_ALIGNED (table_data + i * 12 + 8 + 12 );
102
+ uint32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 8 + 12 );
102
103
103
104
const struct ExportedFunction * bif = bif_registry_get_handler (module_atom , function_atom , arity );
104
105
@@ -130,13 +131,13 @@ static enum ModuleLoadResult module_build_imported_functions_table(Module *this_
130
131
void module_get_imported_function_module_and_name (const Module * this_module , int index , AtomString * module_atom , AtomString * function_atom , GlobalContext * glb )
131
132
{
132
133
const uint8_t * table_data = (const uint8_t * ) this_module -> import_table ;
133
- int functions_count = READ_32_ALIGNED (table_data + 8 );
134
+ int functions_count = READ_32_UNALIGNED (table_data + 8 );
134
135
135
136
if (UNLIKELY (index > functions_count )) {
136
137
AVM_ABORT ();
137
138
}
138
- int local_module_atom_index = READ_32_ALIGNED (table_data + index * 12 + 12 );
139
- int local_function_atom_index = READ_32_ALIGNED (table_data + index * 12 + 4 + 12 );
139
+ int local_module_atom_index = READ_32_UNALIGNED (table_data + index * 12 + 12 );
140
+ int local_function_atom_index = READ_32_UNALIGNED (table_data + index * 12 + 4 + 12 );
140
141
* module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
141
142
* function_atom = module_get_atom_string_by_id (this_module , local_function_atom_index , glb );
142
143
}
@@ -146,11 +147,11 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
146
147
{
147
148
int best_label = -1 ;
148
149
const uint8_t * export_table_data = (const uint8_t * ) this_module -> export_table ;
149
- int exports_count = READ_32_ALIGNED (export_table_data + 8 );
150
+ int exports_count = READ_32_UNALIGNED (export_table_data + 8 );
150
151
for (int export_index = exports_count - 1 ; export_index >= 0 ; export_index -- ) {
151
- int fun_atom_index = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 12 );
152
- int fun_arity = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 4 + 12 );
153
- int fun_label = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 8 + 12 );
152
+ int fun_atom_index = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 12 );
153
+ int fun_arity = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 4 + 12 );
154
+ int fun_label = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 8 + 12 );
154
155
if (fun_label <= label && best_label < fun_label ) {
155
156
best_label = fun_label ;
156
157
* arity = fun_arity ;
@@ -159,11 +160,11 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
159
160
}
160
161
161
162
const uint8_t * local_table_data = (const uint8_t * ) this_module -> local_table ;
162
- int locals_count = READ_32_ALIGNED (local_table_data + 8 );
163
+ int locals_count = READ_32_UNALIGNED (local_table_data + 8 );
163
164
for (int local_index = locals_count - 1 ; local_index >= 0 ; local_index -- ) {
164
- int fun_atom_index = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 12 );
165
- int fun_arity = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 4 + 12 );
166
- int fun_label = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 8 + 12 );
165
+ int fun_atom_index = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 12 );
166
+ int fun_arity = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 4 + 12 );
167
+ int fun_label = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 8 + 12 );
167
168
if (fun_label <= label && best_label < fun_label ) {
168
169
best_label = fun_label ;
169
170
* arity = fun_arity ;
@@ -180,7 +181,7 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
180
181
size_t module_get_exported_functions_count (Module * this_module )
181
182
{
182
183
const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
183
- size_t functions_count = READ_32_ALIGNED (table_data + 8 );
184
+ size_t functions_count = READ_32_UNALIGNED (table_data + 8 );
184
185
return functions_count ;
185
186
}
186
187
@@ -190,10 +191,10 @@ uint32_t module_search_exported_function(Module *this_module, AtomString func_na
190
191
191
192
const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
192
193
for (unsigned int i = 0 ; i < functions_count ; i ++ ) {
193
- AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_ALIGNED (table_data + i * 12 + 12 ), glb );
194
- int32_t arity = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
194
+ AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_UNALIGNED (table_data + i * 12 + 12 ), glb );
195
+ int32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
195
196
if ((func_arity == arity ) && atom_are_equals (func_name , function_atom )) {
196
- uint32_t label = READ_32_ALIGNED (table_data + i * 12 + 8 + 12 );
197
+ uint32_t label = READ_32_UNALIGNED (table_data + i * 12 + 8 + 12 );
197
198
return label ;
198
199
}
199
200
}
@@ -208,8 +209,8 @@ term module_get_exported_functions(Module *this_module, Heap *heap, GlobalContex
208
209
209
210
const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
210
211
for (unsigned int i = 0 ; i < functions_count ; i ++ ) {
211
- AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_ALIGNED (table_data + i * 12 + 12 ), glb );
212
- int32_t arity = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
212
+ AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_UNALIGNED (table_data + i * 12 + 12 ), glb );
213
+ int32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
213
214
term function_tuple = term_alloc_tuple (2 , heap );
214
215
term_put_tuple_element (function_tuple , 0 , globalcontext_existing_term_from_atom_string (glb , function_atom ));
215
216
term_put_tuple_element (function_tuple , 1 , term_from_int (arity ));
@@ -327,7 +328,7 @@ COLD_FUNC void module_destroy(Module *module)
327
328
#ifdef WITH_ZLIB
328
329
static void * module_uncompress_literals (const uint8_t * litT , int size )
329
330
{
330
- unsigned int required_buf_size = READ_32_ALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
331
+ unsigned int required_buf_size = READ_32_UNALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
331
332
332
333
uint8_t * outBuf = malloc (required_buf_size );
333
334
if (IS_NULL_PTR (outBuf )) {
@@ -362,7 +363,7 @@ static void *module_uncompress_literals(const uint8_t *litT, int size)
362
363
363
364
static struct LiteralEntry * module_build_literals_table (const void * literalsBuf )
364
365
{
365
- uint32_t terms_count = READ_32_ALIGNED (literalsBuf );
366
+ uint32_t terms_count = READ_32_UNALIGNED (literalsBuf );
366
367
367
368
const uint8_t * pos = (const uint8_t * ) literalsBuf + sizeof (uint32_t );
368
369
0 commit comments