vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / jobs / RetrieveMemoryBlockJob.cpp
blobfd7f472650d5771011b1b95cea1149a8468ea571
1 /*
2 * Copyright 2012, 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 "Team.h"
12 #include "TeamMemory.h"
13 #include "TeamMemoryBlock.h"
16 RetrieveMemoryBlockJob::RetrieveMemoryBlockJob(Team* team,
17 TeamMemory* teamMemory, TeamMemoryBlock* memoryBlock)
19 fKey(memoryBlock, JOB_TYPE_GET_MEMORY_BLOCK),
20 fTeam(team),
21 fTeamMemory(teamMemory),
22 fMemoryBlock(memoryBlock)
24 fTeamMemory->AcquireReference();
25 fMemoryBlock->AcquireReference();
29 RetrieveMemoryBlockJob::~RetrieveMemoryBlockJob()
31 fTeamMemory->ReleaseReference();
32 fMemoryBlock->ReleaseReference();
36 const JobKey&
37 RetrieveMemoryBlockJob::Key() const
39 return fKey;
43 status_t
44 RetrieveMemoryBlockJob::Do()
46 ssize_t result = fTeamMemory->ReadMemory(fMemoryBlock->BaseAddress(),
47 fMemoryBlock->Data(), fMemoryBlock->Size());
48 if (result < 0) {
49 fMemoryBlock->NotifyDataRetrieved(result);
50 return result;
53 uint32 protection = 0;
54 uint32 locking = 0;
55 status_t error = fTeamMemory->GetMemoryProperties(
56 fMemoryBlock->BaseAddress(), protection, locking);
57 if (error != B_OK) {
58 fMemoryBlock->NotifyDataRetrieved(error);
59 return error;
62 fMemoryBlock->SetWritable((protection & B_WRITE_AREA) != 0);
63 fMemoryBlock->MarkValid();
64 return B_OK;