1/* gtksecurememoryprivate.h - Allocator for non-pageable memory
2
3 Copyright 2007 Stefan Walter
4 Copyright 2020 GNOME Foundation
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7
8 The Gnome Keyring Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 The Gnome Keyring Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public
19 License along with the Gnome Library; see the file COPYING.LIB. If not,
20 see <http://www.gnu.org/licenses/>.
21
22 Author: Stef Walter <stef@memberwebs.com>
23*/
24
25#pragma once
26
27#include <stdlib.h>
28#include <glib.h>
29
30/*
31 * Main functionality
32 *
33 * Allocations return NULL on failure.
34 */
35
36#define GTK_SECURE_USE_FALLBACK 0x0001
37
38void * gtk_secure_alloc_full (const char *tag,
39 size_t length,
40 int options);
41
42void * gtk_secure_realloc_full (const char *tag,
43 void *p,
44 size_t length,
45 int options);
46
47void gtk_secure_free (void *p);
48
49void gtk_secure_free_full (void *p,
50 int fallback);
51
52void gtk_secure_clear (void *p,
53 size_t length);
54
55int gtk_secure_check (const void *p);
56
57void gtk_secure_validate (void);
58
59char * gtk_secure_strdup_full (const char *tag,
60 const char *str,
61 int options);
62
63char * gtk_secure_strndup_full (const char *tag,
64 const char *str,
65 size_t length,
66 int options);
67
68void gtk_secure_strclear (char *str);
69
70void gtk_secure_strfree (char *str);
71
72/* Simple wrappers */
73
74static inline void *gtk_secure_alloc (size_t length) {
75 return gtk_secure_alloc_full (tag: "gtk", length, GTK_SECURE_USE_FALLBACK);
76}
77
78static inline void *gtk_secure_realloc (void *p, size_t length) {
79 return gtk_secure_realloc_full (tag: "gtk", p, length, GTK_SECURE_USE_FALLBACK);
80}
81
82static inline void *gtk_secure_strdup (const char *str) {
83 return gtk_secure_strdup_full (tag: "gtk", str, GTK_SECURE_USE_FALLBACK);
84}
85
86static inline void *gtk_secure_strndup (const char *str, size_t length) {
87 return gtk_secure_strndup_full (tag: "gtk", str, length, GTK_SECURE_USE_FALLBACK);
88}
89
90typedef struct {
91 const char *tag;
92 size_t request_length;
93 size_t block_length;
94} gtk_secure_rec;
95
96gtk_secure_rec * gtk_secure_records (unsigned int *count);
97

source code of gtk/gtk/gtksecurememoryprivate.h