Commit 9c560b45 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[fuchsia] VmexResource improvement tweaks

- Adds a GN flag to enable the feature
- Adds facets to manifest used by d8/unittests
- Adds some DCHECKS
- Uses zx_handle_t type to avoid global initialization/destructor

Bug: v8:11232
Change-Id: Ibd7766abefbf8c213393cf6365c34f9ff4e6ed7d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3420828Reviewed-by: 's avatarWez <wez@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78886}
parent 50d5fb7a
......@@ -357,6 +357,13 @@ declare_args() {
# Change code emission and runtime features to be CET shadow-stack compliant
# (incomplete and experimental).
v8_enable_cet_shadow_stack = false
# Get VMEX priviledge at startup.
# It allows to run V8 without "deprecated-ambient-replace-as-executable".
# Sets -DV8_USE_VMEX_RESOURCE.
# TODO(victorgomes): Remove this flag once Chormium no longer needs
# the deprecated feature.
v8_fuchsia_use_vmex_resource = is_fuchsia && !build_with_chromium
}
# Derived defaults.
......@@ -550,6 +557,10 @@ if (v8_enable_single_generation == true) {
assert(!v8_enable_conservative_stack_scanning || v8_enable_single_generation,
"Conservative stack scanning requires single generation")
if (v8_fuchsia_use_vmex_resource) {
assert(target_os == "fuchsia", "VMEX resource only available on Fuchsia")
}
v8_random_seed = "314159265"
v8_toolset_for_shell = "host"
......@@ -976,6 +987,9 @@ config("features") {
if (v8_advanced_bigint_algorithms) {
defines += [ "V8_ADVANCED_BIGINT_ALGORITHMS" ]
}
if (v8_fuchsia_use_vmex_resource) {
defines += [ "V8_USE_VMEX_RESOURCE" ]
}
}
config("toolchain") {
......
{
"facets": {
"fuchsia.test": {
"system-services": [
"fuchsia.kernel.VmexResource"
]
}
},
"sandbox": {
"dev": [
"null",
......
......@@ -20,21 +20,25 @@ namespace base {
namespace {
static zx::resource g_vmex_resource;
static zx_handle_t g_vmex_resource = ZX_HANDLE_INVALID;
static void* g_root_vmar_base = nullptr;
void SetGlobalVmexResource() {
fuchsia::kernel::VmexResourceSyncPtr vmex_resource;
auto path = std::string("/svc/") + fuchsia::kernel::VmexResource::Name_;
#ifdef V8_USE_VMEX_RESOURCE
void SetVmexResource() {
DCHECK_EQ(g_vmex_resource, ZX_HANDLE_INVALID);
zx::resource vmex_resource;
fuchsia::kernel::VmexResourceSyncPtr vmex_resource_svc;
zx_status_t status = fdio_service_connect(
path.data(), vmex_resource.NewRequest().TakeChannel().release());
if (status != ZX_OK) {
g_vmex_resource = zx::resource();
} else {
vmex_resource->Get(&g_vmex_resource);
}
"/svc/fuchsia.kernel.VmexResource",
vmex_resource_svc.NewRequest().TakeChannel().release());
DCHECK_EQ(status, ZX_OK);
status = vmex_resource_svc->Get(&vmex_resource);
DCHECK_EQ(status, ZX_OK);
DCHECK(vmex_resource.is_valid());
g_vmex_resource = vmex_resource.release();
}
#endif
zx_vm_option_t GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) {
......@@ -103,7 +107,8 @@ void* AllocateInternal(const zx::vmar& vmar, void* vmar_base, size_t page_size,
// to be marked as executable in the future.
// TOOD(https://crbug.com/v8/8899): Only call this when we know that the
// region will need to be marked as executable in the future.
if (vmo.replace_as_executable(g_vmex_resource, &vmo) != ZX_OK) {
zx::unowned_resource vmex(g_vmex_resource);
if (vmo.replace_as_executable(*vmex, &vmo) != ZX_OK) {
return nullptr;
}
......@@ -225,7 +230,9 @@ void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
CHECK_EQ(ZX_OK, status);
g_root_vmar_base = reinterpret_cast<void*>(info.base);
SetGlobalVmexResource();
#ifdef V8_USE_VMEX_RESOURCE
SetVmexResource();
#endif
}
// static
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment