Skip to content

Commit ca41f0a

Browse files
authored
Add trap instructions after noreturn syscalls. (bytecodealliance#1444)
As discussed in bytecodealliance#1433, add trap instructions after noreturn syscalls.
1 parent cb01fbe commit ca41f0a

File tree

13 files changed

+15
-1
lines changed

13 files changed

+15
-1
lines changed

src/backend/linux_raw/arch/aarch64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
5151
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
5252
asm!(
5353
"svc 0",
54+
"brk #0x1",
5455
in("x8") nr.to_asm(),
5556
in("x0") a0.to_asm(),
5657
options(nostack, noreturn)

src/backend/linux_raw/arch/arm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
4848
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
4949
asm!(
5050
"svc 0",
51+
"udf #16",
5152
in("r7") nr.to_asm(),
5253
in("r0") a0.to_asm(),
5354
options(nostack, noreturn)

src/backend/linux_raw/arch/mips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
101101
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
102102
asm!(
103103
"syscall",
104+
"teq $0,$0",
104105
in("$2" /*$v0*/) nr.to_asm(),
105106
in("$4" /*$a0*/) a0.to_asm(),
106107
options(nostack, noreturn)

src/backend/linux_raw/arch/mips32r6.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
101101
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
102102
asm!(
103103
"syscall",
104+
"teq $0,$0",
104105
in("$2" /*$v0*/) nr.to_asm(),
105106
in("$4" /*$a0*/) a0.to_asm(),
106107
options(nostack, noreturn)

src/backend/linux_raw/arch/mips64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
101101
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
102102
asm!(
103103
"syscall",
104+
"teq $0,$0",
104105
in("$2" /*$v0*/) nr.to_asm(),
105106
in("$4" /*$a0*/) a0.to_asm(),
106107
options(nostack, noreturn)

src/backend/linux_raw/arch/mips64r6.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
105105
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
106106
asm!(
107107
"syscall",
108+
"teq $0,$0",
108109
in("$2" /*$v0*/) nr.to_asm(),
109110
in("$4" /*$a0*/) a0.to_asm(),
110111
options(nostack, noreturn)

src/backend/linux_raw/arch/powerpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
9696
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
9797
asm!(
9898
"sc",
99+
"trap",
99100
in("r0") nr.to_asm(),
100101
in("r3") a0.to_asm(),
101102
options(nostack, noreturn)

src/backend/linux_raw/arch/powerpc64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
9696
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
9797
asm!(
9898
"sc",
99+
"trap",
99100
in("r0") nr.to_asm(),
100101
in("r3") a0.to_asm(),
101102
options(nostack, noreturn)

src/backend/linux_raw/arch/riscv64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
4848
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
4949
asm!(
5050
"ecall",
51+
"unimp",
5152
in("a7") nr.to_asm(),
5253
in("a0") a0.to_asm(),
5354
options(nostack, noreturn)

src/backend/linux_raw/arch/s390x.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ pub(in crate::backend) unsafe fn syscall1_readonly(
4848
pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! {
4949
asm!(
5050
"svc 0",
51+
"j .+2",
5152
in("r1") nr.to_asm(),
5253
in("r2") a0.to_asm(),
53-
options(nostack, preserves_flags, noreturn)
54+
options(nostack, noreturn)
5455
)
5556
}
5657

0 commit comments

Comments
 (0)