This repository was archived by the owner on Mar 24, 2022. It is now read-only.
Commit 18b4c42
committed
adjust signal handler to not always be so stack-hungry
Because the Lucet signal handler is run on any arbitrary thread that
recives a signal, if the signal handler is installed anywhere in the
process, it may be run on a signal stack we didn't set up. This means we
are still bound to be careful about how much stack is present, which
will often be SIGSTKSZ (observed to be ~8kb on Debian-likes, at least).
`handle_signal` is the entrypoint for any signal in the process, so its
call frame, locals, etc, are active for any path through the signal
handler. For other paths through the signal handler that may involve
subsequent calls, and in debug builds of lucet-runtime, the body of the
`SignalBehavior::Default` arm would include several `UContext` local
variables, as well as a `State` local which itself contains another
`UContext`. x86_64 `UContext` are large, resulting in this match arm
being responsible for ~5kb of stack usage in `handle_signal`, that is
only _actually_ used in this match arm.
So, by moving the arm to a closure and immediately calling it, we force
Rust to defer that stack usage in debug builds to only be used when the
closure is called. In release builds, the closure is likely inlined, but
all intermediate copies of UContext _probably_ go away and the entire
issue is _probably_ avoided.
A subsequent commit will introduce tests around signal handler stack use
for these various paths.1 parent 2320b5b commit 18b4c42
1 file changed
Lines changed: 41 additions & 24 deletions
Lines changed: 41 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
207 | 222 | | |
| 223 | + | |
| 224 | + | |
208 | 225 | | |
209 | 226 | | |
210 | 227 | | |
| |||
0 commit comments