summaryrefslogtreecommitdiff
path: root/Database/internals/database-segment.h
diff options
context:
space:
mode:
authorunknown <Pixel@.(none)>2009-09-16 22:24:08 -0700
committerunknown <Pixel@.(none)>2009-09-16 22:24:08 -0700
commit6a653b35990e9a642dd4af9b8ee5742d5a84956c (patch)
tree31dac2b537af43584bbc6237df824cad7dba1a00 /Database/internals/database-segment.h
parent2142bda77399a49f0a6684cccb4bb3420c2a10df (diff)
Adding basic Database structure.
Diffstat (limited to 'Database/internals/database-segment.h')
-rw-r--r--Database/internals/database-segment.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/Database/internals/database-segment.h b/Database/internals/database-segment.h
new file mode 100644
index 0000000..72086a7
--- /dev/null
+++ b/Database/internals/database-segment.h
@@ -0,0 +1,72 @@
+#ifndef __DATABASE_SEGMENT_H__
+#define __DATABASE_SEGMENT_H__
+
+#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; }
+ 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