vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / os / arch / x86_common / stack_trace.cpp
blob48b82ae0df1fb4421c0631f00e2d21c5103feafc
1 /*
2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Lotz, mmlr@mlotz.ch
7 */
9 #include <libroot_private.h>
12 /*! Captures a stack trace (the return addresses) of the current thread.
13 \param returnAddresses The array the return address shall be written to.
14 \param maxCount The maximum number of return addresses to be captured.
15 \param skipFrames The number of stack frames that shall be skipped.
16 \param stackBase The base address of the thread stack.
17 \param stackEnd The first address past the thread stack.
18 \return The number of return addresses written to the given array.
20 int32
21 __arch_get_stack_trace(addr_t* returnAddresses, int32 maxCount,
22 int32 skipFrames, addr_t stackBase, addr_t stackEnd)
24 int32 count = 0;
25 addr_t basePointer = (addr_t)get_stack_frame();
27 while (basePointer != 0 && count < maxCount) {
28 if (basePointer < stackBase || basePointer >= stackEnd)
29 break;
31 struct stack_frame {
32 addr_t previous;
33 addr_t return_address;
36 stack_frame* frame = (stack_frame*)basePointer;
38 if (skipFrames <= 0)
39 returnAddresses[count++] = frame->return_address;
40 else
41 skipFrames--;
43 basePointer = frame->previous;
46 return count;