diff options
author | NIIBE Yutaka <[email protected]> | 2018-09-06 01:03:22 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2018-09-06 01:16:46 +0000 |
commit | c6b7bbe9136854bfb4f7d7a0f384dd41d9f6945d (patch) | |
tree | 8f6198eea073847548d868faf2c46b2d91b04bb7 | |
parent | Copy definitions from libgcrypt/src/g10lib.h. (diff) | |
download | libgpg-error-c6b7bbe9136854bfb4f7d7a0f384dd41d9f6945d.tar.gz libgpg-error-c6b7bbe9136854bfb4f7d7a0f384dd41d9f6945d.zip |
secmem: Export symbols and the interface.
* src/Makefile.am (libgpg_error_la_SOURCES): Add secmem.c and secmem.h.
* src/gpg-error.def.in: Add secmem symbols.
* src/gpg-error.vers: Likewise.
* src/gpg-error.h.in: Add secmem functions and macros.
* src/secmem.h: Move internal prototypes to ...
* src/gpgrt-int.h: ... here.
* src/visibility.c: Add external functions.
* src/visibility.h: Declare secmem functions.
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/gpg-error.def.in | 10 | ||||
-rw-r--r-- | src/gpg-error.h.in | 21 | ||||
-rw-r--r-- | src/gpg-error.vers | 10 | ||||
-rw-r--r-- | src/gpgrt-int.h | 13 | ||||
-rw-r--r-- | src/secmem.h | 18 | ||||
-rw-r--r-- | src/visibility.c | 59 | ||||
-rw-r--r-- | src/visibility.h | 22 |
8 files changed, 136 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index fcfbb83..294bc27 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -187,6 +187,7 @@ libgpg_error_la_SOURCES = gettext.h $(arch_sources) \ estream.c estream-printf.c estream-printf.h \ strsource.c strerror.c code-to-errno.c code-from-errno.c \ visibility.c visibility.h \ + secmem.c secmem.h \ sysutils.c \ syscall-clamp.c \ logging.c \ diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in index 67bb12e..f4f3668 100644 --- a/src/gpg-error.def.in +++ b/src/gpg-error.def.in @@ -218,5 +218,15 @@ EXPORTS gpgrt_b64enc_write @167 gpgrt_b64enc_finish @168 + gpgrt_secmem_init @169 + gpgrt_secmem_term @170 + gpgrt_secmem_malloc @171 + gpgrt_secmem_realloc @172 + gpgrt_secmem_free @173 + gpgrt_secmem_dump_stats @174 + gpgrt_secmem_set_auto_expand @175 + gpgrt_secmem_set_flags @176 + gpgrt_secmem_get_flags @177 + gpgrt_private_is_secure @178 ;; end of file with public symbols for Windows. diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in index 8bcafcc..46d4ea7 100644 --- a/src/gpg-error.h.in +++ b/src/gpg-error.h.in @@ -1270,7 +1270,28 @@ const char *gpgrt_strusage (int level); void gpgrt_set_strusage (const char *(*f)(int)); void gpgrt_set_usage_outfnc (int (*f)(int, const char *)); void gpgrt_set_fixed_string_mapper (const char *(*f)(const char*)); + +/* + * secmem functions. + */ +/* Flags for _gpgrt_secmem_{set,get}_flags. */ +#define GPGRT_SECMEM_FLAG_NO_WARNING (1 << 0) +#define GPGRT_SECMEM_FLAG_SUSPEND_WARNING (1 << 1) +#define GPGRT_SECMEM_FLAG_NOT_LOCKED (1 << 2) +#define GPGRT_SECMEM_FLAG_NO_MLOCK (1 << 3) +#define GPGRT_SECMEM_FLAG_NO_PRIV_DROP (1 << 4) + +void gpgrt_secmem_init (size_t npool); +void gpgrt_secmem_term (void); +void *gpgrt_secmem_malloc (size_t size, int xhint) GPGRT_ATTR_MALLOC; +void *gpgrt_secmem_realloc (void *a, size_t newsize, int xhint); +int gpgrt_secmem_free (void *a); +void gpgrt_secmem_dump_stats (int extended); +void gpgrt_secmem_set_auto_expand (unsigned int chunksize); +void gpgrt_secmem_set_flags (unsigned flags); +unsigned gpgrt_secmem_get_flags (void); +int gpgrt_private_is_secure (const void *p); #ifdef __cplusplus diff --git a/src/gpg-error.vers b/src/gpg-error.vers index 201b784..4e58300 100644 --- a/src/gpg-error.vers +++ b/src/gpg-error.vers @@ -190,6 +190,16 @@ GPG_ERROR_1.0 { gpgrt_b64enc_write; gpgrt_b64enc_finish; + gpgrt_secmem_init; + gpgrt_secmem_term; + gpgrt_secmem_malloc; + gpgrt_secmem_realloc; + gpgrt_secmem_free; + gpgrt_secmem_dump_stats; + gpgrt_secmem_set_auto_expand; + gpgrt_secmem_set_flags; + gpgrt_secmem_get_flags; + gpgrt_private_is_secure; local: *; diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h index 34e494c..2cc3a4c 100644 --- a/src/gpgrt-int.h +++ b/src/gpgrt-int.h @@ -742,6 +742,19 @@ void _gpgrt_set_usage_outfnc (int (*fnc)(int, const char *)); void _gpgrt_set_fixed_string_mapper (const char *(*f)(const char*)); +/* + * Local prototypes for secmem. + */ +void _gpgrt_secmem_init (size_t npool); +void _gpgrt_secmem_term (void); +void *_gpgrt_secmem_malloc (size_t size, int xhint) GPGRT_ATTR_MALLOC; +void *_gpgrt_secmem_realloc (void *a, size_t newsize, int xhint); +int _gpgrt_secmem_free (void *a); +void _gpgrt_secmem_dump_stats (int extended); +void _gpgrt_secmem_set_auto_expand (unsigned int chunksize); +void _gpgrt_secmem_set_flags (unsigned flags); +unsigned _gpgrt_secmem_get_flags (void); +int _gpgrt_private_is_secure (const void *p); /* * Internal platform abstraction functions (sysutils.c) diff --git a/src/secmem.h b/src/secmem.h index cdab761..31b2b9b 100644 --- a/src/secmem.h +++ b/src/secmem.h @@ -23,24 +23,6 @@ #ifndef G10_SECMEM_H #define G10_SECMEM_H 1 -void _gpgrt_secmem_init (size_t npool); -void _gpgrt_secmem_term (void); -void *_gpgrt_secmem_malloc (size_t size, int xhint) GPGRT_ATTR_MALLOC; -void *_gpgrt_secmem_realloc (void *a, size_t newsize, int xhint); -int _gpgrt_secmem_free (void *a); -void _gpgrt_secmem_dump_stats (int extended); -void _gpgrt_secmem_set_auto_expand (unsigned int chunksize); -void _gpgrt_secmem_set_flags (unsigned flags); -unsigned _gpgrt_secmem_get_flags(void); -int _gpgrt_private_is_secure (const void *p); - -/* Flags for _gpgrt_secmem_{set,get}_flags. */ -#define GPGRT_SECMEM_FLAG_NO_WARNING (1 << 0) -#define GPGRT_SECMEM_FLAG_SUSPEND_WARNING (1 << 1) -#define GPGRT_SECMEM_FLAG_NOT_LOCKED (1 << 2) -#define GPGRT_SECMEM_FLAG_NO_MLOCK (1 << 3) -#define GPGRT_SECMEM_FLAG_NO_PRIV_DROP (1 << 4) - #if __GNUC__ >= 3 #define LIKELY( expr ) __builtin_expect( !!(expr), 1 ) #define UNLIKELY( expr ) __builtin_expect( !!(expr), 0 ) diff --git a/src/visibility.c b/src/visibility.c index 6f8bb24..e11dc98 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -1122,6 +1122,65 @@ gpgrt_set_fixed_string_mapper (const char *(*f)(const char*)) } +void +gpgrt_secmem_init (size_t n) +{ + _gpgrt_secmem_init (n); +} + +void +gpgrt_secmem_term (void) +{ + _gpgrt_secmem_term (); +} + +void * +gpgrt_secmem_malloc (size_t size, int xhint) +{ + return _gpgrt_secmem_malloc (size, xhint); +} + +void * +gpgrt_secmem_realloc (void *a, size_t newsize, int xhint) +{ + return _gpgrt_secmem_realloc (a, newsize, xhint); +} + +int +gpgrt_secmem_free (void *a) +{ + return _gpgrt_secmem_free (a); +} + +void +gpgrt_secmem_dump_stats (int extended) +{ + _gpgrt_secmem_dump_stats (extended); +} + +void +gpgrt_secmem_set_auto_expand (unsigned int chunksize) +{ + _gpgrt_secmem_set_auto_expand (chunksize); +} + +void +gpgrt_secmem_set_flags (unsigned flags) +{ + _gpgrt_secmem_set_flags (flags); +} + +unsigned +gpgrt_secmem_get_flags (void) +{ + return _gpgrt_secmem_get_flags (); +} + +int +gpgrt_private_is_secure (const void *p) +{ + return _gpgrt_private_is_secure (p); +} /* For consistency reasons we use function wrappers also for Windows * specific function despite that they are technically not needed. */ diff --git a/src/visibility.h b/src/visibility.h index cfa32e5..47ade34 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -209,6 +209,17 @@ MARK_VISIBLE (gpgrt_set_strusage) MARK_VISIBLE (gpgrt_set_fixed_string_mapper); MARK_VISIBLE (gpgrt_set_usage_outfnc); +MARK_VISIBLE (gpgrt_secmem_init); +MARK_VISIBLE (gpgrt_secmem_term); +MARK_VISIBLE (gpgrt_secmem_malloc); +MARK_VISIBLE (gpgrt_secmem_realloc); +MARK_VISIBLE (gpgrt_secmem_free); +MARK_VISIBLE (gpgrt_secmem_dump_stats); +MARK_VISIBLE (gpgrt_secmem_set_auto_expand); +MARK_VISIBLE (gpgrt_secmem_set_flags); +MARK_VISIBLE (gpgrt_secmem_get_flags); +MARK_VISIBLE (gpgrt_private_is_secure); + #undef MARK_VISIBLE #else /*!_GPGRT_INCL_BY_VISIBILITY_C*/ @@ -379,6 +390,17 @@ MARK_VISIBLE (gpgrt_set_usage_outfnc); #define gpgrt_set_usage_outfnc _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_set_fixed_string_mapper _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_init _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_term _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_malloc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_realloc _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_free _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_dump_stats _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_set_auto_expand _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_set_flags _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_secmem_get_flags _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_private_is_secure _gpgrt_USE_UNDERSCORED_FUNCTION + /* Windows specific functions. */ #define gpgrt_w32_reg_query_string _gpgrt_USE_UNDERSCORED_FUNCTION |