Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 14:04:28 +01:00
parent 81b91f4139
commit f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions

View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contains platform-specific typedefs and defines.
// Much of it is derived from Chromium's build/build_config.h.
#ifndef RTC_BASE_SYSTEM_ARCH_H_
#define RTC_BASE_SYSTEM_ARCH_H_
// Processor architecture detection. For more info on what's defined, see:
// https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
// https://www.agner.org/optimize/calling_conventions.pdf
// https://sourceforge.net/p/predef/wiki/Architectures/
// or with gcc, run: "echo | gcc -E -dM -"
#if defined(_M_X64) || defined(__x86_64__)
#define WEBRTC_ARCH_X86_FAMILY
#define WEBRTC_ARCH_X86_64
#define WEBRTC_ARCH_64_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(_M_ARM64) || defined(__aarch64__)
#define WEBRTC_ARCH_ARM_FAMILY
#define WEBRTC_ARCH_64_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(_M_IX86) || defined(__i386__)
#define WEBRTC_ARCH_X86_FAMILY
#define WEBRTC_ARCH_X86
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(_M_ARM) || defined(__ARMEL__)
#define WEBRTC_ARCH_ARM_FAMILY
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__MIPSEL__) || defined(__MIPSEB__)
#define WEBRTC_ARCH_MIPS_FAMILY
#if defined(__LP64__)
#define WEBRTC_ARCH_64_BITS
#else
#define WEBRTC_ARCH_32_BITS
#endif
#if defined(__MIPSEL__)
#define WEBRTC_ARCH_LITTLE_ENDIAN
#else
#define WEBRTC_ARCH_BIG_ENDIAN
#endif
#elif defined(__PPC__)
#if defined(__PPC64__)
#define WEBRTC_ARCH_64_BITS
#else
#define WEBRTC_ARCH_32_BITS
#endif
#if defined(__LITTLE_ENDIAN__)
#define WEBRTC_ARCH_LITTLE_ENDIAN
#else
#define WEBRTC_ARCH_BIG_ENDIAN
#endif
#elif defined(__sparc) || defined(__sparc__)
#if __SIZEOF_LONG__ == 8
#define WEBRTC_ARCH_64_BITS
#else
#define WEBRTC_ARCH_32_BITS
#endif
#define WEBRTC_ARCH_BIG_ENDIAN
#elif defined(__riscv) && __riscv_xlen == 64
#define WEBRTC_ARCH_64_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__riscv) && __riscv_xlen == 32
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__loongarch32)
#define WEBRTC_ARCH_LOONG_FAMILY
#define WEBRTC_ARCH_LOONG32
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__loongarch64)
#define WEBRTC_ARCH_LOONG_FAMILY
#define WEBRTC_ARCH_LOONG64
#define WEBRTC_ARCH_64_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__pnacl__)
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#elif defined(__EMSCRIPTEN__)
#define WEBRTC_ARCH_32_BITS
#define WEBRTC_ARCH_LITTLE_ENDIAN
#else
#error Please add support for your architecture in rtc_base/system/arch.h
#endif
#if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN))
#error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN
#endif
#endif // RTC_BASE_SYSTEM_ARCH_H_

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_ASM_DEFINES_H_
#define RTC_BASE_SYSTEM_ASM_DEFINES_H_
// clang-format off
// clang formatting breaks everything here, e.g. concatenating directives,
// due to absence of context via asm keyword.
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif
// Define the macros used in ARM assembly code, so that for Mac or iOS builds
// we add leading underscores for the function names.
#ifdef __APPLE__
.macro GLOBAL_FUNCTION name
.global _\name
.private_extern _\name
.endm
.macro DEFINE_FUNCTION name
_\name:
.endm
.macro CALL_FUNCTION name
bl _\name
.endm
.macro GLOBAL_LABEL name
.global _\name
.private_extern _\name
.endm
#else
.macro GLOBAL_FUNCTION name
.global \name
.hidden \name
.endm
.macro DEFINE_FUNCTION name
#if defined(__linux__) && defined(__ELF__)
.type \name,%function
#endif
\name:
.endm
.macro CALL_FUNCTION name
bl \name
.endm
.macro GLOBAL_LABEL name
.global \name
.hidden \name
.endm
#endif
// With Apple's clang compiler, for instructions ldrb, strh, etc.,
// the condition code is after the width specifier. Here we define
// only the ones that are actually used in the assembly files.
#if (defined __llvm__) && (defined __APPLE__)
.macro streqh reg1, reg2, num
strheq \reg1, \reg2, \num
.endm
#endif
.text
// clang-format on
#endif // RTC_BASE_SYSTEM_ASM_DEFINES_H_

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_ASSUME_H_
#define RTC_BASE_SYSTEM_ASSUME_H_
// Possibly evaluate `p`, promising the compiler that the result is true; the
// compiler is allowed (but not required) to use this information when
// optimizing the code. USE WITH CAUTION! If you promise the compiler things
// that aren't true, it will build a broken binary for you.
//
// As a simple example, the compiler is allowed to transform this
//
// RTC_ASSUME(x == 4);
// return x;
//
// into this
//
// return 4;
//
// It is even allowed to propagate the assumption "backwards in time", if it can
// prove that it must have held at some earlier time. For example, the compiler
// is allowed to transform this
//
// int Add(int x, int y) {
// if (x == 17)
// y += 1;
// RTC_ASSUME(x != 17);
// return x + y;
// }
//
// into this
//
// int Add(int x, int y) {
// return x + y;
// }
//
// since if `x` isn't 17 on the third line of the function body, the test of `x
// == 17` on the first line must fail since nothing can modify the local
// variable `x` in between.
//
// The intended use is to allow the compiler to optimize better. For example,
// here we allow the compiler to omit an instruction that ensures correct
// rounding of negative arguments:
//
// int DivBy2(int x) {
// RTC_ASSUME(x >= 0);
// return x / 2;
// }
//
// and here we allow the compiler to possibly omit a null check:
//
// void Delete(int* p) {
// RTC_ASSUME(p != nullptr);
// delete p;
// }
//
// clang-format off
#if defined(__GNUC__)
#define RTC_ASSUME(p) do { if (!(p)) __builtin_unreachable(); } while (0)
#else
#define RTC_ASSUME(p) do {} while (0)
#endif
// clang-format on
#endif // RTC_BASE_SYSTEM_ASSUME_H_

