--- qtwebengine-5.15.10_p20230815-orig/src/3rdparty/chromium/third_party/perfetto/include/perfetto/ext/base/utils.h 2021-01-20 12:18:42.000000000 +1100 +++ qtwebengine-5.15.10_p20230815/src/3rdparty/chromium/third_party/perfetto/include/perfetto/ext/base/utils.h 2023-10-08 12:29:04.142828963 +1100 @@ -17,25 +17,26 @@ #ifndef INCLUDE_PERFETTO_EXT_BASE_UTILS_H_ #define INCLUDE_PERFETTO_EXT_BASE_UTILS_H_ -#include "perfetto/base/build_config.h" -#include "perfetto/base/compiler.h" - #include #include +#include #include -#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) -#include -#endif - -#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ - PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) -#include // For getpagesize(). -#elif PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) -#include -#endif #include +#include +#include +#include +#include "perfetto/base/build_config.h" +#include "perfetto/base/compiler.h" +#include "perfetto/ext/base/sys_types.h" + +#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) +// Even if Windows has errno.h, the all syscall-restart behavior does not apply. +// Trying to handle EINTR can cause more harm than good if errno is left stale. +// Chromium does the same. +#define PERFETTO_EINTR(x) (x) +#else #define PERFETTO_EINTR(x) \ ([&] { \ decltype(x) eintr_wrapper_result; \ @@ -44,24 +45,11 @@ } while (eintr_wrapper_result == -1 && errno == EINTR); \ return eintr_wrapper_result; \ }()) - -#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) -// TODO(brucedawson) - create a ::perfetto::base::IOSize to replace this. -#if defined(_WIN64) -using ssize_t = __int64; -#else -using ssize_t = long; -#endif #endif namespace perfetto { namespace base { -#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) -constexpr uid_t kInvalidUid = static_cast(-1); -constexpr pid_t kInvalidPid = static_cast(-1); -#endif - // Do not add new usages of kPageSize, consider using GetSysPageSize() below. // TODO(primiano): over time the semantic of kPageSize became too ambiguous. // Strictly speaking, this constant is incorrect on some new devices where the @@ -72,30 +60,11 @@ // Returns the system's page size. Use this when dealing with mmap, madvise and // similar mm-related syscalls. -inline uint32_t GetSysPageSize() { - ignore_result(kPageSize); // Just to keep the amalgamated build happy. -#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ - PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) - static std::atomic page_size{0}; - // This function might be called in hot paths. Avoid calling getpagesize() all - // the times, in many implementations getpagesize() calls sysconf() which is - // not cheap. - uint32_t cached_value = page_size.load(std::memory_order_relaxed); - if (PERFETTO_UNLIKELY(cached_value == 0)) { - cached_value = static_cast(getpagesize()); - page_size.store(cached_value, std::memory_order_relaxed); - } - return cached_value; -#elif PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) - return static_cast(vm_page_size); -#else - return 4096; -#endif -} +uint32_t GetSysPageSize(); -template -constexpr size_t ArraySize(const T& array) { - return sizeof(array) / sizeof(array[0]); +template +constexpr size_t ArraySize(const T (&)[TSize]) { + return TSize; } // Function object which invokes 'free' on its parameter, which must be @@ -109,8 +78,6 @@ template constexpr T AssumeLittleEndian(T value) { - static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__, - "Unimplemented on big-endian archs"); return value; } @@ -125,6 +92,91 @@ return err == EAGAIN || err == EWOULDBLOCK; } +// setenv(2)-equivalent. Deals with Windows vs Posix discrepancies. +void SetEnv(const std::string& key, const std::string& value); + +// unsetenv(2)-equivalent. Deals with Windows vs Posix discrepancies. +void UnsetEnv(const std::string& key); + +// Calls mallopt(M_PURGE, 0) on Android. Does nothing on other platforms. +// This forces the allocator to release freed memory. This is used to work +// around various Scudo inefficiencies. See b/170217718. +void MaybeReleaseAllocatorMemToOS(); + +// geteuid() on POSIX OSes, returns 0 on Windows (See comment in utils.cc). +uid_t GetCurrentUserId(); + +// Forks the process. +// Parent: prints the PID of the child, calls |parent_cb| and exits from the +// process with its return value. +// Child: redirects stdio onto /dev/null, chdirs into / and returns. +void Daemonize(std::function parent_cb); + +// Returns the path of the current executable, e.g. /foo/bar/exe. +std::string GetCurExecutablePath(); + +// Returns the directory where the current executable lives in, e.g. /foo/bar. +// This is independent of cwd(). +std::string GetCurExecutableDir(); + +// Memory returned by AlignedAlloc() must be freed via AlignedFree() not just +// free. It makes a difference on Windows where _aligned_malloc() and +// _aligned_free() must be paired. +// Prefer using the AlignedAllocTyped() below which takes care of the pairing. +void* AlignedAlloc(size_t alignment, size_t size); +void AlignedFree(void*); + +// A RAII version of the above, which takes care of pairing Aligned{Alloc,Free}. +template +struct AlignedDeleter { + inline void operator()(T* ptr) const { AlignedFree(ptr); } +}; + +// The remove_extent here and below is to allow defining unique_ptr. +// As per https://en.cppreference.com/w/cpp/memory/unique_ptr the Deleter takes +// always a T*, not a T[]*. +template +using AlignedUniquePtr = + std::unique_ptr::type>>; + +template +AlignedUniquePtr AlignedAllocTyped(size_t n_membs) { + using TU = typename std::remove_extent::type; + return AlignedUniquePtr( + static_cast(AlignedAlloc(alignof(TU), sizeof(TU) * n_membs))); +} + +// A RAII wrapper to invoke a function when leaving a function/scope. +template +class OnScopeExitWrapper { + public: + explicit OnScopeExitWrapper(Func f) : f_(std::move(f)), active_(true) {} + OnScopeExitWrapper(OnScopeExitWrapper&& other) noexcept + : f_(std::move(other.f_)), active_(other.active_) { + other.active_ = false; + } + ~OnScopeExitWrapper() { + if (active_) + f_(); + } + + private: + Func f_; + bool active_; +}; + +template +PERFETTO_WARN_UNUSED_RESULT OnScopeExitWrapper OnScopeExit(Func f) { + return OnScopeExitWrapper(std::move(f)); +} + +// Returns a xxd-style hex dump (hex + ascii chars) of the input data. +std::string HexDump(const void* data, size_t len, size_t bytes_per_line = 16); +inline std::string HexDump(const std::string& data, + size_t bytes_per_line = 16) { + return HexDump(data.data(), data.size(), bytes_per_line); +} + } // namespace base } // namespace perfetto --- /dev/null 2013-02-04 11:11:16.750999994 +1100 +++ qtwebengine-5.15.10_p20230815/src/3rdparty/chromium/third_party/perfetto/src/base/utils.cc 2023-10-08 21:22:41.123828556 +1100 @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * 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 "perfetto/ext/base/utils.h" + +#include + +#include "perfetto/base/build_config.h" +#include "perfetto/base/logging.h" +#include "perfetto/ext/base/file_utils.h" +#include "perfetto/ext/base/pipe.h" +#include "perfetto/ext/base/string_utils.h" + +#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ + PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \ + PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) || \ + PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) +#include +#include // For _exit() +#include // For getpagesize() and geteuid() & fork() +#endif + +#if PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) +#include +#include +#endif + +#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) +#include +#include +#include // For _aligned_malloc(). +#endif + +#if PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) +#include +#include + +#ifdef M_PURGE +#define PERFETTO_M_PURGE M_PURGE +#else +// Only available in in-tree builds and on newer SDKs. +#define PERFETTO_M_PURGE -101 +#endif // M_PURGE + +#ifdef M_PURGE_ALL +#define PERFETTO_M_PURGE_ALL M_PURGE_ALL +#else +// Only available in in-tree builds and on newer SDKs. +#define PERFETTO_M_PURGE_ALL -104 +#endif // M_PURGE + +namespace { +extern "C" { +using MalloptType = int (*)(int, int); +} +} // namespace +#endif // OS_ANDROID + +namespace perfetto { +namespace base { + +uint32_t GetSysPageSize() { + ignore_result(kPageSize); // Just to keep the amalgamated build happy. +#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ + PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) + static std::atomic page_size{0}; + // This function might be called in hot paths. Avoid calling getpagesize() all + // the times, in many implementations getpagesize() calls sysconf() which is + // not cheap. + uint32_t cached_value = page_size.load(std::memory_order_relaxed); + if (PERFETTO_UNLIKELY(cached_value == 0)) { + cached_value = static_cast(getpagesize()); + page_size.store(cached_value, std::memory_order_relaxed); + } + return cached_value; +#elif PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) + return static_cast(vm_page_size); +#else + return 4096; +#endif +} + +void* AlignedAlloc(size_t alignment, size_t size) { + void* res = nullptr; + alignment = AlignUp(alignment); // At least pointer size. +#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) + // Window's _aligned_malloc() has a nearly identically signature to Unix's + // aligned_alloc() but its arguments are obviously swapped. + res = _aligned_malloc(size, alignment); +#else + // aligned_alloc() has been introduced in Android only in API 28. + // Also NaCl and Fuchsia seems to have only posix_memalign(). + ignore_result(posix_memalign(&res, alignment, size)); +#endif + PERFETTO_CHECK(res); + return res; +} + +void AlignedFree(void* ptr) { +#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) + _aligned_free(ptr); // MSDN says it is fine to pass nullptr. +#else + free(ptr); +#endif +} + +} // namespace base +} // namespace perfetto --- qtwebengine-5.15.10_p20230815-orig/src/3rdparty/chromium/third_party/perfetto/src/base/BUILD.gn 2021-01-20 12:18:42.000000000 +1100 +++ qtwebengine-5.15.10_p20230815/src/3rdparty/chromium/third_party/perfetto/src/base/BUILD.gn 2023-10-08 18:27:38.497967149 +1100 @@ -34,6 +34,7 @@ "subprocess.cc", "thread_checker.cc", "time.cc", + "utils.cc", "uuid.cc", "virtual_destructors.cc", "waitable_event.cc",