xref: /linux/arch/um/os-Linux/registers.c (revision 1553a1c48281243359a9529a10ddb551f3b967ab)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2004 PathScale, Inc
4  * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
5  */
6 
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/ptrace.h>
10 #include <sysdep/ptrace.h>
11 #include <sysdep/ptrace_user.h>
12 #include <registers.h>
13 
14 /* This is set once at boot time and not changed thereafter */
15 
16 static unsigned long exec_regs[MAX_REG_NR];
17 static unsigned long exec_fp_regs[FP_SIZE];
18 
19 int init_pid_registers(int pid)
20 {
21 	int err;
22 
23 	err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
24 	if (err < 0)
25 		return -errno;
26 
27 	arch_init_registers(pid);
28 	get_fp_registers(pid, exec_fp_regs);
29 	return 0;
30 }
31 
32 void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
33 {
34 	memcpy(regs, exec_regs, sizeof(exec_regs));
35 
36 	if (fp_regs)
37 		memcpy(fp_regs, exec_fp_regs, sizeof(exec_fp_regs));
38 }
39