xref: /netbsd-src/share/man/man9/man9.i386/return_address.9 (revision 6cb10275d08f045e872662c371fe2f2724f2f6e6)
1.\"	$NetBSD: return_address.9,v 1.7 2014/03/18 18:20:40 riastradh Exp $
2.\"
3.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by David Young.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd May 5, 2010
31.Dt RETURN_ADDRESS 9 i386
32.Os
33.Sh NAME
34.Nm return_address
35.Nd return address from call stack
36.Sh SYNOPSIS
37.In i386/return.h
38.Ft void *
39.Fn return_address "unsigned int level"
40.Sh DESCRIPTION
41The
42.Fn return_address
43function evaluates to the first return address on the call stack
44if
45.Fa level
46equals 0, or else
47to the return address for the stack frame
48.Fa level
49frames down.
50.Pp
51This function is intended to be called by diagnostic code to record
52the call stack.
53.Pp
54A special fault handler stops
55.Fn return_address
56from crashing the kernel by examining a non-existent or corrupt stack
57frame.
58.Pp
59Kernel compilation options affect both the ability of
60.Fn return_address
61to locate return addresses on the stack, and the programmer's
62ability to interpret the addresses.
63The compiler may optimize away the stack frame pointers that
64.Fn return_address
65depends on.
66.Pp
67To use
68.Fn return_address
69effecively, try a kernel configuration option such as
70.Bd -literal
71makeoptions     DEBUG="-g -fno-omit-frame-pointer \e
72		       -fno-optimize-sibling-calls -O0"
73.Ed
74.Sh RETURN VALUES
75The
76.Fn return_address
77function returns the requested return address, or
78.Dv NULL
79if it cannot dissect the call stack.
80.Sh CODE REFERENCES
81.Pa sys/arch/i386/i386/copy.S ,
82.Pa sys/arch/i386/include/return.h
83.Sh REFERENCES
84.Xr config 5
85.Sh HISTORY
86The
87.Fn return_address
88function first appeared in
89.Nx 6.0 .
90.Sh AUTHORS
91.An "David Young" Aq Mt dyoung@NetBSD.org
92