Skip to content

Commit 211eb94

Browse files
committed
Fix rsp segfault, incorrect prologue
1 parent 83b2382 commit 211eb94

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

scripts/gen.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
sys.exit(1)
99

1010
with open(binary_path, "rb") as f:
11-
# remove prologue
12-
code = f.read()[4:]
11+
code = f.read()
12+
13+
# remove prologue
14+
i = 0
15+
for i, byte in enumerate(code):
16+
if byte not in range(0x50, 0x58) and byte != 0x41:
17+
break
18+
code = code[i:]
1319

1420
rem = len(code) % 8
1521
if rem:

src/codegen.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ static ALLOC: allocator::Allocator = allocator::Allocator;
99
#[no_mangle]
1010
#[link_section = ".init"]
1111
fn _start() -> ! {
12+
unsafe {
13+
asm!("and rsp, 0xFFFFFFFFFFFFFFF0", options(nomem));
14+
}
1215
solution::main();
1316
unsafe {
1417
asm!("syscall", in("rax") 231, in("rdi") 0, options(nomem, noreturn));

src/io.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,4 +728,3 @@ impl<const N: usize> Writer<N> {
728728
self.write(unsafe { MaybeUninit::slice_assume_init_ref(&buf[offset..]) });
729729
}
730730
}
731-

0 commit comments

Comments
 (0)