Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
memory_ops.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/memory_ops.h
10 //! @brief Memory operations like poisoning, canary values, etc.
11 
12 #ifndef ROC_CORE_MEMORY_OPS_H_
13 #define ROC_CORE_MEMORY_OPS_H_
14 
15 #include "roc_core/stddefs.h"
16 
17 namespace roc {
18 namespace core {
19 
20 //! Memory operations.
21 class MemoryOps {
22 public:
23  //! Poison memory that is going to be used.
24  //! Helps catching uninitialized access bugs.
25  static void poison_before_use(void* data, size_t size);
26 
27  //! Poison memory that is no more used.
28  //! Helps catching use after free bugs.
29  static void poison_after_use(void* data, size_t size);
30 
31  //! Prepare canary memory.
32  //! Helps catching buffer overflow/underflow bugs.
33  static void prepare_canary(void* data, size_t size);
34 
35  //! Check canary memory.
36  //! @returns true if passed.
37  static bool check_canary(void* data, size_t size);
38 
39  //! Some good filler patterns for memory.
40  //! If we fill memory with these values and interpret it as 16-bit or 32-bit
41  //! integers, or as floats, the values will be rather high and will sound
42  //! loudly when trying to play them on sound card.
43  //! We use a few different patterns to make it easy to distinguish between
44  //! them in debugger.
45  enum {
46  Pattern_BeforeUse = 0x7a,
47  Pattern_AfterUse = 0x7d,
48  Pattern_Canary = 0x7b,
49  };
50 };
51 
52 } // namespace core
53 } // namespace roc
54 
55 #endif // ROC_CORE_MEMORY_OPS_H_
Memory operations.
Definition: memory_ops.h:21
static bool check_canary(void *data, size_t size)
Check canary memory.
static void poison_before_use(void *data, size_t size)
Poison memory that is going to be used. Helps catching uninitialized access bugs.
static void poison_after_use(void *data, size_t size)
Poison memory that is no more used. Helps catching use after free bugs.
static void prepare_canary(void *data, size_t size)
Prepare canary memory. Helps catching buffer overflow/underflow bugs.
Root namespace.
Commonly used types and functions.