[PATCH] Fix AMD64 backtrace

Andreas Jaeger aj@suse.de
Sun Jan 11 12:17:00 GMT 2004


And here comes setcontext:


ENTRY(__setcontext)
	/* Save argument since syscall will destroy it.  */
	pushq	%rdi
	cfi_adjust_cfa_offset(8)

	/* Set the signal mask with
	   rt_sigprocmask (SIG_SETMASK, mask, NULL, _NSIG/8).  */
	leaq	oSIGMASK(%rdi), %rsi
	xorq	%rdx, %rdx
	movq	$SIG_SETMASK, %rdi
	movq	$_NSIG8,%r10
	movq	$__NR_rt_sigprocmask, %rax
	syscall
	popq	%rdi			/* Reload %rdi, adjust stack.  */
	cfi_adjust_cfa_offset(-8)
	cmpq	$-4095, %rax		/* Check %rax for error.  */
	jae	SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */

	/* Restore the floating-point context.  Not the registers, only the
	   rest.  */
	movq	oFPREGS(%rdi), %rcx
	fldenv	(%rcx)
	ldmxcsr oMXCSR(%rdi)


	/* Load the new stack pointer, the preserved registers and
	   registers used for passing args.  */
	cfi_def_cfa(%rdi, 0)
	cfi_offset(%rbx,oRBX)
	cfi_offset(%rbp,oRBP)
	cfi_offset(%r12,oR12)
	cfi_offset(%r13,oR13)
	cfi_offset(%r14,oR14)
	cfi_offset(%r15,oR15)
	cfi_offset(%rsp,oRSP)
	cfi_offset(%rip,oRIP)
	
	movq	oRSP(%rdi), %rsp
	movq	oRBX(%rdi), %rbx
	movq	oRBP(%rdi), %rbp
	movq	oR12(%rdi), %r12
	movq	oR13(%rdi), %r13
	movq	oR14(%rdi), %r14
	movq	oR15(%rdi), %r15

	/* The following ret should return to the address set with
	getcontext.  Therefore push the address on the stack.  */
	movq	oRIP(%rdi), %rcx
	pushq	%rcx
	cfi_adjust_cfa_offset(8)

	movq	oRSI(%rdi), %rsi
	movq	oRDX(%rdi), %rdx
	movq	oRCX(%rdi), %rcx
	movq	oR8(%rdi), %r8
	movq	oR9(%rdi), %r9

	/* Setup finally  %rdi.  */
	movq	oRDI(%rdi), %rdi

	/* We changed %rdi, fix cfi.  */
	cfi_def_cfa(%rsp, 0)
	cfi_same_value(%rbx)
	cfi_same_value(%rbp)
	cfi_same_value(%r12)
	cfi_same_value(%r13)
	cfi_same_value(%r14)
	cfi_same_value(%r15)

	/* Clear rax to indicate success.  */
	xorq	%rax, %rax

L(pseudo_end):
	ret
PSEUDO_END(__setcontext)

Does it look sane?  

Btw. cfi_same_value is not yet defined in sysdeps.h and needs to be
defined with the appended patch.  Is it ok to commit that one?

Andreas

2004-01-11  Andreas Jaeger  <aj@suse.de>

	* sysdeps/generic/sysdep.h (CFI_SAME_VALUE): New.
	(cfi_same_value): New.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libc-diff
URL: <http://sourceware.org/pipermail/libc-hacker/attachments/20040111/287471cd/attachment.ksh>
-------------- next part --------------

-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SuSE Linux AG, Maxfeldstr. 5, 90409 N?rnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-hacker/attachments/20040111/287471cd/attachment.sig>


More information about the Libc-hacker mailing list