mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Implement File::Map on Windows.
R=zra@google.com Review URL: https://codereview.chromium.org/2430473002 .
This commit is contained in:
parent
50e557d176
commit
c9c33d9db3
|
@ -74,9 +74,43 @@ bool File::IsClosed() {
|
|||
}
|
||||
|
||||
|
||||
void* File::Map(MapType type, int64_t position, int64_t length) {
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
void* File::Map(File::MapType type, int64_t position, int64_t length) {
|
||||
DWORD prot_alloc;
|
||||
DWORD prot_final;
|
||||
switch (type) {
|
||||
case File::kReadOnly:
|
||||
prot_alloc = PAGE_READWRITE;
|
||||
prot_final = PAGE_READONLY;
|
||||
break;
|
||||
case File::kReadExecute:
|
||||
prot_alloc = PAGE_EXECUTE_READWRITE;
|
||||
prot_final = PAGE_EXECUTE_READ;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* addr = VirtualAlloc(NULL, length, MEM_COMMIT | MEM_RESERVE, prot_alloc);
|
||||
if (addr == NULL) {
|
||||
Log::PrintErr("VirtualAlloc failed %d\n", GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SetPosition(position);
|
||||
if (!ReadFully(addr, length)) {
|
||||
Log::PrintErr("ReadFully failed %d\n", GetLastError());
|
||||
VirtualFree(addr, 0, MEM_RELEASE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DWORD old_prot;
|
||||
bool result = VirtualProtect(addr, length, prot_final, &old_prot);
|
||||
if (!result) {
|
||||
Log::PrintErr("VirtualProtect failed %d\n", GetLastError());
|
||||
VirtualFree(addr, 0, MEM_RELEASE);
|
||||
return NULL;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1241,7 +1241,8 @@ static bool ReadAppSnapshotBlobs(const char* script_name,
|
|||
file->Map(File::kReadOnly, vmisolate_position,
|
||||
instructions_position - vmisolate_position);
|
||||
if (read_only_buffer == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Failed to memory map snapshot\n");
|
||||
Log::PrintErr("Failed to memory map snapshot\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*vmisolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer)
|
||||
|
@ -1261,7 +1262,8 @@ static bool ReadAppSnapshotBlobs(const char* script_name,
|
|||
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||
file->Map(File::kReadExecute, instructions_position, header[4]));
|
||||
if (*instructions_buffer == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Failed to memory map snapshot2\n");
|
||||
Log::PrintErr("Failed to memory map snapshot\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1283,29 +1285,33 @@ static bool ReadAppSnapshotDynamicLibrary(const char* script_name,
|
|||
*vmisolate_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName));
|
||||
if (*vmisolate_buffer == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledVMIsolateSymbolName);
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledVMIsolateSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*isolate_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName));
|
||||
if (*isolate_buffer == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledIsolateSymbolName);
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledIsolateSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName));
|
||||
if (*instructions_buffer == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledInstructionsSymbolName);
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledInstructionsSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
*rodata_buffer = reinterpret_cast<const uint8_t*>(
|
||||
Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName));
|
||||
if (*rodata_buffer == NULL) {
|
||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledDataSymbolName);
|
||||
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||
kPrecompiledDataSymbolName);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue