Debian Codegraph @

crt/s2n/utils/s2n_mem.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #pragma once
17
18 #include <stdint.h>
19
20 #include "utils/s2n_blob.h"
21
22 int s2n_mem_init(void);
23 bool s2n_mem_is_init(void);
24 uint32_t s2n_mem_get_page_size(void);
25 int s2n_mem_cleanup(void);
26
27 /*
28 * Generally, s2n_realloc is preferred over s2n_alloc. This is because calling
29 * s2n_alloc on a blob that already has memory allocated will leak memory.
30 */
31 int S2N_RESULT_MUST_USE s2n_alloc(struct s2n_blob *b, uint32_t size);
32 int S2N_RESULT_MUST_USE s2n_realloc(struct s2n_blob *b, uint32_t size);
33 int s2n_free(struct s2n_blob *b);
34 int s2n_free_without_wipe(struct s2n_blob *b);
35 int s2n_free_object(uint8_t **p_data, uint32_t size);
36 int S2N_RESULT_MUST_USE s2n_dup(struct s2n_blob *from, struct s2n_blob *to);
37
38 /* Unlike free, s2n_free_or_wipe accepts static blobs.
39 * It frees allocated blobs and wipes static blobs.
40 *
41 * This is mostly useful for some of the s2n-tls shared secret generation logic,
42 * which allocates memory for some algorithms and uses static memory for others.
43 *
44 * Prefer s2n_free. Only use this method if completely necessary.
45 */
46 int s2n_free_or_wipe(struct s2n_blob *b);
47
48 S2N_RESULT s2n_mem_override_callbacks(s2n_mem_init_callback mem_init_callback, s2n_mem_cleanup_callback mem_cleanup_callback,
49 s2n_mem_malloc_callback mem_malloc_callback, s2n_mem_free_callback mem_free_callback);
50 S2N_RESULT s2n_mem_get_callbacks(s2n_mem_init_callback *mem_init_callback, s2n_mem_cleanup_callback *mem_cleanup_callback,
51 s2n_mem_malloc_callback *mem_malloc_callback, s2n_mem_free_callback *mem_free_callback);