18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <stdio.h> 38c2ecf20Sopenharmony_ci#include <stddef.h> 48c2ecf20Sopenharmony_ci#include <signal.h> 58c2ecf20Sopenharmony_ci#include <poll.h> 68c2ecf20Sopenharmony_ci#include <sys/mman.h> 78c2ecf20Sopenharmony_ci#include <sys/user.h> 88c2ecf20Sopenharmony_ci#define __FRAME_OFFSETS 98c2ecf20Sopenharmony_ci#include <linux/ptrace.h> 108c2ecf20Sopenharmony_ci#include <asm/types.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define DEFINE(sym, val) \ 138c2ecf20Sopenharmony_ci asm volatile("\n->" #sym " %0 " #val : : "i" (val)) 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define DEFINE_LONGS(sym, val) \ 168c2ecf20Sopenharmony_ci asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long))) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_civoid foo(void) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci#ifdef __i386__ 218c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct)); 228c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct)); 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci DEFINE(HOST_IP, EIP); 258c2ecf20Sopenharmony_ci DEFINE(HOST_SP, UESP); 268c2ecf20Sopenharmony_ci DEFINE(HOST_EFLAGS, EFL); 278c2ecf20Sopenharmony_ci DEFINE(HOST_AX, EAX); 288c2ecf20Sopenharmony_ci DEFINE(HOST_BX, EBX); 298c2ecf20Sopenharmony_ci DEFINE(HOST_CX, ECX); 308c2ecf20Sopenharmony_ci DEFINE(HOST_DX, EDX); 318c2ecf20Sopenharmony_ci DEFINE(HOST_SI, ESI); 328c2ecf20Sopenharmony_ci DEFINE(HOST_DI, EDI); 338c2ecf20Sopenharmony_ci DEFINE(HOST_BP, EBP); 348c2ecf20Sopenharmony_ci DEFINE(HOST_CS, CS); 358c2ecf20Sopenharmony_ci DEFINE(HOST_SS, SS); 368c2ecf20Sopenharmony_ci DEFINE(HOST_DS, DS); 378c2ecf20Sopenharmony_ci DEFINE(HOST_FS, FS); 388c2ecf20Sopenharmony_ci DEFINE(HOST_ES, ES); 398c2ecf20Sopenharmony_ci DEFINE(HOST_GS, GS); 408c2ecf20Sopenharmony_ci DEFINE(HOST_ORIG_AX, ORIG_EAX); 418c2ecf20Sopenharmony_ci#else 428c2ecf20Sopenharmony_ci#ifdef FP_XSTATE_MAGIC1 438c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_FP_SIZE, 2696); 448c2ecf20Sopenharmony_ci#else 458c2ecf20Sopenharmony_ci DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long)); 468c2ecf20Sopenharmony_ci#endif 478c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_BX, RBX); 488c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_CX, RCX); 498c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_DI, RDI); 508c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_SI, RSI); 518c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_DX, RDX); 528c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_BP, RBP); 538c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_AX, RAX); 548c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R8, R8); 558c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R9, R9); 568c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R10, R10); 578c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R11, R11); 588c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R12, R12); 598c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R13, R13); 608c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R14, R14); 618c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_R15, R15); 628c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX); 638c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_CS, CS); 648c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_SS, SS); 658c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_EFLAGS, EFLAGS); 668c2ecf20Sopenharmony_ci#if 0 678c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_FS, FS); 688c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_GS, GS); 698c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_DS, DS); 708c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_ES, ES); 718c2ecf20Sopenharmony_ci#endif 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_IP, RIP); 748c2ecf20Sopenharmony_ci DEFINE_LONGS(HOST_SP, RSP); 758c2ecf20Sopenharmony_ci#endif 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct)); 788c2ecf20Sopenharmony_ci DEFINE(UM_POLLIN, POLLIN); 798c2ecf20Sopenharmony_ci DEFINE(UM_POLLPRI, POLLPRI); 808c2ecf20Sopenharmony_ci DEFINE(UM_POLLOUT, POLLOUT); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci DEFINE(UM_PROT_READ, PROT_READ); 838c2ecf20Sopenharmony_ci DEFINE(UM_PROT_WRITE, PROT_WRITE); 848c2ecf20Sopenharmony_ci DEFINE(UM_PROT_EXEC, PROT_EXEC); 858c2ecf20Sopenharmony_ci} 86