[fuchsia] Add zx_vmo_replace_as_executable calls
In the future, newly created VMOs on Fuchsia will not be mappable as
executable by default. In preparation for that, start using
zx_vmo_replace_as_executable to mark Fuchsia's VMOs as executable as
needed.
SEC-42
TEST=CQ
Change-Id: I9df86bbb33b02042260727d64e74b7146eb1d1a6
Reviewed-on: https://dart-review.googlesource.com/76304
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
diff --git a/runtime/vm/virtual_memory_fuchsia.cc b/runtime/vm/virtual_memory_fuchsia.cc
index df1bfe8..78186e9 100644
--- a/runtime/vm/virtual_memory_fuchsia.cc
+++ b/runtime/vm/virtual_memory_fuchsia.cc
@@ -57,6 +57,17 @@
zx_object_set_property(vmo, ZX_PROP_NAME, name, strlen(name));
}
+ if (is_executable) {
+ // Add ZX_PERM_EXECUTE permission to VMO, so it can be mapped
+ // into memory as executable.
+ status = zx_vmo_replace_as_executable(vmo, ZX_HANDLE_INVALID, &vmo);
+ if (status != ZX_OK) {
+ LOG_ERR("zx_vmo_replace_as_executable() failed: %s\n",
+ zx_status_get_string(status));
+ return NULL;
+ }
+ }
+
const uint32_t flags = ZX_VM_PERM_READ | ZX_VM_PERM_WRITE |
(is_executable ? ZX_VM_PERM_EXECUTE : 0);
uword address;
@@ -94,6 +105,17 @@
zx_object_set_property(vmo, ZX_PROP_NAME, name, strlen(name));
}
+ if (is_executable) {
+ // Add ZX_PERM_EXECUTE permission to VMO, so it can be mapped
+ // into memory as executable.
+ status = zx_vmo_replace_as_executable(vmo, ZX_HANDLE_INVALID, &vmo);
+ if (status != ZX_OK) {
+ LOG_ERR("zx_vmo_replace_as_executable() failed: %s\n",
+ zx_status_get_string(status));
+ return NULL;
+ }
+ }
+
const zx_vm_option_t options = ZX_VM_PERM_READ | ZX_VM_PERM_WRITE |
(is_executable ? ZX_VM_PERM_EXECUTE : 0);
uword base;