View file

@ -0,0 +1,24 @@
/*
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_COCOA_THREADING_H_
#define RTC_BASE_SYSTEM_COCOA_THREADING_H_
// If Cocoa is to be used on more than one thread, it must know that the
// application is multithreaded. Since it's possible to enter Cocoa code
// from threads created by pthread_thread_create, Cocoa won't necessarily
// be aware that the application is multithreaded. Spawning an NSThread is
// enough to get Cocoa to set up for multithreaded operation, so this is done
// if necessary before pthread_thread_create spawns any threads.
//
// http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/chapter_4_section_4.html
void InitCocoaMultiThreading();
#endif // RTC_BASE_SYSTEM_COCOA_THREADING_H_

View file

@ -0,0 +1,24 @@
/*
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/system/cocoa_threading.h"
#import <Foundation/Foundation.h>
#include "rtc_base/checks.h"
void InitCocoaMultiThreading() {
static BOOL is_cocoa_multithreaded = [NSThread isMultiThreaded];
if (!is_cocoa_multithreaded) {
// +[NSObject class] is idempotent.
[NSThread detachNewThreadSelector:@selector(class) toTarget:[NSObject class] withObject:nil];
is_cocoa_multithreaded = YES;
RTC_DCHECK([NSThread isMultiThreaded]);
}
}

View file

@ -0,0 +1,135 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/system/file_wrapper.h"
#include <stddef.h>
#include <cerrno>
#include <cstdint>
#include <string>
#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/numerics/safe_conversions.h"
#ifdef _WIN32
#include <Windows.h>
#else
#endif
#include <utility>
namespace webrtc {
namespace {
FILE* FileOpen(absl::string_view file_name_utf8, bool read_only, int* error) {
RTC_CHECK_EQ(file_name_utf8.find_first_of('\0'), absl::string_view::npos)
<< "Invalid filename, containing NUL character";
std::string file_name(file_name_utf8);
#if defined(_WIN32)
int len = MultiByteToWideChar(CP_UTF8, 0, file_name.c_str(), -1, nullptr, 0);
std::wstring wstr(len, 0);
MultiByteToWideChar(CP_UTF8, 0, file_name.c_str(), -1, &wstr[0], len);
FILE* file = _wfopen(wstr.c_str(), read_only ? L"rb" : L"wb");
#else
FILE* file = fopen(file_name.c_str(), read_only ? "rb" : "wb");
#endif
if (!file && error) {
*error = errno;
}
return file;
}
} // namespace
// static
FileWrapper FileWrapper::OpenReadOnly(absl::string_view file_name_utf8) {
return FileWrapper(FileOpen(file_name_utf8, true, nullptr));
}
// static
FileWrapper FileWrapper::OpenWriteOnly(absl::string_view file_name_utf8,
int* error /*=nullptr*/) {
return FileWrapper(FileOpen(file_name_utf8, false, error));
}
FileWrapper::FileWrapper(FileWrapper&& other) {
operator=(std::move(other));
}
FileWrapper& FileWrapper::operator=(FileWrapper&& other) {
Close();
file_ = other.file_;
other.file_ = nullptr;
return *this;
}
bool FileWrapper::SeekRelative(int64_t offset) {
RTC_DCHECK(file_);
return fseek(file_, rtc::checked_cast<long>(offset), SEEK_CUR) == 0;
}
bool FileWrapper::SeekTo(int64_t position) {
RTC_DCHECK(file_);
return fseek(file_, rtc::checked_cast<long>(position), SEEK_SET) == 0;
}
long FileWrapper::FileSize() {
if (file_ == nullptr)
return -1;
long original_position = ftell(file_);
if (original_position < 0)
return -1;
int seek_error = fseek(file_, 0, SEEK_END);
if (seek_error)
return -1;
long file_size = ftell(file_);
seek_error = fseek(file_, original_position, SEEK_SET);
if (seek_error)
return -1;
return file_size;
}
bool FileWrapper::Flush() {
RTC_DCHECK(file_);
return fflush(file_) == 0;
}
size_t FileWrapper::Read(void* buf, size_t length) {
RTC_DCHECK(file_);
return fread(buf, 1, length, file_);
}
bool FileWrapper::ReadEof() const {
RTC_DCHECK(file_);
return feof(file_);
}
bool FileWrapper::Write(const void* buf, size_t length) {
RTC_DCHECK(file_);
return fwrite(buf, 1, length, file_) == length;
}
bool FileWrapper::Close() {
if (file_ == nullptr)
return true;
bool success = fclose(file_) == 0;
file_ = nullptr;
return success;
}
FILE* FileWrapper::Release() {
FILE* file = file_;
file_ = nullptr;
return file;
}
} // namespace webrtc

