Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fx_memory_wrappers.h
Go to the documentation of this file.
1// Copyright 2019 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CORE_FXCRT_FX_MEMORY_WRAPPERS_H_
6#define CORE_FXCRT_FX_MEMORY_WRAPPERS_H_
7
8#include <limits>
9#include <type_traits>
10#include <utility>
11
12#include "core/fxcrt/fx_memory.h"
13
14// Used with std::unique_ptr to FX_Free raw memory.
16 inline void operator()(void* ptr) const { FX_Free(ptr); }
17};
18
19// Escape hatch mechanism to allow non_arithmetic types into data partition.
20template <typename T>
21struct IsFXDataPartitionException : std::false_type {};
22
23// Use with caution. No further checks are made to see if `T` is appropriate
24// for the Data Partition (e.g. no pointers, strings, vtables, etc.). This
25// declaration must occur in the top-level namespace.
26#define FX_DATA_PARTITION_EXCEPTION(T)
27 template <>
28 struct IsFXDataPartitionException<T> : std::true_type {}
29
30// Allocators for mapping STL containers onto Partition Alloc.
31// Otherwise, replacing e.g. the FX_AllocUninit/FX_Free pairs with STL may
32// undo some of the nice segregation that we get from PartitionAlloc.
33template <class T, void* Alloc(size_t, size_t), void Free(void*)>
35 public:
36#if !defined(COMPILER_MSVC) || defined(NDEBUG)
37 static_assert(std::is_arithmetic<T>::value || std::is_enum<T>::value ||
39 "Only numeric types allowed in this partition");
40#endif
41
42 using value_type = T;
43 using pointer = T*;
44 using const_pointer = const T*;
45 using reference = T&;
46 using const_reference = const T&;
49
50 template <class U>
51 struct rebind {
52 using other = FxPartitionAllocAllocator<U, Alloc, Free>;
53 };
54
55 FxPartitionAllocAllocator() noexcept = default;
57 default;
59
60 template <typename U>
62 const FxPartitionAllocAllocator<U, Alloc, Free>& other) noexcept {}
63
64 pointer address(reference x) const noexcept { return &x; }
65 const_pointer address(const_reference x) const noexcept { return &x; }
66 pointer allocate(size_type n, const void* hint = 0) {
67 return static_cast<pointer>(Alloc(n, sizeof(value_type)));
68 }
69 void deallocate(pointer p, size_type n) { Free(p); }
70 size_type max_size() const noexcept {
71 return std::numeric_limits<size_type>::max() / sizeof(value_type);
72 }
73
74 template <class U, class... Args>
75 void construct(U* p, Args&&... args) {
76 new (reinterpret_cast<void*>(p)) U(std::forward<Args>(args)...);
77 }
78
79 template <class U>
80 void destroy(U* p) {
81 p->~U();
82 }
83
84 // There's no state, so they are all the same,
85 bool operator==(const FxPartitionAllocAllocator& that) { return true; }
86 bool operator!=(const FxPartitionAllocAllocator& that) { return false; }
87};
88
89// Used to put backing store for std::vector<> and such into the
90// general partition, ensuring they contain data only.
91template <typename T,
92 typename = std::enable_if_t<std::is_arithmetic<T>::value ||
93 std::is_enum<T>::value ||
94 IsFXDataPartitionException<T>::value>>
95using FxAllocAllocator = FxPartitionAllocAllocator<T,
96 pdfium::internal::AllocOrDie,
97 pdfium::internal::Dealloc>;
98
99// Used to put backing store for std::string<> and std::ostringstream<>
100// into the string partition.
101template <typename T>
102using FxStringAllocator =
103 FxPartitionAllocAllocator<T,
104 pdfium::internal::StringAllocOrDie,
105 pdfium::internal::StringDealloc>;
106
107#endif // CORE_FXCRT_FX_MEMORY_WRAPPERS_H_
T & reference
Definition span.h:195
constexpr span(T(&array)[N]) noexcept
Definition span.h:211
constexpr reverse_iterator rend() const noexcept
Definition span.h:348
span last() const
Definition span.h:283
constexpr reverse_iterator rbegin() const noexcept
Definition span.h:345
T * iterator
Definition span.h:196
constexpr const_reverse_iterator crend() const noexcept
Definition span.h:355
span first() const
Definition span.h:269
std::reverse_iterator< iterator > reverse_iterator
Definition span.h:198
const span first(size_t count) const
Definition span.h:276
typename std::remove_cv< T >::type value_type
Definition span.h:193
span & operator=(const span &other) noexcept
Definition span.h:258
constexpr const_iterator cbegin() const noexcept
Definition span.h:342
constexpr const_iterator cend() const noexcept
Definition span.h:343
constexpr const_reverse_iterator crbegin() const noexcept
Definition span.h:352
const span last(size_t count) const
Definition span.h:290
constexpr bool empty() const noexcept
Definition span.h:316
constexpr size_t size() const noexcept
Definition span.h:314
constexpr span(Container &container)
Definition span.h:238
friend constexpr span< U > make_span(U *data, size_t size) noexcept
span subspan() const
Definition span.h:297
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition span.h:199
const span subspan(size_t pos, size_t count=dynamic_extent) const
Definition span.h:305
constexpr iterator begin() const noexcept
Definition span.h:337
constexpr size_t size_bytes() const noexcept
Definition span.h:315
constexpr span() noexcept=default
span(const Container &container)
Definition span.h:245
constexpr span(std::array< T, N > &array) noexcept
Definition span.h:216
T * pointer
Definition span.h:194
constexpr T & back() const noexcept
Definition span.h:329
constexpr span(const std::array< std::remove_cv_t< T >, N > &array) noexcept
Definition span.h:221
constexpr T * data() const noexcept
Definition span.h:334
constexpr T & front() const noexcept
Definition span.h:324
constexpr span(const span &other) noexcept=default
UNSAFE_BUFFER_USAGE constexpr span(T *data, size_t size) noexcept
Definition span.h:204
constexpr span(const span< U, M, R > &other)
Definition span.h:255
T & operator[](size_t index) const noexcept
Definition span.h:319
constexpr iterator end() const noexcept
Definition span.h:338
const T * const_iterator
Definition span.h:197
~span() noexcept=default
#define UNSAFE_BUFFERS(...)
#define GSL_POINTER
#define TRIVIAL_ABI
#define UNLIKELY(x)
#define HAS_ATTRIBUTE(x)
#define UNSAFE_BUFFER_USAGE
void CRYPT_MD5Finish(CRYPT_md5_context *context, pdfium::span< uint8_t, 16 > digest)
Definition fx_crypt.cpp:203
#define P(a, b, c, d, k, s, t)
void CRYPT_MD5Generate(pdfium::span< const uint8_t > data, pdfium::span< uint8_t, 16 > digest)
Definition fx_crypt.cpp:219
#define S(x, n)
void CRYPT_ArcFourCryptBlock(pdfium::span< uint8_t > data, pdfium::span< const uint8_t > key)
Definition fx_crypt.cpp:157
void CRYPT_ArcFourSetup(CRYPT_rc4_context *context, pdfium::span< const uint8_t > key)
Definition fx_crypt.cpp:131
void CRYPT_MD5Update(CRYPT_md5_context *context, pdfium::span< const uint8_t > data)
Definition fx_crypt.cpp:175
void CRYPT_ArcFourCrypt(CRYPT_rc4_context *context, pdfium::span< uint8_t > data)
Definition fx_crypt.cpp:146
CRYPT_md5_context CRYPT_MD5Start()
Definition fx_crypt.cpp:164
void CRYPT_AESEncrypt(CRYPT_aes_context *ctx, pdfium::span< uint8_t > dest, pdfium::span< const uint8_t > src)
void CRYPT_AESSetIV(CRYPT_aes_context *ctx, const uint8_t *iv)
void CRYPT_AESDecrypt(CRYPT_aes_context *ctx, uint8_t *dest, const uint8_t *src, uint32_t size)
void CRYPT_AESSetKey(CRYPT_aes_context *ctx, const uint8_t *key, uint32_t keylen)
void CRYPT_SHA512Update(CRYPT_sha2_context *context, pdfium::span< const uint8_t > data)
void CRYPT_SHA384Update(CRYPT_sha2_context *context, pdfium::span< const uint8_t > data)
DataVector< uint8_t > CRYPT_SHA256Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA1Finish(CRYPT_sha1_context *context, pdfium::span< uint8_t, 20 > digest)
void CRYPT_SHA1Update(CRYPT_sha1_context *context, pdfium::span< const uint8_t > data)
void CRYPT_SHA512Finish(CRYPT_sha2_context *context, pdfium::span< uint8_t, 64 > digest)
DataVector< uint8_t > CRYPT_SHA384Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA384Start(CRYPT_sha2_context *context)
void CRYPT_SHA384Finish(CRYPT_sha2_context *context, pdfium::span< uint8_t, 48 > digest)
void CRYPT_SHA512Start(CRYPT_sha2_context *context)
DataVector< uint8_t > CRYPT_SHA1Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA256Start(CRYPT_sha2_context *context)
DataVector< uint8_t > CRYPT_SHA512Generate(pdfium::span< const uint8_t > data)
void CRYPT_SHA1Start(CRYPT_sha1_context *context)
void CRYPT_SHA256Finish(CRYPT_sha2_context *context, pdfium::span< uint8_t, 32 > digest)
void CRYPT_SHA256Update(CRYPT_sha2_context *context, pdfium::span< const uint8_t > data)
#define IMMEDIATE_CRASH_ALWAYS_INLINE
#define TRAP_SEQUENCE_()
std::is_integral< decltype(std::declval< Container >().size())> ContainerHasIntegralSize
Definition span.h:63
IsSpanImpl< typename std::decay< T >::type > IsSpan
Definition span.h:43
std::is_convertible< From *, To * > IsLegalSpanConversion
Definition span.h:55
IsStdArrayImpl< typename std::decay< T >::type > IsStdArray
Definition span.h:52
constexpr span< T > make_span(T(&array)[N]) noexcept
Definition span.h:374
span< char > as_writable_chars(span< T, N, P > s) noexcept
Definition span.h:427
span< const uint8_t > as_bytes(span< T, N, P > s) noexcept
Definition span.h:400
constexpr size_t dynamic_extent
Definition span.h:24
static constexpr span< T > span_from_ref(T &single_object) noexcept
Definition span.h:437
static constexpr span< const uint8_t > byte_span_from_ref(const T &single_object) noexcept
Definition span.h:446
UNSAFE_BUFFER_USAGE constexpr span< T > make_span(T *data, size_t size) noexcept
Definition span.h:369
span< const uint8_t > as_byte_span(T &&arg)
Definition span.h:465
span< const char > as_chars(span< T, N, P > s) noexcept
Definition span.h:417
span< const uint8_t > as_byte_span(const T &arg)
Definition span.h:461
UNOWNED_PTR_EXCLUSION T * DefaultSpanInternalPtr
Definition span.h:27
span< uint8_t > as_writable_bytes(span< T, N, P > s) noexcept
Definition span.h:410
constexpr span< T > make_span(std::array< T, N > &array) noexcept
Definition span.h:379
constexpr span< T > make_span(Container &container)
Definition span.h:386
constexpr span< uint8_t > as_writable_byte_span(T &&arg)
Definition span.h:475
IMMEDIATE_CRASH_ALWAYS_INLINE void ImmediateCrash()
static constexpr span< uint8_t > byte_span_from_ref(T &single_object) noexcept
Definition span.h:451
constexpr span< T > make_span(const Container &container)
Definition span.h:394
#define CHECK(cvref)
#define assert
#define __has_attribute(x)
std::array< uint32_t, kMaxNb > iv
std::array< uint32_t, kSchedSize > invkeysched
static constexpr int kMaxNr
static constexpr int kSchedSize
static constexpr int kMaxNb
std::array< uint32_t, kSchedSize > keysched
uint8_t buffer[64]
Definition fx_crypt.h:28
std::array< uint32_t, 4 > state
Definition fx_crypt.h:27
std::array< uint32_t, 2 > total
Definition fx_crypt.h:26
std::array< int32_t, kPermutationLength > m
Definition fx_crypt.h:22
static constexpr int32_t kPermutationLength
Definition fx_crypt.h:18
std::array< uint32_t, 5 > h
std::array< uint8_t, 64 > block
std::array< uint64_t, 8 > state
uint8_t buffer[128]
void operator()(void *ptr) const
FxPartitionAllocAllocator< U, Alloc, Free > other
pointer allocate(size_type n, const void *hint=0)
void deallocate(pointer p, size_type n)
const_pointer address(const_reference x) const noexcept
FxPartitionAllocAllocator() noexcept=default
size_type max_size() const noexcept
~FxPartitionAllocAllocator()=default
pointer address(reference x) const noexcept
FxPartitionAllocAllocator(const FxPartitionAllocAllocator< U, Alloc, Free > &other) noexcept
bool operator!=(const FxPartitionAllocAllocator &that)
void construct(U *p, Args &&... args)
bool operator==(const FxPartitionAllocAllocator &that)
FxPartitionAllocAllocator(const FxPartitionAllocAllocator &other) noexcept=default
#define UNOWNED_PTR_EXCLUSION