Commit 70d3ab46 authored by Kenton Varda's avatar Kenton Varda

Fix msync() usage in Unix filesystem implementation.

Apparently, msync()'s parameters must be page-aligned, bah.
parent 3f4beb3b
...@@ -310,10 +310,10 @@ KJ_TEST("DiskFile") { ...@@ -310,10 +310,10 @@ KJ_TEST("DiskFile") {
KJ_EXPECT(kj::str(writableMapping->get().slice(0, 6).asChars()) == "foobaz"); KJ_EXPECT(kj::str(writableMapping->get().slice(0, 6).asChars()) == "foobaz");
KJ_EXPECT(kj::str(privateMapping.slice(0, 6).asChars()) == "Foobaz"); KJ_EXPECT(kj::str(privateMapping.slice(0, 6).asChars()) == "Foobaz");
writableMapping->get()[0] = 'D'; writableMapping->get()[1] = 'D';
writableMapping->changed(writableMapping->get().slice(0, 1)); writableMapping->changed(writableMapping->get().slice(1, 2));
KJ_EXPECT(kj::str(mapping.slice(0, 6).asChars()) == "Doobaz"); KJ_EXPECT(kj::str(mapping.slice(0, 6).asChars()) == "fDobaz");
KJ_EXPECT(kj::str(writableMapping->get().slice(0, 6).asChars()) == "Doobaz"); KJ_EXPECT(kj::str(writableMapping->get().slice(0, 6).asChars()) == "fDobaz");
KJ_EXPECT(kj::str(privateMapping.slice(0, 6).asChars()) == "Foobaz"); KJ_EXPECT(kj::str(privateMapping.slice(0, 6).asChars()) == "Foobaz");
file->write(0, StringPtr("qux").asBytes()); file->write(0, StringPtr("qux").asBytes());
......
...@@ -441,13 +441,19 @@ public: ...@@ -441,13 +441,19 @@ public:
void changed(ArrayPtr<byte> slice) override { void changed(ArrayPtr<byte> slice) override {
KJ_REQUIRE(slice.begin() >= bytes.begin() && slice.end() <= bytes.end(), KJ_REQUIRE(slice.begin() >= bytes.begin() && slice.end() <= bytes.end(),
"byte range is not part of this mapping"); "byte range is not part of this mapping");
KJ_SYSCALL(msync(slice.begin(), slice.size(), MS_ASYNC));
// msync() requires page-alignment, apparently, so use getMmapRange() to accomplish that.
auto range = getMmapRange(reinterpret_cast<uintptr_t>(slice.begin()), slice.size());
KJ_SYSCALL(msync(reinterpret_cast<void*>(range.offset), range.size, MS_ASYNC));
} }
void sync(ArrayPtr<byte> slice) override { void sync(ArrayPtr<byte> slice) override {
KJ_REQUIRE(slice.begin() >= bytes.begin() && slice.end() <= bytes.end(), KJ_REQUIRE(slice.begin() >= bytes.begin() && slice.end() <= bytes.end(),
"byte range is not part of this mapping"); "byte range is not part of this mapping");
KJ_SYSCALL(msync(slice.begin(), slice.size(), MS_SYNC));
// msync() requires page-alignment, apparently, so use getMmapRange() to accomplish that.
auto range = getMmapRange(reinterpret_cast<uintptr_t>(slice.begin()), slice.size());
KJ_SYSCALL(msync(reinterpret_cast<void*>(range.offset), range.size, MS_SYNC));
} }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment