(root)/
strace-6.5/
src/
linux/
x86_64/
getregs_old.c
       1  /*
       2   * Copyright (c) 2013 Denys Vlasenko <vda.linux@googlemail.com>
       3   * Copyright (c) 2013-2015 Dmitry V. Levin <ldv@strace.io>
       4   * Copyright (c) 2015-2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: LGPL-2.1-or-later
       8   */
       9  
      10  /*
      11   * PTRACE_GETREGSET was added to the kernel in v2.6.25,
      12   * a PTRACE_GETREGS based fallback is provided for old kernels.
      13   */
      14  static int
      15  getregs_old(struct tcb *tcp)
      16  {
      17  	/* Use old method, with unreliable heuristical detection of 32-bitness. */
      18  	long r = ptrace(PTRACE_GETREGS, tcp->pid, NULL, &x86_64_regs);
      19  	if (r)
      20  		return r;
      21  
      22  	if (x86_64_regs.cs == 0x23) {
      23  		x86_io.iov_len = sizeof(i386_regs);
      24  		/*
      25  		 * The order is important: i386_regs and x86_64_regs
      26  		 * are overlaid in memory!
      27  		 */
      28  		i386_regs.ebx = x86_64_regs.rbx;
      29  		i386_regs.ecx = x86_64_regs.rcx;
      30  		i386_regs.edx = x86_64_regs.rdx;
      31  		i386_regs.esi = x86_64_regs.rsi;
      32  		i386_regs.edi = x86_64_regs.rdi;
      33  		i386_regs.ebp = x86_64_regs.rbp;
      34  		i386_regs.eax = x86_64_regs.rax;
      35  		/* i386_regs.xds = x86_64_regs.ds; unused by strace */
      36  		/* i386_regs.xes = x86_64_regs.es; ditto... */
      37  		/* i386_regs.xfs = x86_64_regs.fs; */
      38  		/* i386_regs.xgs = x86_64_regs.gs; */
      39  		i386_regs.orig_eax = x86_64_regs.orig_rax;
      40  		i386_regs.eip = x86_64_regs.rip;
      41  		/* i386_regs.xcs = x86_64_regs.cs; */
      42  		/* i386_regs.eflags = x86_64_regs.eflags; */
      43  		i386_regs.esp = x86_64_regs.rsp;
      44  		/* i386_regs.xss = x86_64_regs.ss; */
      45  	} else {
      46  		x86_io.iov_len = sizeof(x86_64_regs);
      47  	}
      48  	return 0;
      49  }