Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Use posix API in module net and base
Browse files Browse the repository at this point in the history
cobalt build link error under third_party
   Renamed namespace logging to mini_chromium_base_logging
   Renamed namespace base to mini_chromium_base

Compiled for Evergreen.

Add the double-add-check back
   starboard/shared/libevent/socket_waiter_internal.cc:214

SB16 cobalt calls MessagePumpLibevent::Attach() which doesn't exist

b/302741384
maxz-lab committed Aug 13, 2024
1 parent 9545024 commit 5ab5b29
Showing 93 changed files with 550 additions and 253 deletions.
24 changes: 22 additions & 2 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ if (is_apple) {

# Determines whether libevent should be dep.
dep_libevent = !is_fuchsia && !is_win && !is_mac && !is_nacl
&& !use_cobalt_customizations
&& (!use_cobalt_customizations || sb_api_version >= 16)

# Determines whether message_pump_libevent should be used.
use_libevent = dep_libevent && !is_ios
@@ -980,6 +980,26 @@ component("base") {
"message_loop/message_pump_io_starboard.h",
"message_loop/message_pump_ui_starboard.cc",
"message_loop/message_pump_ui_starboard.h",

# added for posix - by zhangmax


"synchronization/condition_variable_posix.cc",
"time/time_conversion_posix.cc",

"files/file_posix.cc",
"files/file_util_posix.cc",
"files/file_descriptor_watcher_posix.cc",
"files/file_descriptor_watcher_posix.h",
"files/file_enumerator_posix.cc",

"memory/page_size_posix.cc",

"message_loop/watchable_io_message_pump_posix.cc",
"message_loop/watchable_io_message_pump_posix.h",

# end of adding - zhangmax

"process/launch.cc",
"process/launch.h",
"process/launch_starboard.cc",
@@ -2345,7 +2365,7 @@ component("base") {
]
}

if (!use_cobalt_customizations && is_posix && !is_apple) {
if (use_libevent) {
sources += [
"strings/sys_string_conversions_posix.cc",
"synchronization/waitable_event_posix.cc",
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@
#include <jni.h>
#endif

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
#include <sys/time.h>
#include <unistd.h>
#endif
@@ -126,14 +126,13 @@ class PlatformThreadHandle;
class PA_COMPONENT_EXPORT(PARTITION_ALLOC) TimeDelta {
public:
constexpr TimeDelta() = default;

#if BUILDFLAG(IS_WIN)
static TimeDelta FromQPCValue(LONGLONG qpc_value);
// TODO(crbug.com/989694): Avoid base::TimeDelta factory functions
// based on absolute time
static TimeDelta FromFileTime(FILETIME ft);
static TimeDelta FromWinrtDateTime(ABI::Windows::Foundation::DateTime dt);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
static TimeDelta FromTimeSpec(const timespec& ts);
#endif
#if BUILDFLAG(IS_FUCHSIA)
@@ -198,7 +197,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) TimeDelta {
constexpr bool is_min() const { return *this == Min(); }
constexpr bool is_inf() const { return is_min() || is_max(); }

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
struct timespec ToTimeSpec() const;
#endif
#if BUILDFLAG(IS_FUCHSIA)
@@ -586,7 +585,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Time
static Time FromDoubleT(double dt);
double ToDoubleT() const;

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
// Converts the timespec structure to time. MacOS X 10.8.3 (and tentatively,
// earlier versions) will have the |ts|'s tv_nsec component zeroed out,
// having a 1 second resolution, which agrees with
@@ -612,7 +611,7 @@ class PA_COMPONENT_EXPORT(PARTITION_ALLOC) Time
static Time FromJavaTime(int64_t ms_since_epoch);
int64_t ToJavaTime() const;

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
static Time FromTimeVal(struct timeval t);
struct timeval ToTimeVal() const;
#endif
12 changes: 6 additions & 6 deletions base/check.cc
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ class DCheckLogMessage : public LogMessage {
const base::Location location_;
};

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
class DCheckStarboardErrorLogMessage : public StarboardErrorLogMessage {
public:
DCheckStarboardErrorLogMessage(const base::Location& location,
@@ -123,7 +123,7 @@ class DCheckWin32ErrorLogMessage : public Win32ErrorLogMessage {
private:
const base::Location location_;
};
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
class DCheckErrnoLogMessage : public ErrnoLogMessage {
public:
DCheckErrnoLogMessage(const base::Location& location,
@@ -166,13 +166,13 @@ CheckError CheckError::PCheck(const char* file,
int line,
const char* condition) {
SystemErrorCode err_code = logging::GetLastSystemErrorCode();
#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
auto* const log_message =
new StarboardErrorLogMessage(file, line, LOGGING_FATAL, err_code);
#elif BUILDFLAG(IS_WIN)
auto* const log_message =
new Win32ErrorLogMessage(file, line, LOGGING_FATAL, err_code);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
auto* const log_message =
new ErrnoLogMessage(file, line, LOGGING_FATAL, err_code);
#endif
@@ -187,13 +187,13 @@ CheckError CheckError::PCheck(const char* file, int line) {
CheckError CheckError::DPCheck(const char* condition,
const base::Location& location) {
SystemErrorCode err_code = logging::GetLastSystemErrorCode();
#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
auto* const log_message =
new DCheckStarboardErrorLogMessage(location, LOGGING_DCHECK, err_code);
#elif BUILDFLAG(IS_WIN)
auto* const log_message =
new DCheckWin32ErrorLogMessage(location, LOGGING_DCHECK, err_code);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
auto* const log_message =
new DCheckErrnoLogMessage(location, LOGGING_DCHECK, err_code);
#endif
11 changes: 7 additions & 4 deletions base/files/file.h
Original file line number Diff line number Diff line change
@@ -22,10 +22,13 @@ struct stat;

namespace base {

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
using stat_wrapper_t = struct ::stat;
#else
using stat_wrapper_t = struct stat;
#ifndef ftruncate64
#define ftruncate64 ftruncate
#endif
#endif

// Thin wrapper around an OS-level file.
@@ -357,11 +360,11 @@ class BASE_EXPORT File {
bool DeleteOnClose(bool delete_on_close);
#endif

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
static Error OSErrorToFileError(SbSystemError sb_system_error);
#elif BUILDFLAG(IS_WIN)
static Error OSErrorToFileError(DWORD last_error);
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
static Error OSErrorToFileError(int saved_errno);
#endif

@@ -378,7 +381,7 @@ class BASE_EXPORT File {
// Wrapper for stat() or stat64().
static int Stat(const char* path, stat_wrapper_t* sb);
static int Fstat(int fd, stat_wrapper_t* sb);
# if !defined(STARBOARD)
# if !defined(STARBOARD) || (defined(STARBOARD) && SB_API_VERSION >= 16)
// Starboard does not support lstat yet.
static int Lstat(const char* path, stat_wrapper_t* sb);
#endif
4 changes: 4 additions & 0 deletions base/files/file_descriptor_watcher_posix.cc
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@

namespace base {

#if SB_API_VERSION >= 16

namespace {

// Per-thread FileDescriptorWatcher registration.
@@ -272,4 +274,6 @@ void FileDescriptorWatcher::AssertAllowed() {
}
#endif

#endif // SB_API_VERSION >= 16

} // namespace base
12 changes: 6 additions & 6 deletions base/files/file_enumerator.h
Original file line number Diff line number Diff line change
@@ -17,13 +17,13 @@
#include "base/time/time.h"
#include "build/build_config.h"

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
#include <sys/stat.h>
#include <unistd.h>
#include "starboard/file.h"
#elif BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
#include <sys/stat.h>
#include <unistd.h>
#include <unordered_set>
@@ -96,8 +96,8 @@ class BASE_EXPORT FileEnumerator {
// called.
NAMES_ONLY = 1 << 3,

#if defined(STARBOARD)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if defined(STARBOARD) && SB_API_VERSION <= 15
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
SHOW_SYM_LINKS = 1 << 4,
#endif
};
@@ -193,7 +193,7 @@ class BASE_EXPORT FileEnumerator {

bool IsPatternMatched(const FilePath& src) const;

#if defined(STARBOARD)
#if defined(STARBOARD) && SB_API_VERSION <= 15
std::vector<FileInfo> ReadDirectory(const FilePath& source);

// The files in the current directory
@@ -210,7 +210,7 @@ class BASE_EXPORT FileEnumerator {
bool has_find_data_ = false;
CHROME_WIN32_FIND_DATA find_data_;
HANDLE find_handle_ = INVALID_HANDLE_VALUE;
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
// The files in the current directory
std::vector<FileInfo> directory_entries_;

5 changes: 5 additions & 0 deletions base/files/file_enumerator_posix.cc
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@
#include "build/build_config.h"

namespace base {

#if SB_API_VERSION >= 16

namespace {

void GetStat(const FilePath& path, bool show_links, stat_wrapper_t* st) {
@@ -258,4 +261,6 @@ bool FileEnumerator::IsPatternMatched(const FilePath& path) const {
!fnmatch(pattern_.c_str(), path.value().c_str(), FNM_NOESCAPE);
}

#endif // SB_API_VERSION >= 16

} // namespace base
4 changes: 4 additions & 0 deletions base/files/file_enumerator_starboard.cc
Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@

namespace base {

#if SB_API_VERSION <= 15

// FileEnumerator::FileInfo ----------------------------------------------------

FileEnumerator::FileInfo::FileInfo() {
@@ -225,4 +227,6 @@ FileEnumerator::FileInfo FileEnumerator::GetInfo() const {
return directory_entries_[current_directory_entry_];
}

#endif // SB_API_VERSION <= 15

} // namespace base
4 changes: 4 additions & 0 deletions base/files/file_posix.cc
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ static_assert(sizeof(base::stat_wrapper_t::st_size) >= 8);

namespace base {

#if SB_API_VERSION >= 16

// Make sure our Whence mappings match the system headers.
static_assert(File::FROM_BEGIN == SEEK_SET && File::FROM_CURRENT == SEEK_CUR &&
File::FROM_END == SEEK_END,
@@ -615,4 +617,6 @@ int File::Lstat(const char* path, stat_wrapper_t* sb) {
return lstat(path, sb);
}

#endif // SB_API_VERSION >= 16

} // namespace base
4 changes: 4 additions & 0 deletions base/files/file_starboard.cc
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@

namespace base {

#if SB_API_VERSION <= 15

namespace {
SbFileError g_sb_file_error = kSbFileOk;
} // namespace
@@ -503,4 +505,6 @@ File File::Duplicate() const {
return File();
}

#endif // SB_API_VERSION <= 15

} // namespace base
Loading

0 comments on commit 5ab5b29

Please sign in to comment.