Skip to content

Commit

Permalink
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

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

b/302741384
  • Loading branch information
maxz-lab committed Aug 14, 2024
1 parent 9545024 commit 885cbbc
Show file tree
Hide file tree
Showing 87 changed files with 528 additions and 251 deletions.
29 changes: 28 additions & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -980,6 +980,33 @@ 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
"strings/sys_string_conversions_posix.cc",

"synchronization/waitable_event_posix.cc",
"synchronization/waitable_event_watcher_posix.cc",
"synchronization/condition_variable_posix.cc",

"threading/platform_thread_internal_posix.cc",
"threading/platform_thread_internal_posix.h",
"time/time_exploded_posix.cc",
"time/time_now_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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions base/check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions base/files/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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;
Expand Down Expand Up @@ -357,11 +357,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

Expand All @@ -378,7 +378,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
Expand Down
4 changes: 4 additions & 0 deletions base/files/file_descriptor_watcher_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace base {

#if SB_API_VERSION >= 16

namespace {

// Per-thread FileDescriptorWatcher registration.
Expand Down Expand Up @@ -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
Expand Up @@ -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>
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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
Expand All @@ -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_;

Expand Down
5 changes: 5 additions & 0 deletions base/files/file_enumerator_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Up @@ -28,6 +28,8 @@

namespace base {

#if SB_API_VERSION <= 15

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

FileEnumerator::FileInfo::FileInfo() {
Expand Down Expand Up @@ -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
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Up @@ -32,6 +32,8 @@

namespace base {

#if SB_API_VERSION <= 15

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

#endif // SB_API_VERSION <= 15

} // namespace base
22 changes: 11 additions & 11 deletions base/files/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#if 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 "base/posix/eintr_wrapper.h"
Expand All @@ -50,7 +50,7 @@ class Time;
// 3) it removes "." and ".." directory components.
BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input);

#if BUILDFLAG(IS_POSIX)
#if BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16
// Prepends the current working directory if `input` is not already absolute,
// and removes "/./" and "/../" This is similar to MakeAbsoluteFilePath(), but
// MakeAbsoluteFilePath() expands all symlinks in the path and this does not.
Expand Down Expand Up @@ -252,7 +252,7 @@ BASE_EXPORT bool ReadFileToStringWithMaxSize(const FilePath& path,
std::string* contents,
size_t max_size);

#if !defined(STARBOARD)
#if !defined(STARBOARD) || SB_API_VERSION >= 16
// As ReadFileToString, but reading from an open stream after seeking to its
// start (if supported by the stream). This can also be used to read the whole
// file from a file descriptor by converting the file descriptor into a stream
Expand All @@ -266,7 +266,7 @@ BASE_EXPORT bool ReadStreamToStringWithMaxSize(FILE* stream,
std::string* contents);
#endif

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16

// Read exactly |bytes| bytes from file descriptor |fd|, storing the result
// in |buffer|. This function is protected against EINTR and partial reads.
Expand All @@ -281,9 +281,9 @@ BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes);
BASE_EXPORT ScopedFD CreateAndOpenFdForTemporaryFileInDir(const FilePath& dir,
FilePath* path);

#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16

#if BUILDFLAG(IS_POSIX)
#if BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16

// ReadFileToStringNonBlocking is identical to ReadFileToString except it
// guarantees that it will not block. This guarantee is provided on POSIX by
Expand Down Expand Up @@ -354,7 +354,7 @@ BASE_EXPORT bool ExecutableExistsInPath(Environment* env,
BASE_EXPORT bool IsPathExecutable(const FilePath& path);
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX)

#endif // BUILDFLAG(IS_POSIX)
#endif // BUILDFLAG(IS_POSIX) || SB_API_VERSION >= 16

// Returns true if the given directory is empty
BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path);
Expand Down Expand Up @@ -549,7 +549,7 @@ BASE_EXPORT bool WriteFile(const FilePath& filename, span<const uint8_t> data);
// do manual conversions from a char span to a uint8_t span.
BASE_EXPORT bool WriteFile(const FilePath& filename, StringPiece data);

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
// Appends |data| to |fd|. Does not close |fd| when done. Returns true iff all
// of |data| were written to |fd|.
BASE_EXPORT bool WriteFileDescriptor(int fd, span<const uint8_t> data);
Expand Down Expand Up @@ -627,7 +627,7 @@ BASE_EXPORT bool PreReadFile(
bool is_executable,
int64_t max_bytes = std::numeric_limits<int64_t>::max());

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16

// Creates a pipe. Returns true on success, otherwise false.
// On success, |read_fd| will be set to the fd of the read side, and
Expand All @@ -648,7 +648,7 @@ BASE_EXPORT bool CreateLocalNonBlockingPipe(int fds[2]);
// Returns true if it was able to set it in the close-on-exec mode, otherwise
// false.
BASE_EXPORT bool SetCloseOnExec(int fd);
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16

#if BUILDFLAG(IS_MAC)
// Test that |path| can only be changed by a given user and members of
Expand Down Expand Up @@ -681,7 +681,7 @@ BASE_EXPORT bool VerifyPathControlledByAdmin(const base::FilePath& path);
// the directory |path|, in the number of FilePath::CharType, or -1 on failure.
BASE_EXPORT int GetMaximumPathComponentLength(const base::FilePath& path);

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || SB_API_VERSION >= 16
// Get a temporary directory for shared memory files. The directory may depend
// on whether the destination is intended for executable files, which in turn
// depends on how /dev/shmem was mounted. As a result, you must supply whether
Expand Down
Loading

0 comments on commit 885cbbc

Please sign in to comment.