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 */ 6 7 #include "Jobs.h" 8 9 #include <AutoLocker.h> 10 11 #include "Team.h" 12 #include "TeamMemory.h" 13 #include "TeamMemoryBlock.h" 14 15 16 RetrieveMemoryBlockJob::RetrieveMemoryBlockJob(Team* team, 17 TeamMemory* teamMemory, TeamMemoryBlock* memoryBlock) 18 : 19 fKey(memoryBlock, JOB_TYPE_GET_MEMORY_BLOCK), 20 fTeam(team), 21 fTeamMemory(teamMemory), 22 fMemoryBlock(memoryBlock) 23 { 24 fTeamMemory->AcquireReference(); 25 fMemoryBlock->AcquireReference(); 26 } 27 28 29 RetrieveMemoryBlockJob::~RetrieveMemoryBlockJob() 30 { 31 fTeamMemory->ReleaseReference(); 32 fMemoryBlock->ReleaseReference(); 33 } 34 35 36 const JobKey& 37 RetrieveMemoryBlockJob::Key() const 38 { 39 return fKey; 40 } 41 42 43 status_t 44 RetrieveMemoryBlockJob::Do() 45 { 46 ssize_t result = fTeamMemory->ReadMemory(fMemoryBlock->BaseAddress(), 47 fMemoryBlock->Data(), fMemoryBlock->Size()); 48 if (result < 0) { 49 fMemoryBlock->NotifyDataRetrieved(result); 50 return result; 51 } 52 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; 60 } 61 62 fMemoryBlock->SetWritable((protection & B_WRITE_AREA) != 0); 63 fMemoryBlock->MarkValid(); 64 return B_OK; 65 } 66