X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/7a8635c970daf8d9e01bc387183136da7b4e20c4..15580453fc31f5e09669f7a24f74da6dcdf948b0:/Cytore.hpp?ds=sidebyside diff --git a/Cytore.hpp b/Cytore.hpp index 62e956c0..9f3b4c8f 100644 --- a/Cytore.hpp +++ b/Cytore.hpp @@ -52,9 +52,6 @@ struct Header { uint32_t reserved_; }; -struct Block { -}; - template class Offset { private: @@ -85,6 +82,10 @@ class Offset { } }; +struct Block { + Cytore::Offset reserved_; +}; + template static _finline Type_ Round(Type_ value, Type_ size) { Type_ mask(size - 1); @@ -100,7 +101,23 @@ class File { private: int file_; - std::vector blocks_; + + typedef std::vector BlockVector_; + BlockVector_ blocks_; + + struct Mapping_ { + uint8_t *data_; + size_t size_; + + Mapping_(uint8_t *data, size_t size) : + data_(data), + size_(size) + { + } + }; + + typedef std::vector MappingVector_; + MappingVector_ maps_; Header &Header_() { return *reinterpret_cast
(blocks_[0]); @@ -115,8 +132,11 @@ class File { size_t extend(size - before); void *data(mmap(NULL, extend, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, file_, before)); + uint8_t *bytes(reinterpret_cast(data)); + + maps_.push_back(Mapping_(bytes,extend)); for (size_t i(0); i != extend >> Shift_; ++i) - blocks_.push_back(reinterpret_cast(data) + Block_ * i); + blocks_.push_back(bytes + Block_ * i); } void Truncate_(size_t capacity) { @@ -138,10 +158,16 @@ class File { } ~File() { - // XXX: this object is never deconstructed. if it were, this should unmap the memory + for (typename MappingVector_::const_iterator map(maps_.begin()); map != maps_.end(); ++map) + munmap(map->data_, map->size_); close(file_); } + void Sync() { + for (typename MappingVector_::const_iterator map(maps_.begin()); map != maps_.end(); ++map) + msync(map->data_, map->size_, MS_SYNC); + } + size_t Capacity() const { return blocks_.size() * Block_; }