OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [doc/] [new_chapters/] [stackchk.t] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.