OSDN Git Service

Set permissions after loading image.
authorNicolas Capens <capn@google.com>
Mon, 29 May 2017 14:00:32 +0000 (10:00 -0400)
committerNicolas Capens <capn@google.com>
Mon, 29 May 2017 14:15:24 +0000 (14:15 +0000)
Bug b/38514001

Change-Id: I6d2d891545840beee54db95a7456b6ede293d0eb
Reviewed-on: https://swiftshader-review.googlesource.com/9908
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
src/Reactor/SubzeroReactor.cpp

index 020f82b..f52ce98 100644 (file)
@@ -492,20 +492,16 @@ namespace sw
                {
                        if(!entry)
                        {
-                               #if defined(_WIN32)
-                                       VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection);
-                               #else
-                                       mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_WRITE | PROT_EXEC);
-                               #endif
-
                                position = std::numeric_limits<std::size_t>::max();   // Can't stream more data after this
 
                                size_t codeSize = 0;
                                entry = loadImage(&buffer[0], codeSize);
 
                                #if defined(_WIN32)
+                                       VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection);
                                        FlushInstructionCache(GetCurrentProcess(), NULL, 0);
                                #else
+                                       mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC);
                                        __builtin___clear_cache((char*)entry, (char*)entry + codeSize);
                                #endif
                        }