vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debug / Image.h
blob1472bcb0cd1824f94609d6297f3a9b9c9c41ac49
1 /*
2 * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #ifndef IMAGE_H
7 #define IMAGE_H
9 #include <stdio.h>
11 #include <elf_private.h>
12 #include <image.h>
13 #include <OS.h>
15 #include <util/DoublyLinkedList.h>
18 struct image_t;
19 struct runtime_loader_debug_area;
22 namespace BPrivate {
23 namespace Debug {
26 class Image : public DoublyLinkedListLinkImpl<Image> {
27 public:
28 Image();
29 virtual ~Image();
31 const image_info& Info() const { return fInfo; }
32 image_id ID() const { return fInfo.id; }
33 const char* Name() const { return fInfo.name; }
34 addr_t TextAddress() const
35 { return (addr_t)fInfo.text; }
36 size_t TextSize() const { return fInfo.text_size; }
38 virtual const elf_sym* LookupSymbol(addr_t address,
39 addr_t* _baseAddress,
40 const char** _symbolName,
41 size_t *_symbolNameLen,
42 bool *_exactMatch) const = 0;
43 virtual status_t NextSymbol(int32& iterator,
44 const char** _symbolName,
45 size_t* _symbolNameLen,
46 addr_t* _symbolAddress, size_t* _symbolSize,
47 int32* _symbolType) const = 0;
49 virtual status_t GetSymbol(const char* name, int32 symbolType,
50 void** _symbolLocation, size_t* _symbolSize,
51 int32* _symbolType) const;
53 protected:
54 image_info fInfo;
58 class SymbolTableBasedImage : public Image {
59 public:
60 SymbolTableBasedImage();
61 virtual ~SymbolTableBasedImage();
63 virtual const elf_sym* LookupSymbol(addr_t address,
64 addr_t* _baseAddress,
65 const char** _symbolName,
66 size_t *_symbolNameLen,
67 bool *_exactMatch) const;
68 virtual status_t NextSymbol(int32& iterator,
69 const char** _symbolName,
70 size_t* _symbolNameLen,
71 addr_t* _symbolAddress, size_t* _symbolSize,
72 int32* _symbolType) const;
74 protected:
75 size_t _SymbolNameLen(const char* symbolName) const;
77 protected:
78 addr_t fLoadDelta;
79 elf_sym* fSymbolTable;
80 char* fStringTable;
81 int32 fSymbolCount;
82 size_t fStringTableSize;
86 class ImageFile : public SymbolTableBasedImage {
87 public:
88 ImageFile();
89 virtual ~ImageFile();
91 status_t Init(const image_info& info);
92 status_t Init(const char* path);
94 private:
95 status_t _LoadFile(const char* path,
96 addr_t* _textAddress, size_t* _textSize,
97 addr_t* _dataAddress, size_t* _dataSize);
99 status_t _FindTableInSection(elf_ehdr* elfHeader,
100 uint16 sectionType);
102 private:
103 int fFD;
104 off_t fFileSize;
105 uint8* fMappedFile;
109 class KernelImage : public SymbolTableBasedImage {
110 public:
111 KernelImage();
112 virtual ~KernelImage();
114 status_t Init(const image_info& info);
118 class CommPageImage : public SymbolTableBasedImage {
119 public:
120 CommPageImage();
121 virtual ~CommPageImage();
123 status_t Init(const image_info& info);
126 } // namespace Debug
127 } // namespace BPrivate
130 using BPrivate::Debug::ImageFile;
133 #endif // IMAGE_H