source: rtems/doc/user/stackchk.t @ aba8a85

4.104.114.84.95
Last change on this file since aba8a85 was aba8a85, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/06 at 16:21:09

2006-09-13 Joel Sherrill <joel@…>

  • new_chapters/Makefile.am, user/Makefile.am, user/c_user.texi, user/dirstat.texi, user/task.t: Move stack to first class citizen status. Include it in User Manual and rename to start with rtems_.
  • user/stackchk.t: New file.
  • new_chapters/stackchk.t: Removed.
  • Property mode set to 100644
File size: 6.2 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2006.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6@c  $Id$
7@c
8
9@chapter Stack Bounds Checker
10
11@section Introduction
12
13The stack bounds checker is an RTEMS support component that determines
14if a task has overflowed its run-time stack.  The routines provided
15by the stack bounds checker manager are:
16
17@itemize @bullet
18@item @code{@value{DIRPREFIX}stack_checker_initialize} - Initialize the Stack Bounds Checker
19@item @code{@value{DIRPREFIX}stack_checker_dump_usage} - Report Task Stack Usage
20@end itemize
21
22@section Background
23
24@subsection Task Stack
25
26Each task in a system has a fixed size stack associated with it.  This
27stack is allocated when the task is created.  As the task executes, the
28stack is used to contain parameters, return addresses, saved registers,
29and local variables.  The amount of stack space required by a task
30is dependent on the exact set of routines used.  The peak stack usage
31reflects the worst case of subroutine pushing information on the stack.
32For example, if a subroutine allocates a local buffer of 1024 bytes, then
33this data must be accounted for in the stack of every task that invokes that
34routine.
35
36Recursive routines make calculating peak stack usage difficult, if not
37impossible.  Each call to the recursive routine consumes @i{n} bytes
38of stack space.  If the routine recursives 1000 times, then @code{1000 * @i{n}}
39bytes of stack space are required.
40
41@subsection Execution
42
43The stack bounds checker operates as a set of task extensions.  At
44task creation time, the task's stack is filled with a pattern to
45indicate the stack is unused.  As the task executes, it will overwrite
46this pattern in memory.  At each task switch, the stack bounds checker's
47task switch extension is executed.  This extension checks that the last
48@code{n} bytes of the task's stack have not been overwritten.  If they
49have, then a blown stack error is reported.
50
51The number of bytes checked for an overwrite is processor family dependent.
52The minimum stack frame per subroutine call varies widely between processor
53families.  On CISC families like the Motorola MC68xxx and Intel ix86, all
54that is needed is a return address.  On more complex RISC processors,
55the minimum stack frame per subroutine call may include space to save
56a significant number of registers.
57
58Another processor dependent feature that must be taken into account by
59the stack bounds checker is the direction that the stack grows.  On some
60processor families, the stack grows up or to higher addresses as the
61task executes.  On other families, it grows down to lower addresses.  The
62stack bounds checker implementation uses the stack description definitions
63provided by every RTEMS port to get for this information.
64
65@section Operations
66
67@subsection Initializing the Stack Bounds Checker
68
69The stack checker is initialized automatically when its task
70create extension runs for the first time.  When this occurs,
71the @code{@value{DIRPREFIX}stack_checker_initialize} is invoked.
72
73The application must include the stack bounds checker extension set
74in its set of Initial Extensions.  This set of extensions is
75defined as @code{STACK_CHECKER_EXTENSION}.  If using @code{<confdefs.h>}
76for Configuration Table generation, then all that is necessary is
77to define the macro @code{STACK_CHECKER_ON} before including
78@code{<confdefs.h>} as shown below:
79
80@example
81@group
82#define STACK_CHECKER_ON
83  ...
84#include <confdefs.h>
85@end group
86@end example
87
88@subsection Reporting Task Stack Usage
89
90The application may dynamically report the stack usage for every task
91in the system by calling the @code{@value{DIRPREFIX}stack_checker_dump_usage} routine.
92This routine prints a table with the peak usage and stack size of
93every task in the system.  The following is an example of the
94report generated:
95
96@example
97@group
98    ID      NAME       LOW        HIGH     AVAILABLE      USED
990x04010001  IDLE  0x003e8a60  0x003e9667       2952        200
1000x08010002  TA1   0x003e5750  0x003e7b57       9096       1168
1010x08010003  TA2   0x003e31c8  0x003e55cf       9096       1168
1020x08010004  TA3   0x003e0c40  0x003e3047       9096       1104
1030xffffffff  INTR  0x003ecfc0  0x003effbf      12160        128
104@end group
105@end example
106
107Notice the last time.  The task id is 0xffffffff and its name is "INTR".
108This is not actually a task, it is the interrupt stack.
109
110@subsection When a Task Overflows the Stack
111
112When the stack bounds checker determines that a stack overflow has occurred,
113it will attempt to print a message identifying the task and then shut the
114system down.  If the stack overflow has caused corruption, then it is
115possible that the message can not be printed.
116
117The following is an example of the output generated:
118
119@example
120@group
121BLOWN STACK!!! Offending task(0x3eb360): id=0x08010002; name=0x54413120
122  stack covers range 0x003e5750 - 0x003e7b57 (9224 bytes)
123  Damaged pattern begins at 0x003e5758 and is 128 bytes long
124@end group
125@end example
126
127The above includes the task id and a pointer to the task control block as
128well as enough information so one can look at the task's stack and
129see what was happening.
130
131@section Routines
132
133This section details the stack bounds checker's routines.
134A subsection is dedicated to each of routines
135and describes the calling sequence, related constants, usage,
136and status codes.
137
138@page
139@subsection stack_checker_initialize - Initialize the Stack Bounds Checker
140
141@subheading CALLING SEQUENCE:
142
143@ifset is-C
144@example
145void rtems_stack_checker_initialize( void );
146@end example
147@end ifset
148
149@ifset is-Ada
150@example
151An Ada interface is not currently available.
152@end example
153@end ifset
154
155@subheading STATUS CODES: NONE
156
157@subheading DESCRIPTION:
158
159Initialize the stack bounds checker.
160
161@subheading NOTES:
162
163This is performed automatically the first time the stack bounds checker
164task create extension executes.
165
166@page
167@subsection stack_checker_dump_usage - Report Task Stack Usage
168
169@subheading CALLING SEQUENCE:
170
171@ifset is-C
172@example
173void rtems_stack_checker_dump_usage( void );
174@end example
175@end ifset
176
177@ifset is-Ada
178@example
179An Ada interface is not currently available.
180@end example
181@end ifset
182
183@subheading STATUS CODES: NONE
184
185@subheading DESCRIPTION:
186
187This routine prints a table with the peak stack usage and stack space
188allocation of every task in the system.
189
190@subheading NOTES:
191
192NONE
Note: See TracBrowser for help on using the repository browser.