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) {
|
void* File::Map(File::MapType type, int64_t position, int64_t length) {
|
||||||
UNIMPLEMENTED();
|
DWORD prot_alloc;
|
||||||
return NULL;
|
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,
|
file->Map(File::kReadOnly, vmisolate_position,
|
||||||
instructions_position - vmisolate_position);
|
instructions_position - vmisolate_position);
|
||||||
if (read_only_buffer == NULL) {
|
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)
|
*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*>(
|
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||||
file->Map(File::kReadExecute, instructions_position, header[4]));
|
file->Map(File::kReadExecute, instructions_position, header[4]));
|
||||||
if (*instructions_buffer == NULL) {
|
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*>(
|
*vmisolate_buffer = reinterpret_cast<const uint8_t*>(
|
||||||
Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName));
|
Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName));
|
||||||
if (*vmisolate_buffer == NULL) {
|
if (*vmisolate_buffer == NULL) {
|
||||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||||
kPrecompiledVMIsolateSymbolName);
|
kPrecompiledVMIsolateSymbolName);
|
||||||
|
Platform::Exit(kErrorExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
*isolate_buffer = reinterpret_cast<const uint8_t*>(
|
*isolate_buffer = reinterpret_cast<const uint8_t*>(
|
||||||
Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName));
|
Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName));
|
||||||
if (*isolate_buffer == NULL) {
|
if (*isolate_buffer == NULL) {
|
||||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||||
kPrecompiledIsolateSymbolName);
|
kPrecompiledIsolateSymbolName);
|
||||||
|
Platform::Exit(kErrorExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
*instructions_buffer = reinterpret_cast<const uint8_t*>(
|
||||||
Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName));
|
Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName));
|
||||||
if (*instructions_buffer == NULL) {
|
if (*instructions_buffer == NULL) {
|
||||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||||
kPrecompiledInstructionsSymbolName);
|
kPrecompiledInstructionsSymbolName);
|
||||||
|
Platform::Exit(kErrorExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
*rodata_buffer = reinterpret_cast<const uint8_t*>(
|
*rodata_buffer = reinterpret_cast<const uint8_t*>(
|
||||||
Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName));
|
Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName));
|
||||||
if (*rodata_buffer == NULL) {
|
if (*rodata_buffer == NULL) {
|
||||||
ErrorExit(kErrorExitCode, "Failed to resolve symbol '%s'\n",
|
Log::PrintErr("Failed to resolve symbol '%s'\n",
|
||||||
kPrecompiledDataSymbolName);
|
kPrecompiledDataSymbolName);
|
||||||
|
Platform::Exit(kErrorExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue