| 1 | /* libc-internal interface for tagged (colored) memory support. |
| 2 | Copyright (C) 2020-2022 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef _GENERIC_LIBC_MTAG_H |
| 20 | #define _GENERIC_LIBC_MTAG_H 1 |
| 21 | |
| 22 | /* Generic bindings for systems that do not support memory tagging. */ |
| 23 | |
| 24 | /* Used to ensure additional alignment when objects need to have distinct |
| 25 | tags. */ |
| 26 | #define __MTAG_GRANULE_SIZE 1 |
| 27 | |
| 28 | /* Non-zero if memory obtained via morecore (sbrk) is not tagged. */ |
| 29 | #define __MTAG_SBRK_UNTAGGED 0 |
| 30 | |
| 31 | /* Extra flags to pass to mmap() to request a tagged region of memory. */ |
| 32 | #define __MTAG_MMAP_FLAGS 0 |
| 33 | |
| 34 | /* Memory tagging target hooks are only called when memory tagging is |
| 35 | enabled at runtime. The generic definitions here must not be used. */ |
| 36 | void __libc_mtag_link_error (void); |
| 37 | |
| 38 | /* Set the tags for a region of memory, which must have size and alignment |
| 39 | that are multiples of __MTAG_GRANULE_SIZE. Size cannot be zero. */ |
| 40 | static inline void * |
| 41 | __libc_mtag_tag_region (void *p, size_t n) |
| 42 | { |
| 43 | __libc_mtag_link_error (); |
| 44 | return p; |
| 45 | } |
| 46 | |
| 47 | /* Optimized equivalent to __libc_mtag_tag_region followed by memset to 0. */ |
| 48 | static inline void * |
| 49 | __libc_mtag_tag_zero_region (void *p, size_t n) |
| 50 | { |
| 51 | __libc_mtag_link_error (); |
| 52 | return memset (p, 0, n); |
| 53 | } |
| 54 | |
| 55 | /* Convert address P to a pointer that is tagged correctly for that |
| 56 | location. */ |
| 57 | static inline void * |
| 58 | __libc_mtag_address_get_tag (void *p) |
| 59 | { |
| 60 | __libc_mtag_link_error (); |
| 61 | return p; |
| 62 | } |
| 63 | |
| 64 | /* Assign a new (random) tag to a pointer P (does not adjust the tag on |
| 65 | the memory addressed). */ |
| 66 | static inline void * |
| 67 | __libc_mtag_new_tag (void *p) |
| 68 | { |
| 69 | __libc_mtag_link_error (); |
| 70 | return p; |
| 71 | } |
| 72 | |
| 73 | #endif /* _GENERIC_LIBC_MTAG_H */ |
| 74 | |