View file

@ -0,0 +1,113 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_FILE_WRAPPER_H_
#define RTC_BASE_SYSTEM_FILE_WRAPPER_H_
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include "absl/strings/string_view.h"
// Implementation that can read (exclusive) or write from/to a file.
namespace webrtc {
// This class is a thin wrapper around FILE*. It's main features are that it
// owns the FILE*, calling fclose on destruction, and that on windows, file
// names passed to the open methods are always treated as utf-8, regardless of
// system code page.
// Most of the methods return only a success/fail indication. When needed, an
// optional argument |int* error| should be added to all methods, in the same
// way as for the OpenWriteOnly methods.
class FileWrapper final {
public:
// Opens a file, in read or write mode. Use the is_open() method on the
// returned object to check if the open operation was successful. On failure,
// and if `error` is non-null, the system errno value is stored at |*error|.
// The file is closed by the destructor.
static FileWrapper OpenReadOnly(absl::string_view file_name_utf8);
static FileWrapper OpenWriteOnly(absl::string_view file_name_utf8,
int* error = nullptr);
FileWrapper() = default;
// Takes over ownership of `file`, closing it on destruction. Calling with
// null `file` is allowed, and results in a FileWrapper with is_open() false.
explicit FileWrapper(FILE* file) : file_(file) {}
~FileWrapper() { Close(); }
// Copying is not supported.
FileWrapper(const FileWrapper&) = delete;
FileWrapper& operator=(const FileWrapper&) = delete;
// Support for move semantics.
FileWrapper(FileWrapper&&);
FileWrapper& operator=(FileWrapper&&);
// Returns true if a file has been opened. If the file is not open, no methods
// but is_open and Close may be called.
bool is_open() const { return file_ != nullptr; }
// Closes the file, and implies Flush. Returns true on success, false if
// writing buffered data fails. On failure, the file is nevertheless closed.
// Calling Close on an already closed file does nothing and returns success.
bool Close();
// Releases and returns the wrapped file without closing it. This call passes
// the ownership of the file to the caller, and the wrapper is no longer
// responsible for closing it. Similarly the previously wrapped file is no
// longer available for the wrapper to use in any aspect.
FILE* Release();
// Write any buffered data to the underlying file. Returns true on success,
// false on write error. Note: Flushing when closing, is not required.
bool Flush();
// Seeks to the beginning of file. Returns true on success, false on failure,
// e.g., if the underlying file isn't seekable.
bool Rewind() { return SeekTo(0); }
// TODO(nisse): The seek functions are used only by the WavReader. If that
// code is demoted to test code, seek functions can be deleted from this
// utility.
// Seek relative to current file position.
bool SeekRelative(int64_t offset);
// Seek to given position.
bool SeekTo(int64_t position);
// Returns the file size or -1 if a size could not be determined.
// (A file size might not exists for non-seekable files or file-like
// objects, for example /dev/tty on unix.)
long FileSize();
// Returns number of bytes read. Short count indicates EOF or error.
size_t Read(void* buf, size_t length);
// If the most recent Read() returned a short count, this methods returns true
// if the short count was due to EOF, and false it it was due to some i/o
// error.
bool ReadEof() const;
// Returns true if all data was successfully written (or buffered), or false
// if there was an error. Writing buffered data can fail later, and is
// reported with return value from Flush or Close.
bool Write(const void* buf, size_t length);
private:
FILE* file_ = nullptr;
};
} // namespace webrtc
#endif // RTC_BASE_SYSTEM_FILE_WRAPPER_H_

