Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

.\"	$NetBSD: return_address.9,v 1.7 2014/03/18 18:20:40 riastradh Exp $
.\"
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by David Young.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 5, 2010
.Dt RETURN_ADDRESS 9 i386
.Os
.Sh NAME
.Nm return_address
.Nd return address from call stack
.Sh SYNOPSIS
.In i386/return.h
.Ft void *
.Fn return_address "unsigned int level"
.Sh DESCRIPTION
The
.Fn return_address
function evaluates to the first return address on the call stack
if
.Fa level
equals 0, or else
to the return address for the stack frame
.Fa level
frames down.
.Pp
This function is intended to be called by diagnostic code to record
the call stack.
.Pp
A special fault handler stops
.Fn return_address
from crashing the kernel by examining a non-existent or corrupt stack
frame.
.Pp
Kernel compilation options affect both the ability of
.Fn return_address
to locate return addresses on the stack, and the programmer's
ability to interpret the addresses.
The compiler may optimize away the stack frame pointers that
.Fn return_address
depends on.
.Pp
To use
.Fn return_address
effecively, try a kernel configuration option such as
.Bd -literal
makeoptions     DEBUG="-g -fno-omit-frame-pointer \e
		       -fno-optimize-sibling-calls -O0"
.Ed
.Sh RETURN VALUES
The
.Fn return_address
function returns the requested return address, or
.Dv NULL
if it cannot dissect the call stack.
.Sh CODE REFERENCES
.Pa sys/arch/i386/i386/copy.S ,
.Pa sys/arch/i386/include/return.h
.Sh REFERENCES
.Xr config 5
.Sh HISTORY
The
.Fn return_address
function first appeared in
.Nx 6.0 .
.Sh AUTHORS
.An "David Young" Aq Mt dyoung@NetBSD.org