Skip to content

Commit 3b9ddf3

Browse files
committed
AArch64: Small fixes inspired by LLM Review
Signed-off-by: Paul Guyot <[email protected]>
1 parent 47ae139 commit 3b9ddf3

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

libs/jit/src/jit_aarch64_asm.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ add(Rd, Rn, Rm, {lsl, Amount}) when
124124
RdNum = reg_to_num(Rd),
125125
RnNum = reg_to_num(Rn),
126126
RmNum = reg_to_num(Rm),
127-
%% AArch64 ADD (immediate) encoding: 1001000100iiiiiiiiiiiinnnnndddddd
127+
%% AArch64 ADD (shifted register) encoding: 10001011000mmmmmiiiiiinnnnndddddd
128128
%% 0x8B000000 | Rm << 16 | Amount << 10 | Rn << 5 | Rd
129129
<<
130130
(16#8B000000 bor (RmNum bsl 16) bor ((Amount band 16#3F) bsl 10) bor (RnNum bsl 5) bor

libs/jit/src/jit_precompile.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ compile(Target, Dir, Path) ->
6969
Arch =
7070
case Target of
7171
"x86_64" -> ?JIT_ARCH_X86_64;
72-
"aarch64" -> ?JIT_ARCH_AARCH64
72+
"aarch64" -> ?JIT_ARCH_AARCH64;
73+
_ -> error({unsupported_target, Target})
7374
end,
7475

7576
Stream1 = jit_stream_binary:append(

src/platforms/generic_unix/lib/jit_stream_mmap.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "platform_defaultatoms.h"
3030
#include "term.h"
3131

32+
#include <errno.h>
3233
#include <pthread.h>
3334
#include <stdint.h>
3435
#include <stdio.h>
@@ -74,7 +75,7 @@ static term nif_jit_stream_mmap_new(Context *ctx, int argc, term argv[])
7475

7576
uint8_t *addr = (uint8_t *) mmap(0, size, prot, flags, fd, offset);
7677
if (addr == MAP_FAILED) {
77-
fprintf(stderr, "Could not allocate mmap for JIT");
78+
fprintf(stderr, "Could not allocate mmap for JIT: size=%zu, errno=%d\n", size, errno);
7879
RAISE_ERROR(BADARG_ATOM);
7980
}
8081

@@ -119,7 +120,9 @@ static term nif_jit_stream_mmap_append(Context *ctx, int argc, term argv[])
119120

120121
size_t binary_size = term_binary_size(argv[1]);
121122
const uint8_t *binary_data = (const uint8_t *) term_binary_data(argv[1]);
122-
assert(js_obj->stream_offset + binary_size < js_obj->stream_size);
123+
if (UNLIKELY(js_obj->stream_offset + binary_size > js_obj->stream_size)) {
124+
RAISE_ERROR(BADARG_ATOM);
125+
}
123126

124127
#if HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
125128
pthread_jit_write_protect_np(0);

src/platforms/generic_unix/lib/sys.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#ifndef AVM_NO_JIT
4949
#include "jit_stream_mmap.h"
50+
51+
#include <errno.h>
5052
#include <pthread.h>
5153
#include <sys/mman.h>
5254

@@ -818,7 +820,7 @@ ModuleNativeEntryPoint sys_map_native_code(const uint8_t *native_code, size_t si
818820
#if defined(__APPLE__) && defined(__arm64__)
819821
uint8_t *native_code_mmap = (uint8_t *) mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT, -1, 0);
820822
if (native_code_mmap == MAP_FAILED) {
821-
fprintf(stderr, "Could not allocate mmap for native code");
823+
fprintf(stderr, "Could not allocate mmap for native code: size=%zu, errno=%d\n", size, errno);
822824
return NULL;
823825
}
824826
pthread_jit_write_protect_np(0);

0 commit comments

Comments
 (0)