#ifndef __DATABASE_SEGMENT_H__ #define __DATABASE_SEGMENT_H__ #include #include "database-types.h" class SegmentRefData; /** * The Segment class that holds the memory and patches for a memory segment. * * This class will passively hold the memory for a segment memory. The tags * corresponding to each byte are also stored there. The patches are optionnal, * and will only be allocated if a patch is actually done. * * TODO: do in-memory hollow structure for the tags. */ class Segment : public Base { public: /** * Main constructor. * * @param size is the real data size of this segment. * @param id is the static id for that data segment. * @param cpu_base is the base absolute physical address for that segment in the cpu's flat memory. * @param extra_size gives the size of the uninitialized memory at the end of the segment, typically the bss part. * @param data optionally holds the memory to use for this segment. If it's provided, the caller MUST NOT free it, as it's going to be used directly. */ Segment(Uint32 size, Uint32 id, Uint64 cpu_base, Uint32 extra_size = 0, const Byte * data = 0); ~Segment(); Uint32 getId() { return id; } /** Will return the byte for that pointer in the segment. May be patched. * @param ptr is the pointer for the byte to be retrieved. * @return the byte read, or -1 if it's inside the BSS part, or outside the whole segment. */ short Read(Uint32 ptr); /** Will return the byte for that pointer in the segment. Will NOT be patched. * @param ptr is the pointer for the byte to be retrieved. * @return the byte read, or -1 if it's inside the BSS part, or outside the whole segment. */ short RawRead(Uint32 ptr); /** In case you need to read the (unpatched) memory block. * @return the memory block of the segment. */ const Byte * getPristineMemory() { return plainmemory; } const memory_tags_t * getMemoryTags() { return tags; } void Patch(Uint32 ptr, Byte val); void Restore(Uint32 ptr); bool IsPatched(Uint32 ptr); bool IsLoaded() { return loaded; } /** Will load the memory segment with the provided Handle; will * only work if you didn't provide data during the constructor. * @see Segment() */ void LoadMemory(Handle * src); void setTag(Uint32 ptr, memory_tags_t tag); memory_tags_t getTag(Uint32 ptr); Uint32 getSize() { return size; } Uint64 getFullSize() { return size + extra_size; } Uint64 getCpuBase() { return cpu_base; } SegmentRefData * getSegmentRefData(Uint32 ptr); void setSegmentRefData(Uint32 ptr, SegmentRefData * data); private: Byte * plainmemory, * patches, * patchesmap; SegmentRefData ** refData; memory_tags_t * tags; bool loaded, allocated; Uint32 size, extra_size; Uint32 id; Uint64 cpu_base; }; #endif