[fuchsia] Get VmexResource using FIDL

Moves g_root_vmar_base up in the file, so that we have all
the globals together.

Bug: v8:11232
Change-Id: Ic08cdf3399982962de255028be6718951a17aedb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3416249
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: Samuel Groß <saelo@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78786}
This commit is contained in:
Victor Gomes 2022-01-26 17:50:58 +01:00 committed by V8 LUCI CQ
parent 9cf4f1319d
commit 7d1727d6c9
3 changed files with 27 additions and 4 deletions

View File

@ -5163,7 +5163,11 @@ v8_component("v8_libbase") {
"src/base/debug/stack_trace_fuchsia.cc",
"src/base/platform/platform-fuchsia.cc",
]
deps += [ "//third_party/fuchsia-sdk/sdk/pkg/zx" ]
deps += [
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.kernel",
"//third_party/fuchsia-sdk/sdk/pkg/fdio",
"//third_party/fuchsia-sdk/sdk/pkg/zx",
]
} else if (is_mac || is_ios) {
sources += [
"src/base/debug/stack_trace_posix.cc",

View File

@ -18,6 +18,7 @@
"fuchsia.device.NameProvider",
"fuchsia.fonts.Provider",
"fuchsia.intl.PropertyProvider",
"fuchsia.kernel.VmexResource",
"fuchsia.logger.Log",
"fuchsia.logger.LogSink",
"fuchsia.media.Audio",

View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuchsia/kernel/cpp/fidl.h>
#include <lib/fdio/directory.h>
#include <lib/zx/resource.h>
#include <lib/zx/thread.h>
#include <lib/zx/vmar.h>
@ -18,6 +20,22 @@ namespace base {
namespace {
static zx::resource g_vmex_resource;
static void* g_root_vmar_base = nullptr;
void SetGlobalVmexResource() {
fuchsia::kernel::VmexResourceSyncPtr vmex_resource;
auto path = std::string("/svc/") + fuchsia::kernel::VmexResource::Name_;
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);
}
}
zx_vm_option_t GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
switch (access) {
case OS::MemoryPermission::kNoAccess:
@ -85,7 +103,7 @@ 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(zx::resource(), &vmo) != ZX_OK) {
if (vmo.replace_as_executable(g_vmex_resource, &vmo) != ZX_OK) {
return nullptr;
}
@ -196,8 +214,6 @@ TimezoneCache* OS::CreateTimezoneCache() {
return new PosixDefaultTimezoneCache();
}
static void* g_root_vmar_base = nullptr;
// static
void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
PosixInitializeCommon(hard_abort, gc_fake_mmap);
@ -208,6 +224,8 @@ void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
ZX_INFO_VMAR, &info, sizeof(info), nullptr, nullptr);
CHECK_EQ(ZX_OK, status);
g_root_vmar_base = reinterpret_cast<void*>(info.base);
SetGlobalVmexResource();
}
// static