vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debug / arch / x86 / arch_debug_support.cpp
blob1968ede7869d6725305c875405b8342569b8a465
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <debug_support.h>
9 #include "arch_debug_support.h"
12 struct stack_frame {
13 struct stack_frame *previous;
14 void *return_address;
18 status_t
19 arch_debug_get_instruction_pointer(debug_context *context, thread_id thread,
20 void **ip, void **stackFrameAddress)
22 // get the CPU state
23 debug_cpu_state cpuState;
24 status_t error = debug_get_cpu_state(context, thread, NULL, &cpuState);
25 if (error != B_OK)
26 return error;
28 *ip = (void*)cpuState.eip;
29 *stackFrameAddress = (void*)cpuState.ebp;
31 return B_OK;
35 status_t
36 arch_debug_get_stack_frame(debug_context *context, void *stackFrameAddress,
37 debug_stack_frame_info *stackFrameInfo)
39 stack_frame stackFrame;
40 ssize_t bytesRead = debug_read_memory(context, stackFrameAddress, &stackFrame,
41 sizeof(stackFrame));
42 if (bytesRead < B_OK)
43 return bytesRead;
44 if (bytesRead != sizeof(stackFrame))
45 return B_ERROR;
47 stackFrameInfo->frame = stackFrameAddress;
48 stackFrameInfo->parent_frame = stackFrame.previous;
49 stackFrameInfo->return_address = stackFrame.return_address;
50 return B_OK;