Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: import Cobalt 25 /base #4724

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
353 changes: 282 additions & 71 deletions base/BUILD.gn

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions base/BUILD.gn.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- BUILD.gn
+++ BUILD.gn
@@ -103,6 +103,7 @@ if (is_apple) {

# Determines whether libevent should be dep.
dep_libevent = !is_fuchsia && !is_win && !is_mac && !is_nacl
+ && !use_cobalt_customizations

# Determines whether message_pump_libevent should be used.
use_libevent = dep_libevent && !is_ios
24 changes: 24 additions & 0 deletions base/METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "base"
description:
"Subtree at base."

third_party {
identifier {
type: "ChromiumVersion"
value: "114.0.5735.358" # from https://chromereleases.googleblog.com/2024/03/long-term-support-channel-update-for_26.html
}
identifier {
type: "Git"
value: "https://chromium.googlesource.com/chromium/src.git"
version: "1759c6ae9316996b9f150c0ce9d0ca78a3d15c02"
}
identifier {
type: "UpstreamSubdir"
value: "base"
}
last_upgrade_date {
year: 2023
month: 9
day: 12
}
}
2 changes: 2 additions & 0 deletions base/allocator/dispatcher/dispatcher.cc
Original file line number Diff line number Diff line change
@@ -6,9 +6,11 @@

#include "base/allocator/buildflags.h"
#include "base/allocator/dispatcher/internal/dispatch_data.h"
#if !defined(COBALT_PENDING_CLEAN_UP)
#include "base/allocator/partition_allocator/partition_alloc.h"
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#include "base/allocator/partition_allocator/shim/allocator_shim.h"
#endif
#include "base/check.h"
#include "base/dcheck_is_on.h"
#include "base/no_destructor.h"
2 changes: 2 additions & 0 deletions base/allocator/dispatcher/dispatcher_unittest.cc
Original file line number Diff line number Diff line change
@@ -26,8 +26,10 @@ namespace base::allocator::dispatcher {
namespace {
using configuration::kMaximumNumberOfObservers;
using configuration::kMaximumNumberOfOptionalObservers;
#if BUILDFLAG(USE_PARTITION_ALLOC)
using partition_alloc::PartitionOptions;
using partition_alloc::ThreadSafePartitionRoot;
#endif
using testing::DispatcherTest;

// A simple observer implementation. Since these tests plug in to Partition
2 changes: 2 additions & 0 deletions base/allocator/dispatcher/internal/dispatch_data.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@
#define BASE_ALLOCATOR_DISPATCHER_INTERNAL_DISPATCH_DATA_H_

#include "base/allocator/buildflags.h"
#if defined(COBALT_PENDING_CLEAN_UP)
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#endif
#include "base/base_export.h"
#include "build/build_config.h"

2 changes: 2 additions & 0 deletions base/allocator/dispatcher/internal/dispatcher_internal.h
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@
#include "base/allocator/dispatcher/internal/dispatch_data.h"
#include "base/allocator/dispatcher/internal/tools.h"
#include "base/allocator/dispatcher/subsystem.h"
#if !defined(COBALT_PENDING_CLEAN_UP)
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#endif
#include "base/check.h"
#include "base/compiler_specific.h"
#include "build/build_config.h"
8 changes: 7 additions & 1 deletion base/allocator/partition_allocator/BUILD.gn
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ component("partition_alloc") {
]
deps = []
public_configs = []
if (is_android) {
if (is_android && !use_cobalt_customizations) {
# tagging.cc requires __arm_mte_set_* functions.
deps += [ "//third_party/android_ndk:cpu_features" ]
}
@@ -370,6 +370,12 @@ component("partition_alloc") {
if (enable_pkeys && is_debug) {
configs += [ ":no_stack_protector" ]
}

# Need to include |component("partition_alloc")| for gn check.
if (is_starboard) {
# TODO: b/326459868 - Try using |check_includes = false|.
sources = []
}
}

source_set("raw_ptr") {
4 changes: 2 additions & 2 deletions base/allocator/partition_allocator/partition_alloc.gni
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ declare_args() {
# and doesn't wish to incur the library size increase (crbug.com/674570).
# 2. On NaCl (through this declaration), where PartitionAlloc doesn't
# build at all.
use_partition_alloc = !is_nacl
use_partition_alloc = !use_cobalt_customizations && !is_nacl
}

declare_args() {
@@ -305,7 +305,7 @@ assert(!use_asan_backup_ref_ptr || use_hookable_raw_ptr,
"AsanBackupRefPtr requires RawPtrHookableImpl")

declare_args() {
enable_pkeys = is_linux && target_cpu == "x64"
enable_pkeys = is_linux && target_cpu == "x64" && !use_cobalt_customizations
}
assert(!enable_pkeys || (is_linux && target_cpu == "x64"),
"Pkeys are only supported on x64 linux")
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) CheckError {
#error "Debug builds are not expected to be optimized as official builds."
#endif // defined(OFFICIAL_BUILD) && !defined(NDEBUG)

#if defined(OFFICIAL_BUILD) && !BUILDFLAG(PA_DCHECK_IS_ON)
#if defined(OFFICIAL_BUILD) && !BUILDFLAG(PA_DCHECK_IS_ON) && !defined(STARBOARD)

// Discard log strings to reduce code bloat.
//
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@
#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if defined(STARBOARD)
andrewsavage1 marked this conversation as resolved.
Show resolved Hide resolved
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "third_party/lss/linux_syscall_support.h"
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/995996): Waiting for this header to appear in the iOS SDK.
Original file line number Diff line number Diff line change
@@ -18,7 +18,9 @@
#include "base/allocator/partition_allocator/partition_alloc_base/time/time.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_WIN)
#if defined(STARBOARD)
#include "starboard/thread.h"
#elif BUILDFLAG(IS_WIN)
#include "base/allocator/partition_allocator/partition_alloc_base/win/windows_types.h"
#elif BUILDFLAG(IS_FUCHSIA)
#include <zircon/types.h>
@@ -32,7 +34,9 @@
namespace partition_alloc::internal::base {

// Used for logging. Always an integer value.
#if BUILDFLAG(IS_WIN)
#if defined(STARBOARD)
typedef SbThreadId PlatformThreadId;
#elif BUILDFLAG(IS_WIN)
typedef DWORD PlatformThreadId;
#elif BUILDFLAG(IS_FUCHSIA)
typedef zx_handle_t PlatformThreadId;
@@ -45,7 +49,9 @@ typedef pid_t PlatformThreadId;
// Used to operate on threads.
class PlatformThreadHandle {
public:
#if BUILDFLAG(IS_WIN)
#if defined(STARBOARD)
typedef SbThread Handle;
#elif BUILDFLAG(IS_WIN)
typedef void* Handle;
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
typedef pthread_t Handle;
Original file line number Diff line number Diff line change
@@ -15,7 +15,9 @@
#include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_WIN)
#if defined(STARBOARD)
#include "starboard/thread.h"
#elif BUILDFLAG(IS_WIN)
#include "base/allocator/partition_allocator/partition_alloc_base/win/windows_types.h"
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include <pthread.h>
@@ -33,7 +35,9 @@ namespace partition_alloc::internal::base {
// to distinguish a new thread from an old, dead thread.
class PlatformThreadRef {
public:
#if BUILDFLAG(IS_WIN)
#if defined(STARBOARD)
typedef SbThread RefType;
#elif BUILDFLAG(IS_WIN)
using RefType = DWORD;
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
using RefType = pthread_t;
11 changes: 11 additions & 0 deletions base/allocator/partition_allocator/partition_alloc_config.h.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- allocator/partition_allocator/partition_alloc_config.h
+++ allocator/partition_allocator/partition_alloc_config.h
@@ -104,7 +104,7 @@ static_assert(sizeof(void*) != 8, "");
// POSIX is not only UNIX, e.g. macOS and other OSes. We do use Linux-specific
// features such as futex(2).
#define PA_CONFIG_HAS_LINUX_KERNEL() \
- (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID))
+ (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)) && !defined(STARBOARD)

// On some platforms, we implement locking by spinning in userspace, then going
// into the kernel only if there is contention. This requires platform support,
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@
#include <arm_acle.h>
#endif

#if BUILDFLAG(IS_POSIX)
#if defined(STARBOARD)
#elif BUILDFLAG(IS_POSIX)
#if BUILDFLAG(IS_LINUX)
// We need PKEY_DISABLE_WRITE in this file; glibc defines it in sys/mman.h but
// it's actually Linux-specific and other Linux libcs define it in linux/mman.h.
2 changes: 1 addition & 1 deletion base/at_exit.cc
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ static bool g_disable_managers = false;
AtExitManager::AtExitManager() : next_manager_(g_top_manager) {
// If multiple modules instantiate AtExitManagers they'll end up living in this
// module... they have to coexist.
#if !defined(COMPONENT_BUILD)
#if !defined(COMPONENT_BUILD) && !defined(STARBOARD)
DCHECK(!g_top_manager);
#endif
g_top_manager = this;
4 changes: 4 additions & 0 deletions base/base_paths.h
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@

#include "build/build_config.h"

#if defined(STARBOARD)
andrewsavage1 marked this conversation as resolved.
Show resolved Hide resolved
#include "base/base_paths_starboard.h"
#else
#if BUILDFLAG(IS_WIN)
#include "base/base_paths_win.h"
#elif BUILDFLAG(IS_APPLE)
@@ -21,6 +24,7 @@
#if BUILDFLAG(IS_POSIX)
#include "base/base_paths_posix.h"
#endif
#endif

namespace base {

119 changes: 119 additions & 0 deletions base/base_paths_starboard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright 2018 Google Inc. All Rights Reserved.
andrewsavage1 marked this conversation as resolved.
Show resolved Hide resolved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "starboard/configuration_constants.h"
#include "starboard/system.h"

namespace base {

// This is where we can control the path for placement of a lot of file
// resources for cobalt.
bool PathProviderStarboard(int key, FilePath *result) {
std::vector<char> path(kSbFileMaxPath, 0);
switch (key) {
case base::FILE_EXE:
case base::FILE_MODULE: {
bool success = SbSystemGetPath(kSbSystemPathExecutableFile, path.data(),
path.size());
DCHECK(success);
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(ERROR) << "FILE_EXE not defined.";
return false;
}

case base::DIR_EXE:
case base::DIR_MODULE:
case base::DIR_ASSETS: {
bool success = SbSystemGetPath(kSbSystemPathContentDirectory, path.data(),
path.size());
DCHECK(success);
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(ERROR) << "DIR_EXE/DIR_MODULE not defined.";
return false;
}

#if defined(ENABLE_TEST_DATA)
case base::DIR_TEST_DATA: {
bool success = SbSystemGetPath(kSbSystemPathContentDirectory, path.data(),
path.size());
DCHECK(success);
if (success) {
// Append "test" to match the output of the files copied during builds.
*result = FilePath(path.data()).Append(FILE_PATH_LITERAL("test"));
return true;
}
DLOG(ERROR) << "DIR_TEST_DATA not defined.";
return false;
}
#endif // ENABLE_TEST_DATA

case base::DIR_CACHE: {
bool success = SbSystemGetPath(kSbSystemPathCacheDirectory, path.data(),
path.size());
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(INFO) << "DIR_CACHE not defined.";
return false;
}

case base::DIR_TEMP: {
bool success =
SbSystemGetPath(kSbSystemPathTempDirectory, path.data(), path.size());
DCHECK(success);
if (success) {
*result = FilePath(path.data());
return true;
}
DLOG(ERROR) << "DIR_TEMP not defined.";
return false;
}

case base::DIR_HOME:
// TODO: Add a home directory to SbSystemPathId and get it from there.
return PathProviderStarboard(base::DIR_CACHE, result);

case base::DIR_SYSTEM_FONTS:
if (SbSystemGetPath(kSbSystemPathFontDirectory, path.data(),
path.size())) {
*result = FilePath(path.data());
return true;
}
DLOG(INFO) << "DIR_SYSTEM_FONTS not defined.";
return false;

case base::DIR_SYSTEM_FONTS_CONFIGURATION:
if (SbSystemGetPath(kSbSystemPathFontConfigurationDirectory, path.data(),
path.size())) {
*result = FilePath(path.data());
return true;
}
DLOG(INFO) << "DIR_SYSTEM_FONTS_CONFIGURATION not defined.";
return false;
}

return false;
}

}
Loading