summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2010-11-30 23:38:24 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2010-12-01 01:46:27 -0800
commitffbb3bd57668b3733a13f00d43760d8b9abfd887 (patch)
tree025e6dd327a0488954635aa0bc0e8b929aa73004
parenta171abd4ff69aa3d897f4d70e6971606ad36d7c4 (diff)
Add File::mappings_ to Cytore for munmap() and msync().
-rw-r--r--Cytore.hpp31
-rw-r--r--MobileCydia.mm11
2 files changed, 35 insertions, 7 deletions
diff --git a/Cytore.hpp b/Cytore.hpp
index 62e956c..db40045 100644
--- a/Cytore.hpp
+++ b/Cytore.hpp
@@ -100,7 +100,23 @@ class File {
private:
int file_;
- std::vector<uint8_t *> blocks_;
+
+ typedef std::vector<uint8_t *> 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<Mapping_> MappingVector_;
+ MappingVector_ maps_;
Header &Header_() {
return *reinterpret_cast<Header *>(blocks_[0]);
@@ -115,8 +131,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<uint8_t *>(data));
+
+ maps_.push_back(Mapping_(bytes,extend));
for (size_t i(0); i != extend >> Shift_; ++i)
- blocks_.push_back(reinterpret_cast<uint8_t *>(data) + Block_ * i);
+ blocks_.push_back(bytes + Block_ * i);
}
void Truncate_(size_t capacity) {
@@ -138,10 +157,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_;
}
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 069a04a..5a09168 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -8062,21 +8062,24 @@ static _finline void _setHomePage(Cydia *self) {
}
- (void) _saveConfig {
+ _trace();
+ MetaFile_.Sync();
+ _trace();
+
if (Changed_) {
- _trace();
NSString *error(nil);
+
if (NSData *data = [NSPropertyListSerialization dataFromPropertyList:Metadata_ format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error]) {
_trace();
NSError *error(nil);
if (![data writeToFile:@"/var/lib/cydia/metadata.plist" options:NSAtomicWrite error:&error])
NSLog(@"failure to save metadata data: %@", error);
_trace();
+
+ Changed_ = false;
} else {
NSLog(@"failure to serialize metadata: %@", error);
- return;
}
-
- Changed_ = false;
}
}