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() { ...@@ -357,6 +357,13 @@ declare_args() {
# Change code emission and runtime features to be CET shadow-stack compliant # Change code emission and runtime features to be CET shadow-stack compliant
# (incomplete and experimental). # (incomplete and experimental).
v8_enable_cet_shadow_stack = false 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. # Derived defaults.
...@@ -550,6 +557,10 @@ if (v8_enable_single_generation == true) { ...@@ -550,6 +557,10 @@ if (v8_enable_single_generation == true) {
assert(!v8_enable_conservative_stack_scanning || v8_enable_single_generation, assert(!v8_enable_conservative_stack_scanning || v8_enable_single_generation,
"Conservative stack scanning requires 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_random_seed = "314159265"
v8_toolset_for_shell = "host" v8_toolset_for_shell = "host"
...@@ -976,6 +987,9 @@ config("features") { ...@@ -976,6 +987,9 @@ config("features") {
if (v8_advanced_bigint_algorithms) { if (v8_advanced_bigint_algorithms) {
defines += [ "V8_ADVANCED_BIGINT_ALGORITHMS" ] defines += [ "V8_ADVANCED_BIGINT_ALGORITHMS" ]
} }
if (v8_fuchsia_use_vmex_resource) {
defines += [ "V8_USE_VMEX_RESOURCE" ]
}
} }
config("toolchain") { config("toolchain") {
......
{ {
"facets": {
"fuchsia.test": {
"system-services": [
"fuchsia.kernel.VmexResource"
]
}
},
"sandbox": { "sandbox": {
"dev": [ "dev": [
"null", "null",
......
...@@ -20,21 +20,25 @@ namespace base { ...@@ -20,21 +20,25 @@ namespace base {
namespace { namespace {
static zx::resource g_vmex_resource; static zx_handle_t g_vmex_resource = ZX_HANDLE_INVALID;
static void* g_root_vmar_base = nullptr; static void* g_root_vmar_base = nullptr;
void SetGlobalVmexResource() { #ifdef V8_USE_VMEX_RESOURCE
fuchsia::kernel::VmexResourceSyncPtr vmex_resource; void SetVmexResource() {
auto path = std::string("/svc/") + fuchsia::kernel::VmexResource::Name_; 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( zx_status_t status = fdio_service_connect(
path.data(), vmex_resource.NewRequest().TakeChannel().release()); "/svc/fuchsia.kernel.VmexResource",
if (status != ZX_OK) { vmex_resource_svc.NewRequest().TakeChannel().release());
g_vmex_resource = zx::resource(); DCHECK_EQ(status, ZX_OK);
} else { status = vmex_resource_svc->Get(&vmex_resource);
vmex_resource->Get(&g_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) { zx_vm_option_t GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) { switch (access) {
...@@ -103,7 +107,8 @@ void* AllocateInternal(const zx::vmar& vmar, void* vmar_base, size_t page_size, ...@@ -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. // to be marked as executable in the future.
// TOOD(https://crbug.com/v8/8899): Only call this when we know that the // 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. // 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; return nullptr;
} }
...@@ -225,7 +230,9 @@ void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) { ...@@ -225,7 +230,9 @@ void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
CHECK_EQ(ZX_OK, status); CHECK_EQ(ZX_OK, status);
g_root_vmar_base = reinterpret_cast<void*>(info.base); g_root_vmar_base = reinterpret_cast<void*>(info.base);
SetGlobalVmexResource(); #ifdef V8_USE_VMEX_RESOURCE
SetVmexResource();
#endif
} }
// static // 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