| // Copyright 2023 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| .globl restricted_enter_wrapper |
| restricted_enter_wrapper: |
| // X0 contains the options vector, and X1 contains the reason code pointer. |
| |
| // Save the reason code pointer and shadow call stack pointer on the stack. |
| stp x1, x18, [sp, #-16]! |
| |
| // Save the callee saved regs since the return from restricted mode |
| // will modify all registers. |
| stp x20, x19, [sp, #-16]! |
| stp x22, x21, [sp, #-16]! |
| stp x24, x23, [sp, #-16]! |
| stp x26, x25, [sp, #-16]! |
| stp x28, x27, [sp, #-16]! |
| |
| // Save the frame pointer and return address to the stack. |
| stp x30, x29, [sp, #-16]! |
| |
| // Pass restricted exit as the return vector to the syscall. |
| adr x1, restricted_exit |
| |
| // Pass the stack pointer as the context argument to the syscall. |
| mov x2, sp |
| |
| bl zx_restricted_enter |
| |
| // if we got here it must have failed |
| add sp, sp, #(14*8) // pop the previous state on the stack |
| ret |
| |
| .globl restricted_exit |
| restricted_exit: |
| // Back from restricted mode |
| // x0 holds the context, which is the stack pointer |
| // x1 holds the reason code |
| |
| // Restore the stack pointer at the point of the restricted enter wrapper. |
| mov sp,x0 |
| |
| // Load the frame pointer and return address from the wrapper. |
| ldp x30, x29, [sp], #16 |
| |
| // Restore the callee saved registers. |
| ldp x28, x27, [sp], #16 |
| ldp x26, x25, [sp], #16 |
| ldp x24, x23, [sp], #16 |
| ldp x22, x21, [sp], #16 |
| ldp x20, x19, [sp], #16 |
| |
| // Load the shadow call stack pointer and reason code pointer. |
| ldp x2, x18, [sp], #16 |
| |
| // Return the reason code from this function by setting the reason code pointer. |
| str x1, [x2] |
| |
| // Return back to whatever the address was in the link register. |
| // Make it appear as if the wrapper had returned ZX_OK |
| mov x0, xzr |
| ret |