66 lines · cpp
1//===-- Implementation of longjmp -----------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/setjmp/longjmp.h"10#include "include/llvm-libc-macros/offsetof-macro.h"11#include "src/__support/common.h"12#include "src/__support/macros/config.h"13 14#if !defined(LIBC_TARGET_ARCH_IS_X86)15#error "Invalid file include"16#endif17 18namespace LIBC_NAMESPACE_DECL {19 20#ifdef __i386__21[[gnu::naked]]22LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf, int)) {23 asm(R"(24 mov 0x4(%%esp), %%ecx25 mov 0x8(%%esp), %%eax26 cmpl $0x1, %%eax27 adcl $0x0, %%eax28 29 mov %c[ebx](%%ecx), %%ebx30 mov %c[esi](%%ecx), %%esi31 mov %c[edi](%%ecx), %%edi32 mov %c[ebp](%%ecx), %%ebp33 mov %c[esp](%%ecx), %%esp34 35 jmp *%c[eip](%%ecx)36 )" ::[ebx] "i"(offsetof(__jmp_buf, ebx)),37 [esi] "i"(offsetof(__jmp_buf, esi)), [edi] "i"(offsetof(__jmp_buf, edi)),38 [ebp] "i"(offsetof(__jmp_buf, ebp)), [esp] "i"(offsetof(__jmp_buf, esp)),39 [eip] "i"(offsetof(__jmp_buf, eip)));40}41#else42[[gnu::naked]]43LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf, int)) {44 asm(R"(45 cmpl $0x1, %%esi46 adcl $0x0, %%esi47 movq %%rsi, %%rax48 49 movq %c[rbx](%%rdi), %%rbx50 movq %c[rbp](%%rdi), %%rbp51 movq %c[r12](%%rdi), %%r1252 movq %c[r13](%%rdi), %%r1353 movq %c[r14](%%rdi), %%r1454 movq %c[r15](%%rdi), %%r1555 movq %c[rsp](%%rdi), %%rsp56 jmpq *%c[rip](%%rdi)57 )" ::[rbx] "i"(offsetof(__jmp_buf, rbx)),58 [rbp] "i"(offsetof(__jmp_buf, rbp)), [r12] "i"(offsetof(__jmp_buf, r12)),59 [r13] "i"(offsetof(__jmp_buf, r13)), [r14] "i"(offsetof(__jmp_buf, r14)),60 [r15] "i"(offsetof(__jmp_buf, r15)), [rsp] "i"(offsetof(__jmp_buf, rsp)),61 [rip] "i"(offsetof(__jmp_buf, rip)));62}63#endif64 65} // namespace LIBC_NAMESPACE_DECL66