vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / model / Image.cpp
blob61269b592880e609592580c173dfe2ba5a8c68a4
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "Image.h"
8 #include "ImageDebugInfo.h"
9 #include "LocatableFile.h"
10 #include "Team.h"
11 #include "TeamDebugInfo.h"
14 Image::Image(Team* team,const ImageInfo& imageInfo, LocatableFile* imageFile)
16 fTeam(team),
17 fInfo(imageInfo),
18 fImageFile(imageFile),
19 fDebugInfo(NULL),
20 fDebugInfoState(IMAGE_DEBUG_INFO_NOT_LOADED)
22 if (fImageFile != NULL)
23 fImageFile->AcquireReference();
27 Image::~Image()
29 if (fDebugInfo != NULL) {
30 if (fTeam != NULL)
31 fTeam->DebugInfo()->RemoveImageDebugInfo(fDebugInfo);
32 fDebugInfo->ReleaseReference();
34 if (fImageFile != NULL)
35 fImageFile->ReleaseReference();
39 status_t
40 Image::Init()
42 return B_OK;
46 bool
47 Image::ContainsAddress(target_addr_t address) const
49 return (address >= fInfo.TextBase()
50 && address < fInfo.TextBase() + fInfo.TextSize())
51 || (address >= fInfo.DataBase()
52 && address < fInfo.DataBase() + fInfo.DataSize());
56 status_t
57 Image::SetImageDebugInfo(ImageDebugInfo* debugInfo,
58 image_debug_info_state state)
60 if (debugInfo == fDebugInfo && state == fDebugInfoState)
61 return B_OK;
63 if (fDebugInfo != NULL) {
64 fTeam->DebugInfo()->RemoveImageDebugInfo(fDebugInfo);
65 fDebugInfo->ReleaseReference();
68 fDebugInfo = debugInfo;
69 fDebugInfoState = state;
71 status_t error = B_OK;
72 if (fDebugInfo != NULL) {
73 error = fTeam->DebugInfo()->AddImageDebugInfo(fDebugInfo);
74 if (error == B_OK) {
75 fDebugInfo->AcquireReference();
76 } else {
77 fDebugInfo = NULL;
78 fDebugInfoState = IMAGE_DEBUG_INFO_UNAVAILABLE;
82 // notify listeners
83 fTeam->NotifyImageDebugInfoChanged(this);
85 return error;