| 1 | /* Repeating a memory blob, with alias mapping optimization. |
| 2 | Copyright (C) 2018-2021 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 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef SUPPORT_BLOB_REPEAT_H |
| 20 | #define SUPPORT_BLOB_REPEAT_H |
| 21 | |
| 22 | #include <stdbool.h> |
| 23 | #include <stddef.h> |
| 24 | |
| 25 | struct support_blob_repeat |
| 26 | { |
| 27 | void *start; |
| 28 | size_t size; |
| 29 | bool use_malloc; |
| 30 | }; |
| 31 | |
| 32 | /* Return an allocation of COUNT elements, each of ELEMENT_SIZE bytes, |
| 33 | initialized with the bytes starting at ELEMENT. The memory is |
| 34 | writable (and thus counts towards the commit charge). In case of |
| 35 | on error, all members of the return struct are zero-initialized, |
| 36 | and errno is set accordingly. */ |
| 37 | struct support_blob_repeat support_blob_repeat_allocate (const void *element, |
| 38 | size_t element_size, |
| 39 | size_t count); |
| 40 | |
| 41 | /* Like support_blob_repeat_allocate, except that copy-on-write |
| 42 | semantics are disabled. This means writing to one part of the blob |
| 43 | can affect other parts. It is possible to map non-shared memory |
| 44 | over parts of the resulting blob using MAP_ANONYMOUS | MAP_FIXED |
| 45 | | MAP_PRIVATE, so that writes to these parts do not affect |
| 46 | others. */ |
| 47 | struct support_blob_repeat support_blob_repeat_allocate_shared |
| 48 | (const void *element, size_t element_size, size_t count); |
| 49 | |
| 50 | /* Deallocate the blob created by support_blob_repeat_allocate or |
| 51 | support_blob_repeat_allocate_shared. */ |
| 52 | void support_blob_repeat_free (struct support_blob_repeat *); |
| 53 | |
| 54 | #endif /* SUPPORT_BLOB_REPEAT_H */ |
| 55 | |