Commit 2e7ece6b authored by Harris Hancock's avatar Harris Hancock Committed by Kenton Varda

Fix crashes due to null vtable pointers with MSVC

MSVC as of VS2015 does not initialize the vtable pointers of constexpr
objects, causing nullptr dereferences at runtime. To solve this, we can
just convert them to regular const variables with internal (static)
linkage.

The internal linkage bit is important: as long as they are invisible
outside their respective translation units, we do not risk the static
initialization order fiasco.  If we ever need to reference them outside
their translation units, we would need to hide them behind functions (like
HeapArrayDisposer::instance()) to keep things safe.
parent 34031907
......@@ -57,7 +57,7 @@ protected:
}
};
constexpr MmapDisposer mmapDisposer = MmapDisposer();
KJ_CONSTEXPR(static const) MmapDisposer mmapDisposer = MmapDisposer();
kj::Array<const byte> mmapForRead(kj::StringPtr filename) {
int fd;
......
......@@ -42,7 +42,7 @@ public:
}
#endif
};
static constexpr DummyCapTableReader dummyCapTableReader = DummyCapTableReader();
static KJ_CONSTEXPR(const) DummyCapTableReader dummyCapTableReader = DummyCapTableReader();
} // namespace
......
......@@ -242,7 +242,7 @@ protected:
}
};
constexpr MmapDisposer mmapDisposer = MmapDisposer();
KJ_CONSTEXPR(static const) MmapDisposer mmapDisposer = MmapDisposer();
static char* canonicalizePath(char* path) {
// Taken from some old C code of mine.
......
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