Reviewers: Mikhail Naganov (Chromium), Søren Gjesse,
Message:
While testing LOL code, I see that OS::MemoryMappedFile::open() which I
introduced previously had a bug. In the unix ports, it was truncating the
file
that it opens. In the win32 port, it was opening the file only if it
pre-existed. The actual behavior of open() is actually expected to open the
file if it exists, and to create the file if it doesn't already exists.
Hence, for the unix ports, the fopen mode has been corrected to be "a+"
instead
of "w+". For the win32 port, the dwCreationDisposition arg has been changed
from OPEN_EXISTING to OPEN_ALWAYS (which is equivalent to a+ according to
msdn
docs).
Please take a look. Thanks.
Description:
Bug: OS::MemoryMappedFile::open() should not truncate a pre-existing file.
Please review this at http://codereview.chromium.org/6543039/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/platform-cygwin.cc
M src/platform-freebsd.cc
M src/platform-linux.cc
M src/platform-macos.cc
M src/platform-openbsd.cc
M src/platform-solaris.cc
M src/platform-win32.cc
Index: src/platform-cygwin.cc
===================================================================
--- src/platform-cygwin.cc (revision 6858)
+++ src/platform-cygwin.cc (working copy)
@@ -209,7 +209,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
- FILE* file = fopen(name, "w+");
+ FILE* file = fopen(name, "a+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
Index: src/platform-freebsd.cc
===================================================================
--- src/platform-freebsd.cc (revision 6858)
+++ src/platform-freebsd.cc (working copy)
@@ -224,7 +224,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
- FILE* file = fopen(name, "w+");
+ FILE* file = fopen(name, "a+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
Index: src/platform-linux.cc
===================================================================
--- src/platform-linux.cc (revision 6858)
+++ src/platform-linux.cc (working copy)
@@ -327,7 +327,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
- FILE* file = fopen(name, "w+");
+ FILE* file = fopen(name, "a+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
Index: src/platform-macos.cc
===================================================================
--- src/platform-macos.cc (revision 6858)
+++ src/platform-macos.cc (working copy)
@@ -205,7 +205,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
- FILE* file = fopen(name, "w+");
+ FILE* file = fopen(name, "a+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
Index: src/platform-openbsd.cc
===================================================================
--- src/platform-openbsd.cc (revision 6858)
+++ src/platform-openbsd.cc (working copy)
@@ -222,7 +222,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
- FILE* file = fopen(name, "w+");
+ FILE* file = fopen(name, "a+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
Index: src/platform-solaris.cc
===================================================================
--- src/platform-solaris.cc (revision 6858)
+++ src/platform-solaris.cc (working copy)
@@ -235,7 +235,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
- FILE* file = fopen(name, "w+");
+ FILE* file = fopen(name, "a+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
Index: src/platform-win32.cc
===================================================================
--- src/platform-win32.cc (revision 6858)
+++ src/platform-win32.cc (working copy)
@@ -938,7 +938,7 @@
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
// Open a physical file
HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
if (file == NULL) return NULL;
int size = static_cast<int>(GetFileSize(file, NULL));
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev