Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: components/nacl/loader/nonsfi/irt_memory.cc

Issue 239763005: Add workaround for mmap() with PROT_EXEC on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/nacl/loader/nonsfi/irt_memory.cc
diff --git a/components/nacl/loader/nonsfi/irt_memory.cc b/components/nacl/loader/nonsfi/irt_memory.cc
index cd7796515db0890b284c218fd4c89d6a0881ff50..16f38e69d030a03c1edaa8d5b619c10b0f0e513e 100644
--- a/components/nacl/loader/nonsfi/irt_memory.cc
+++ b/components/nacl/loader/nonsfi/irt_memory.cc
@@ -5,6 +5,7 @@
#include <errno.h>
#include <sys/mman.h>
+#include "base/logging.h"
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "components/nacl/loader/nonsfi/irt_util.h"
#include "native_client/src/trusted/service_runtime/include/machine/_types.h"
@@ -46,10 +47,21 @@ int NaClFlagsToFlags(int nacl_flags) {
int IrtMMap(void** addr, size_t len, int prot, int flags,
int fd, nacl_abi_off_t off) {
- void* result =
- mmap(*addr, len, NaClProtToProt(prot), NaClFlagsToFlags(flags), fd, off);
+ const int host_prot = NaClProtToProt(prot);
+ // On Chrome OS, mmap will fail if PROT_EXEC is set in |host_prot|,
Mark Seaborn 2014/04/15 23:28:03 Nit: "can fail"
mazda 2014/04/16 00:33:36 Done.
+ // but mprotect will allow changing the permissions later.
+ // See the comments for NaClHostDescMap in
Mark Seaborn 2014/04/15 23:28:03 X-refs in comments are a little bit of an anti-pat
mazda 2014/04/16 00:33:36 Done.
+ // native_client/src/shared/platform/posix/nacl_host_desc.c for details.
+ void* result = mmap(
+ *addr, len, host_prot & ~PROT_EXEC, NaClFlagsToFlags(flags), fd, off);
if (result == MAP_FAILED)
return errno;
+ if (host_prot & PROT_EXEC) {
+ if (mprotect(result, len, host_prot) != 0) {
+ LOG(FATAL) << "IrtMMap: mprotect to turn on PROT_EXEC failed, "
Mark Seaborn 2014/04/15 23:28:03 I was going to suggest doing "return errno" here,
mazda 2014/04/16 00:33:36 Done.
+ << "errno " << errno;
Mark Seaborn 2014/04/15 23:28:03 It's better to use LOG_ERRNO or PLOG -- they repor
mazda 2014/04/16 00:33:36 Done.
+ }
+ }
*addr = result;
return 0;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698