00001
00002
00003 #ifndef _CORE_MEMORY_MMAP_HPP
00004 #define _CORE_MEMORY_MMAP_HPP
00005
00006
00007 #include "src/common/blist.hpp"
00008 #include "src/ipc/lock.hpp"
00009 #include "src/memory/heap.hpp"
00010
00011
00012 const uint32 ME_NONE = 0x0000;
00013 const uint32 ME_OTHER = 0x0001;
00014 const uint32 ME_MM_FILE = 0x0002;
00015 const uint32 ME_MOD = 0x0003;
00016 const uint32 ME_CODE = 0x0004;
00017 const uint32 ME_STACK = 0x0005;
00018 const uint32 ME_STACKGUARD = 0x0006;
00019 const uint32 ME_MEMORY = 0x0007;
00020 const uint32 ME_USERDATA = 0x0008;
00021 const uint32 ME_SHMEM = 0x0009;
00022 const uint32 ME_UDATA = 0x000a;
00023 const uint32 ME_ANY = 0xFFFFFFFF;
00024
00025 namespace Thread {
00026 struct thread_t; }
00027
00028
00029 struct mmap_s
00030 {
00031 uint32 start;
00032 uint32 end;
00033 uint32 size;
00034 uint32 type;
00035 void *dt;
00036 uint64 info;
00037 int thread;
00038 int (*destroy)(class mmap_t*, struct mmap_s*);
00039 };
00040
00041
00042 class mmap_t
00043 {
00044 protected:
00045 public:
00046 class IPC::Lock::lock_t lock_mmap;
00047 uint32 range_lo, range_hi;
00048 blist_t map;
00049 class Memory::Heap::heapbox *heap;
00050
00051
00052
00053 blist_s *madd(uint32 start, size_t size, uint32 type, void *dt, uint64 info, int threadno, int (*destroy)(mmap_t*,mmap_s*));
00054 int mdel(blist_s *item);
00055 int mdel(mmap_s *item);
00056
00057 blist_s *mfind(uint32 start);
00058 blist_s *lower (uint32 start);
00059 blist_s *higher (uint32 start);
00060 uint32 lgth();
00061
00062
00063 int mfirstfit(uint32 size, uint32 alignment, uint32 *loc);
00064 int mlastfit (uint32 size, uint32 alignment, uint32 *loc);
00065 int mfitabove(uint32 size, uint32 alignment, uint32 min, uint32 *loc, bool force);
00066 int mfitbelow(uint32 size, uint32 alignment, uint32 max, uint32 *loc, bool force);
00067
00068 public:
00069 void init(uint32 start, uint32 end, class Memory::Heap::heapbox *hp);
00070 void done();
00071
00072
00073 int del(blist_s *item);
00074
00075 blist_s *find(uint32 start);
00076 blist_s *mmap_find(uint32 type, uint32 virt);
00077
00078 blist_s *add(uint32 start, size_t size, uint32 type, void *dt, uint64 info, int threadno, int (*destroy)(mmap_t*,mmap_s*));
00079
00080
00081 int firstfit(uint32 size, uint32 alignment, uint32 type, void *dt, uint64 info,
00082 uint32 *loc, int threadno, int (*destroy)(mmap_t*,mmap_s*));
00083
00084
00085 int fitbelow(uint32 size, uint32 alignment, uint32 max, uint32 type, void *dt,
00086 uint64 info, uint32 *loc, int threadno, int (*destroy)(mmap_t*,mmap_s*), bool force);
00087 };
00088
00089 int mmapcompar(const void *a, const void *b);
00090
00091 #endif