vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / jobs / WriteValueNodeJob.cpp
blob40c4bf0ab793a0b5bc0137b6276f0ffa962c014a
1 /*
2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
7 #include "Jobs.h"
9 #include <AutoLocker.h>
11 #include "Architecture.h"
12 #include "CpuState.h"
13 #include "DebuggerInterface.h"
14 #include "TeamTypeInformation.h"
15 #include "Tracing.h"
16 #include "Value.h"
17 #include "ValueLocation.h"
18 #include "ValueNode.h"
19 #include "ValueNodeContainer.h"
20 #include "ValueWriter.h"
23 WriteValueNodeValueJob::WriteValueNodeValueJob(
24 DebuggerInterface* debuggerInterface, Architecture* architecture,
25 CpuState* cpuState, TeamTypeInformation* typeInformation,
26 ValueNode* valueNode, Value* newValue)
28 fKey(valueNode, JOB_TYPE_WRITE_VALUE_NODE_VALUE),
29 fDebuggerInterface(debuggerInterface),
30 fArchitecture(architecture),
31 fCpuState(cpuState),
32 fTypeInformation(typeInformation),
33 fValueNode(valueNode),
34 fNewValue(newValue)
36 if (fCpuState != NULL)
37 fCpuState->AcquireReference();
38 fValueNode->AcquireReference();
39 fNewValue->AcquireReference();
43 WriteValueNodeValueJob::~WriteValueNodeValueJob()
45 if (fCpuState != NULL)
46 fCpuState->ReleaseReference();
47 fValueNode->ReleaseReference();
48 fNewValue->ReleaseReference();
52 const JobKey&
53 WriteValueNodeValueJob::Key() const
55 return fKey;
59 status_t
60 WriteValueNodeValueJob::Do()
62 ValueNodeContainer* container = fValueNode->Container();
63 if (container == NULL)
64 return B_BAD_VALUE;
66 ValueWriter writer(fArchitecture, fDebuggerInterface,
67 fCpuState, -1);
69 BVariant value;
70 fNewValue->ToVariant(value);
72 status_t error = writer.WriteValue(fValueNode->Location(), value);
73 if (error != B_OK)
74 return error;
76 AutoLocker<ValueNodeContainer> containerLocker(container);
77 fValueNode->SetLocationAndValue(fValueNode->Location(), fNewValue, B_OK);
79 return B_OK;