View file

@ -0,0 +1,29 @@
/*
* Copyright 2020 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_GCD_HELPERS_H_
#define RTC_BASE_SYSTEM_GCD_HELPERS_H_
#include <dispatch/dispatch.h>
#ifdef __cplusplus
extern "C" {
#endif
DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT DISPATCH_NOTHROW dispatch_queue_t
RTCDispatchQueueCreateWithTarget(const char* label,
dispatch_queue_attr_t attr,
dispatch_queue_t target);
#ifdef __cplusplus
}
#endif
#endif // RTC_BASE_SYSTEM_GCD_HELPERS_H_

View file

@ -0,0 +1,22 @@
/*
* Copyright 2020 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/system/gcd_helpers.h"
dispatch_queue_t RTCDispatchQueueCreateWithTarget(const char *label,
dispatch_queue_attr_t attr,
dispatch_queue_t target) {
if (@available(iOS 10, macOS 10.12, tvOS 10, watchOS 3, *)) {
return dispatch_queue_create_with_target(label, attr, target);
}
dispatch_queue_t queue = dispatch_queue_create(label, attr);
dispatch_set_target_queue(queue, target);
return queue;
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_IGNORE_WARNINGS_H_
#define RTC_BASE_SYSTEM_IGNORE_WARNINGS_H_
#ifdef __clang__
#define RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wframe-larger-than=\"")
#define RTC_POP_IGNORING_WFRAME_LARGER_THAN() _Pragma("clang diagnostic pop")
#elif __GNUC__
#define RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wframe-larger-than=\"")
#define RTC_POP_IGNORING_WFRAME_LARGER_THAN() _Pragma("GCC diagnostic pop")
#else
#define RTC_PUSH_IGNORING_WFRAME_LARGER_THAN()
#define RTC_POP_IGNORING_WFRAME_LARGER_THAN()
#endif
#endif // RTC_BASE_SYSTEM_IGNORE_WARNINGS_H_

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_INLINE_H_
#define RTC_BASE_SYSTEM_INLINE_H_
#if defined(_MSC_VER)
#define RTC_FORCE_INLINE __forceinline
#define RTC_NO_INLINE __declspec(noinline)
#elif defined(__GNUC__)
#define RTC_FORCE_INLINE __attribute__((__always_inline__))
#define RTC_NO_INLINE __attribute__((__noinline__))
#else
#define RTC_FORCE_INLINE
#define RTC_NO_INLINE
#endif
#endif // RTC_BASE_SYSTEM_INLINE_H_

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_NO_CFI_ICALL_H_
#define RTC_BASE_SYSTEM_NO_CFI_ICALL_H_
#include "rtc_base/sanitizer.h"
// DISABLE_CFI_ICALL -- Disable Control Flow Integrity indirect call checks.
// Note that the same macro is defined in "base/compiler_specific.h".
// Only use this when building standalone WebRTC.
#if !defined(WEBRTC_CHROMIUM_BUILD)
#if !defined(DISABLE_CFI_ICALL)
#if defined(WEBRTC_WIN)
// Windows also needs __declspec(guard(nocf)).
#define DISABLE_CFI_ICALL RTC_NO_SANITIZE("cfi-icall") __declspec(guard(nocf))
#else
#define DISABLE_CFI_ICALL RTC_NO_SANITIZE("cfi-icall")
#endif // defined(WEBRTC_WIN)
#endif // !defined(DISABLE_CFI_ICALL)
#if !defined(DISABLE_CFI_ICALL)
#define DISABLE_CFI_ICALL
#endif
#endif // !defined(WEBRTC_CHROMIUM_BUILD)
#endif // RTC_BASE_SYSTEM_NO_CFI_ICALL_H_

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_NO_UNIQUE_ADDRESS_H_
#define RTC_BASE_SYSTEM_NO_UNIQUE_ADDRESS_H_
// RTC_NO_UNIQUE_ADDRESS is a portable annotation to tell the compiler that
// a data member need not have an address distinct from all other non-static
// data members of its class.
// It allows empty types to actually occupy zero bytes as class members,
// instead of occupying at least one byte just so that they get their own
// address. There is almost never any reason not to use it on class members
// that could possibly be empty.
// The macro expands to [[no_unique_address]] if the compiler supports the
// attribute, it expands to nothing otherwise.
// Clang should supports this attribute since C++11, while other compilers
// should add support for it starting from C++20. Among clang compilers,
// clang-cl doesn't support it yet and support is unclear also when the target
// platform is iOS.
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#if __has_cpp_attribute(no_unique_address)
// NOLINTNEXTLINE(whitespace/braces)
#define RTC_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
#define RTC_NO_UNIQUE_ADDRESS
#endif
#endif // RTC_BASE_SYSTEM_NO_UNIQUE_ADDRESS_H_

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_RTC_EXPORT_H_
#define RTC_BASE_SYSTEM_RTC_EXPORT_H_
// RTC_EXPORT is used to mark symbols as exported or imported when WebRTC is
// built or used as a shared library.
// When WebRTC is built as a static library the RTC_EXPORT macro expands to
// nothing.
#ifdef WEBRTC_ENABLE_SYMBOL_EXPORT
#ifdef WEBRTC_WIN
#ifdef WEBRTC_LIBRARY_IMPL
#define RTC_EXPORT __declspec(dllexport)
#else
#define RTC_EXPORT __declspec(dllimport)
#endif
#else // WEBRTC_WIN
#if __has_attribute(visibility) && defined(WEBRTC_LIBRARY_IMPL)
#define RTC_EXPORT __attribute__((visibility("default")))
#endif
#endif // WEBRTC_WIN
#endif // WEBRTC_ENABLE_SYMBOL_EXPORT
#ifndef RTC_EXPORT
#define RTC_EXPORT
#endif
#endif // RTC_BASE_SYSTEM_RTC_EXPORT_H_

View file

@ -0,0 +1,197 @@
/*
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_RTC_EXPORT_TEMPLATE_H_
#define RTC_BASE_SYSTEM_RTC_EXPORT_TEMPLATE_H_
// clang-format off
// clang formating would cause cpplint errors in the macros below.
// Most of this was borrowed (with minor modifications) from Chromium's
// base/export_template.h.
// Synopsis
//
// This header provides macros for using RTC_EXPORT macros with explicit
// template instantiation declarations and definitions.
// Generally, the RTC_EXPORT macros are used at declarations,
// and GCC requires them to be used at explicit instantiation declarations,
// but MSVC requires __declspec(dllexport) to be used at the explicit
// instantiation definitions instead.
// Usage
//
// In a header file, write:
//
// extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT) foo<bar>;
//
// In a source file, write:
//
// template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) foo<bar>;
// Implementation notes
//
// On Windows, when building when RTC_EXPORT expands to __declspec(dllexport)),
// we want the two lines to expand to:
//
// extern template class foo<bar>;
// template class RTC_EXPORT foo<bar>;
//
// In all other cases (non-Windows, and Windows when RTC_EXPORT expands to
// __declspec(dllimport)), we want:
//
// extern template class RTC_EXPORT foo<bar>;
// template class foo<bar>;
//
// The implementation of this header uses some subtle macro semantics to
// detect what the provided RTC_EXPORT value was defined as and then
// to dispatch to appropriate macro definitions. Unfortunately,
// MSVC's C preprocessor is rather non-compliant and requires special
// care to make it work.
//
// Issue 1.
//
// #define F(x)
// F()
//
// MSVC emits warning C4003 ("not enough actual parameters for macro
// 'F'), even though it's a valid macro invocation. This affects the
// macros below that take just an "export" parameter, because export
// may be empty.
//
// As a workaround, we can add a dummy parameter and arguments:
//
// #define F(x,_)
// F(,)
//
// Issue 2.
//
// #define F(x) G##x
// #define Gj() ok
// F(j())
//
// The correct replacement for "F(j())" is "ok", but MSVC replaces it
// with "Gj()". As a workaround, we can pass the result to an
// identity macro to force MSVC to look for replacements again. (This
// is why RTC_EXPORT_TEMPLATE_STYLE_3 exists.)
#define RTC_EXPORT_TEMPLATE_DECLARE(export) \
RTC_EXPORT_TEMPLATE_INVOKE( \
DECLARE, \
RTC_EXPORT_TEMPLATE_STYLE(export, ), export) // NOLINT
#define RTC_EXPORT_TEMPLATE_DEFINE(export) \
RTC_EXPORT_TEMPLATE_INVOKE( \
DEFINE, \
RTC_EXPORT_TEMPLATE_STYLE(export, ), export) // NOLINT
// INVOKE is an internal helper macro to perform parameter replacements
// and token pasting to chain invoke another macro. E.g.,
// RTC_EXPORT_TEMPLATE_INVOKE(DECLARE, DEFAULT, RTC_EXPORT)
// will export to call
// RTC_EXPORT_TEMPLATE_DECLARE_DEFAULT(RTC_EXPORT, )
// (but with RTC_EXPORT expanded too).
#define RTC_EXPORT_TEMPLATE_INVOKE(which, style, export) \
RTC_EXPORT_TEMPLATE_INVOKE_2(which, style, export)
#define RTC_EXPORT_TEMPLATE_INVOKE_2(which, style, export) \
RTC_EXPORT_TEMPLATE_##which##_##style(export, )
// Default style is to apply the RTC_EXPORT macro at declaration sites.
#define RTC_EXPORT_TEMPLATE_DECLARE_DEFAULT(export, _) export
#define RTC_EXPORT_TEMPLATE_DEFINE_DEFAULT(export, _)
// The "MSVC hack" style is used when RTC_EXPORT is defined
// as __declspec(dllexport), which MSVC requires to be used at
// definition sites instead.
#define RTC_EXPORT_TEMPLATE_DECLARE_MSVC_HACK(export, _)
#define RTC_EXPORT_TEMPLATE_DEFINE_MSVC_HACK(export, _) export
// RTC_EXPORT_TEMPLATE_STYLE is an internal helper macro that identifies which
// export style needs to be used for the provided RTC_EXPORT macro definition.
// "", "__attribute__(...)", and "__declspec(dllimport)" are mapped
// to "DEFAULT"; while "__declspec(dllexport)" is mapped to "MSVC_HACK".
//
// It's implemented with token pasting to transform the __attribute__ and
// __declspec annotations into macro invocations. E.g., if RTC_EXPORT is
// defined as "__declspec(dllimport)", it undergoes the following sequence of
// macro substitutions:
// RTC_EXPORT_TEMPLATE_STYLE(RTC_EXPORT,)
// RTC_EXPORT_TEMPLATE_STYLE_2(__declspec(dllimport),)
// RTC_EXPORT_TEMPLATE_STYLE_3(
// RTC_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport))
// RTC_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport)
// RTC_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport
// DEFAULT
#define RTC_EXPORT_TEMPLATE_STYLE(export, _) \
RTC_EXPORT_TEMPLATE_STYLE_2(export, )
#define RTC_EXPORT_TEMPLATE_STYLE_2(export, _) \
RTC_EXPORT_TEMPLATE_STYLE_3( \
RTC_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA##export)
#define RTC_EXPORT_TEMPLATE_STYLE_3(style) style
// Internal helper macros for RTC_EXPORT_TEMPLATE_STYLE.
//
// XXX: C++ reserves all identifiers containing "__" for the implementation,
// but "__attribute__" and "__declspec" already contain "__" and the token-paste
// operator can only add characters; not remove them. To minimize the risk of
// conflict with implementations, we include "foj3FJo5StF0OvIzl7oMxA" (a random
// 128-bit string, encoded in Base64) in the macro name.
#define RTC_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA DEFAULT
#define RTC_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__( \
...) \
DEFAULT
#define RTC_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec(arg) \
RTC_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_##arg
// Internal helper macros for RTC_EXPORT_TEMPLATE_STYLE.
#define RTC_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport MSVC_HACK
#define RTC_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport DEFAULT
// Sanity checks.
//
// RTC_EXPORT_TEMPLATE_TEST uses the same macro invocation pattern as
// RTC_EXPORT_TEMPLATE_DECLARE and RTC_EXPORT_TEMPLATE_DEFINE do to check that
// they're working correctly. When they're working correctly, the sequence of
// macro replacements should go something like:
//
// RTC_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport));
//
// static_assert(RTC_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT,
// RTC_EXPORT_TEMPLATE_STYLE(__declspec(dllimport), ),
// __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(RTC_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT,
// DEFAULT, __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(RTC_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(
// __declspec(dllimport)), "__declspec(dllimport)");
//
// static_assert(true, "__declspec(dllimport)");
//
// When they're not working correctly, a syntax error should occur instead.
#define RTC_EXPORT_TEMPLATE_TEST(want, export) \
static_assert( \
RTC_EXPORT_TEMPLATE_INVOKE( \
TEST_##want, \
RTC_EXPORT_TEMPLATE_STYLE(export, ), export), #export) // NOLINT
#define RTC_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(...) true
#define RTC_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK(...) true
RTC_EXPORT_TEMPLATE_TEST(DEFAULT, ); // NOLINT
RTC_EXPORT_TEMPLATE_TEST(DEFAULT, __attribute__((visibility("default"))));
RTC_EXPORT_TEMPLATE_TEST(MSVC_HACK, __declspec(dllexport));
RTC_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport));
#undef RTC_EXPORT_TEMPLATE_TEST
#undef RTC_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT
#undef RTC_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK
// clang-format on
#endif // RTC_BASE_SYSTEM_RTC_EXPORT_TEMPLATE_H_

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_UNUSED_H_
#define RTC_BASE_SYSTEM_UNUSED_H_
// Prevent the compiler from warning about an unused variable. For example:
// int result = DoSomething();
// RTC_DCHECK(result == 17);
// RTC_UNUSED(result);
// Note: In most cases it is better to remove the unused variable rather than
// suppressing the compiler warning.
#ifndef RTC_UNUSED
#ifdef __cplusplus
#define RTC_UNUSED(x) static_cast<void>(x)
#else
#define RTC_UNUSED(x) (void)(x)
#endif
#endif // RTC_UNUSED
#endif // RTC_BASE_SYSTEM_UNUSED_H_

View file

@ -0,0 +1,23 @@
/*
* Copyright 2019 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/system/warn_current_thread_is_deadlocked.h"
#include "rtc_base/logging.h"
#include "sdk/android/native_api/stacktrace/stacktrace.h"
namespace webrtc {
void WarnThatTheCurrentThreadIsProbablyDeadlocked() {
RTC_LOG(LS_WARNING) << "Probable deadlock:";
RTC_LOG(LS_WARNING) << StackTraceToString(GetStackTrace());
}
} // namespace webrtc

View file

@ -0,0 +1,24 @@
/*
* Copyright 2019 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef RTC_BASE_SYSTEM_WARN_CURRENT_THREAD_IS_DEADLOCKED_H_
#define RTC_BASE_SYSTEM_WARN_CURRENT_THREAD_IS_DEADLOCKED_H_
namespace webrtc {
#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
void WarnThatTheCurrentThreadIsProbablyDeadlocked();
#else
inline void WarnThatTheCurrentThreadIsProbablyDeadlocked() {}
#endif
} // namespace webrtc
#endif // RTC_BASE_SYSTEM_WARN_CURRENT_THREAD_IS_DEADLOCKED_H_