summaryrefslogtreecommitdiffstats
path: root/security/libgnome-keyring/files/patch-egg_egg-secure-memory.h
blob: 89df7cdc758edb9b0ba6ae8d230ea9bbe0a0d417 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- egg/egg-secure-memory.h.orig    Wed Jun  8 10:00:06 2011
+++ egg/egg-secure-memory.h Sat Oct 27 14:36:16 2012
@@ -40,46 +40,58 @@
  * secure memory between threads:
  */
 
-extern void   egg_memory_lock (void);
+typedef struct {
+   void       (* lock)        (void);
+   void       (* unlock)      (void);
+   void *     (* fallback)    (void *pointer,
+                               size_t length);
+   void *        pool_data;
+   const char *  pool_version;
+} egg_secure_glob;
 
-extern void   egg_memory_unlock (void);
+#define EGG_SECURE_POOL_VER_STR             "1.0"
+#define EGG_SECURE_GLOBALS SECMEM_pool_data_v1_0
 
-/*
- * Allocation Fallbacks
- *
- * If we cannot allocate secure memory, then this function
- * (defined elsewhere) will be called which has a chance to
- * allocate other memory abort or do whatever.
- *
- * Same call semantics as realloc with regard to NULL and zeros
- */
-extern void*  egg_memory_fallback (void *p, size_t length);
+#define EGG_SECURE_DEFINE_GLOBALS(lock, unlock, fallback) \
+   egg_secure_glob EGG_SECURE_GLOBALS = { \
+       lock, unlock, fallback, NULL, EGG_SECURE_POOL_VER_STR };
 
-#define EGG_SECURE_GLIB_DEFINITIONS() \
+#define EGG_SECURE_DEFINE_GLIB_GLOBALS() \
    static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT; \
-   void egg_memory_lock (void) \
+   static void egg_memory_lock (void) \
        { g_static_mutex_lock (&memory_mutex); } \
-   void egg_memory_unlock (void) \
+   static void egg_memory_unlock (void) \
        { g_static_mutex_unlock (&memory_mutex); } \
-   void* egg_memory_fallback (void *p, size_t sz) \
-       { return g_realloc (p, sz); } \
+   EGG_SECURE_DEFINE_GLOBALS (egg_memory_lock, egg_memory_unlock, g_realloc);
 
+extern egg_secure_glob EGG_SECURE_GLOBALS;
+
 /*
  * Main functionality
  *
  * Allocations return NULL on failure.
  */
 
-#define GKR_SECURE_USE_FALLBACK     0x0001
+#define EGG_SECURE_USE_FALLBACK     0x0001
 
-void*  egg_secure_alloc        (size_t length);
+#define EGG_SECURE_DECLARE(tag) \
+   static inline void* egg_secure_alloc (size_t length) { \
+       return egg_secure_alloc_full (G_STRINGIFY (tag), length, EGG_SECURE_USE_FALLBACK); \
+   } \
+   static inline void* egg_secure_realloc (void *p, size_t length) { \
+       return egg_secure_realloc_full (G_STRINGIFY (tag), p, length, EGG_SECURE_USE_FALLBACK); \
+   } \
+   static inline void* egg_secure_strdup (const char *str) { \
+       return egg_secure_strdup_full (G_STRINGIFY (tag), str, EGG_SECURE_USE_FALLBACK); \
+   } \
+   static inline void* egg_secure_strndup (const char *str, size_t length) { \
+       return egg_secure_strndup_full (G_STRINGIFY (tag), str, length, EGG_SECURE_USE_FALLBACK); \
+   }
 
-void*  egg_secure_alloc_full   (size_t length, int flags);
+void*  egg_secure_alloc_full   (const char *tag, size_t length, int options);
 
-void*  egg_secure_realloc      (void *p, size_t length);
+void*  egg_secure_realloc_full (const char *tag, void *p, size_t length, int options);
 
-void*  egg_secure_realloc_full (void *p, size_t length, int fallback);
-
 void   egg_secure_free         (void* p);
 
 void   egg_secure_free_full    (void* p, int fallback);
@@ -90,12 +102,20 @@ int    egg_secure_check        (const void* p);
 
 void   egg_secure_validate     (void);
 
-void   egg_secure_dump_blocks  (void);
+char*  egg_secure_strdup_full  (const char *tag, const char *str, int options);
 
-char*  egg_secure_strdup       (const char *str);
+char*  egg_secure_strndup_full (const char *tag, const char *str, size_t length, int options);
 
 void   egg_secure_strclear     (char *str);
 
 void   egg_secure_strfree      (char *str);
+
+typedef struct {
+   const char *tag;
+   size_t request_length;
+   size_t block_length;
+} egg_secure_rec;
+
+egg_secure_rec *   egg_secure_records    (unsigned int *count);
 
 #endif /* EGG_SECURE_MEMORY_H */