提交 62dc5aad 编写于 作者: R Richard Levitte

Introduce the possibility to access global variables through

functions on platform were that's the best way to handle exporting
global variables in shared libraries.  To enable this functionality,
one must configure with "EXPORT_VAR_AS_FN" or defined the C macro
"OPENSSL_EXPORT_VAR_AS_FUNCTION" in crypto/opensslconf.h (the latter
is normally done by Configure or something similar).

To implement a global variable, use the macro OPENSSL_IMPLEMENT_GLOBAL
in the source file (foo.c) like this:

	OPENSSL_IMPLEMENT_GLOBAL(int,foo)=1;
	OPENSSL_IMPLEMENT_GLOBAL(double,bar);

To declare a global variable, use the macros OPENSSL_DECLARE_GLOBAL
and OPENSSL_GLOBAL_REF in the header file (foo.h) like this:

	OPENSSL_DECLARE_GLOBAL(int,foo);
	#define foo OPENSSL_GLOBAL_REF(foo)
	OPENSSL_DECLARE_GLOBAL(double,bar);
	#define bar OPENSSL_GLOBAL_REF(bar)

The #defines are very important, and therefore so is including the
header file everywere where the defined globals are used.

The macro OPENSSL_EXPORT_VAR_AS_FUNCTION also affects the definition
of ASN.1 items, but that structure is a bt different.

The largest change is in util/mkdef.pl which has been enhanced with
better and easier to understand logic to choose which symbols should
go into the Windows .def files as well as a number of fixes and code
cleanup (among others, algorithm keywords are now sorted
lexicographically to avoid constant rewrites).
上级 45ecfb19
......@@ -3,6 +3,40 @@
Changes between 0.9.6 and 0.9.7 [xx XXX 2000]
*) Introduce the possibility to access global variables through
functions on platform were that's the best way to handle exporting
global variables in shared libraries. To enable this functionality,
one must configure with "EXPORT_VAR_AS_FN" or defined the C macro
"OPENSSL_EXPORT_VAR_AS_FUNCTION" in crypto/opensslconf.h (the latter
is normally done by Configure or something similar).
To implement a global variable, use the macro OPENSSL_IMPLEMENT_GLOBAL
in the source file (foo.c) like this:
OPENSSL_IMPLEMENT_GLOBAL(int,foo)=1;
OPENSSL_IMPLEMENT_GLOBAL(double,bar);
To declare a global variable, use the macros OPENSSL_DECLARE_GLOBAL
and OPENSSL_GLOBAL_REF in the header file (foo.h) like this:
OPENSSL_DECLARE_GLOBAL(int,foo);
#define foo OPENSSL_GLOBAL_REF(foo)
OPENSSL_DECLARE_GLOBAL(double,bar);
#define bar OPENSSL_GLOBAL_REF(bar)
The #defines are very important, and therefore so is including the
header file everywere where the defined globals are used.
The macro OPENSSL_EXPORT_VAR_AS_FUNCTION also affects the definition
of ASN.1 items, but that structure is a bt different.
The largest change is in util/mkdef.pl which has been enhanced with
better and easier to understand logic to choose which symbols should
go into the Windows .def files as well as a number of fixes and code
cleanup (among others, algorithm keywords are now sorted
lexicographically to avoid constant rewrites).
[Richard Levitte]
*) In copy_email() check for >= 0 as a return value for
X509_NAME_get_index_by_NID() since 0 is a valid index.
[Steve Henson reported by Massimiliano Pala <madwolf@opensca.org>]
......
......@@ -968,6 +968,7 @@ my $rc4_chunk=0;
my $bf_ptr=0;
my @type=("char","short","int","long");
my ($b64l,$b64,$b32,$b16,$b8)=(0,0,1,0,0);
my $export_var_as_fn=0;
my $des_int;
......@@ -997,6 +998,7 @@ foreach (sort split(/\s+/,$bn_ops))
($b64l,$b64,$b32,$b16,$b8)=(0,0,1,0,0) if /THIRTY_TWO_BIT/;
($b64l,$b64,$b32,$b16,$b8)=(0,0,0,1,0) if /SIXTEEN_BIT/;
($b64l,$b64,$b32,$b16,$b8)=(0,0,0,0,1) if /EIGHT_BIT/;
$export_var_as_fn=1 if /EXPORT_VAR_AS_FN/;
}
open(IN,'<crypto/opensslconf.h.in') || die "unable to read crypto/opensslconf.h.in:$!\n";
......@@ -1029,6 +1031,11 @@ while (<IN>)
{
if (/^#define\s+OPENSSLDIR/)
{ print OUT "#define OPENSSLDIR \"$openssldir\"\n"; }
elsif (/^#((define)|(undef))\s+OPENSSL_EXPORT_VAR_AS_FUNCTION/)
{ printf OUT "#undef OPENSSL_EXPORT_VAR_AS_FUNCTION\n"
if $export_var_as_fn;
printf OUT "#%s OPENSSL_EXPORT_VAR_AS_FUNCTION\n",
($export_var_as_fn)?"define":"undef"; }
elsif (/^#define\s+OPENSSL_UNISTD/)
{
$unistd = "<unistd.h>" if $unistd eq "";
......
......@@ -357,7 +357,7 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
*
*/
#ifndef ASN1_ITEM_FUNCTIONS
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
/* ASN1_ITEM pointer exported type */
typedef const ASN1_ITEM ASN1_ITEM_EXP;
......
......@@ -74,7 +74,7 @@ extern "C" {
#endif
#ifndef ASN1_ITEM_FUNCTIONS
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
......@@ -287,7 +287,7 @@ extern "C" {
/* Any defined by macros: the field used is in the table itself */
#ifndef ASN1_ITEM_FUNCTIONS
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
#else
......@@ -358,7 +358,7 @@ extern "C" {
#define ASN1_ADB(name) \
const static ASN1_ADB_TABLE name##_adbtbl[]
#ifndef ASN1_ITEM_FUNCTIONS
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
;\
......
......@@ -116,8 +116,10 @@ typedef struct des_ks_struct
#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
OPENSSL_EXTERN int des_check_key; /* defaults to false */
OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */
OPENSSL_DECLARE_GLOBAL(int,des_check_key); /* defaults to false */
#define des_check_key OPENSSL_GLOBAL_REF(des_check_key)
OPENSSL_DECLARE_GLOBAL(int,des_rw_mode); /* defaults to DES_PCBC_MODE */
#define des_rw_mode OPENSSL_GLOBAL_REF(des_rw_mode)
const char *des_options(void);
void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
......
......@@ -63,7 +63,7 @@
/* This has some uglies in it but it works - even over sockets. */
/*extern int errno;*/
OPENSSL_GLOBAL int des_rw_mode=DES_PCBC_MODE;
OPENSSL_IMPLEMENT_GLOBAL(int,des_rw_mode)=DES_PCBC_MODE;
/*
......
......@@ -65,7 +65,7 @@
*/
#include "des_locl.h"
OPENSSL_GLOBAL int des_check_key=0;
OPENSSL_IMPLEMENT_GLOBAL(int,des_check_key); /* defaults to false */
static const unsigned char odd_parity[256]={
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
......
......@@ -12,6 +12,8 @@
#undef OPENSSL_UNISTD
#define OPENSSL_UNISTD <unistd.h>
#undef OPENSSL_EXPORT_VAR_AS_FUNCTIONS
#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
#define IDEA_INT unsigned int
#endif
......
......@@ -200,6 +200,28 @@ extern "C" {
#endif
#define OPENSSL_EXTERN OPENSSL_IMPORT
/* Macros to allow global variables to be reached through function calls when
required (if a shared library version requvres it, for example.
The way it's done allows definitions like this:
// in foobar.c
OPENSSL_IMPLEMENT_GLOBAL(int,foobar) = 0;
// in foobar.h
OPENSSL_DECLARE_GLOBAL(int,foobar);
#define foobar OPENSSL_GLOBAL_REF(foobar)
*/
#ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
# define OPENSSL_IMPLEMENT_GLOBAL(type,name) extern static type _hide_##name; \
type *_shadow_##name(void) { static type local_var; return &local_var; } \
static type _hide_##name
# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
#else
# define OPENSSL_IMPLEMENT_GLOBAL(type,name) OPENSSL_GLOBAL type _shadow_##name
# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
# define OPENSSL_GLOBAL_REF(name) _shadow_##name
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -285,6 +285,8 @@ $ WRITE H_FILE "#undef THIRTY_TWO_BIT"
$ WRITE H_FILE "#undef SIXTEEN_BIT"
$ WRITE H_FILE "#undef EIGHT_BIT"
$ WRITE H_FILE "#endif"
$
$ WRITE H_FILE "#undef OPENSSL_EXPORT_VAR_AS_FUNCTION"
$!
$! Else...
$!
......@@ -317,6 +319,9 @@ $ WRITE H_FILE "#define THIRTY_TWO_BIT"
$ WRITE H_FILE "#undef SIXTEEN_BIT"
$ WRITE H_FILE "#undef EIGHT_BIT"
$ WRITE H_FILE "#endif"
$
$ WRITE H_FILE "#undef OPENSSL_EXPORT_VAR_AS_FUNCTION"
$ WRITE H_FILE "#define OPENSSL_EXPORT_VAR_AS_FUNCTION"
$!
$! End
$!
......
此差异已折叠。
此差异已折叠。
......@@ -21,7 +21,7 @@ SSL_CTX_use_PrivateKey_ASN1 23 EXIST::FUNCTION:
SSL_CTX_use_PrivateKey_file 24 EXIST::FUNCTION:STDIO
SSL_CTX_use_RSAPrivateKey 25 EXIST::FUNCTION:RSA
SSL_CTX_use_RSAPrivateKey_ASN1 26 EXIST::FUNCTION:RSA
SSL_CTX_use_RSAPrivateKey_file 27 EXIST::FUNCTION:STDIO,RSA
SSL_CTX_use_RSAPrivateKey_file 27 EXIST::FUNCTION:RSA,STDIO
SSL_CTX_use_certificate 28 EXIST::FUNCTION:
SSL_CTX_use_certificate_ASN1 29 EXIST::FUNCTION:
SSL_CTX_use_certificate_file 30 EXIST::FUNCTION:STDIO
......@@ -89,7 +89,7 @@ SSL_use_PrivateKey_ASN1 100 EXIST::FUNCTION:
SSL_use_PrivateKey_file 101 EXIST::FUNCTION:STDIO
SSL_use_RSAPrivateKey 102 EXIST::FUNCTION:RSA
SSL_use_RSAPrivateKey_ASN1 103 EXIST::FUNCTION:RSA
SSL_use_RSAPrivateKey_file 104 EXIST::FUNCTION:STDIO,RSA
SSL_use_RSAPrivateKey_file 104 EXIST::FUNCTION:RSA,STDIO
SSL_use_certificate 105 EXIST::FUNCTION:
SSL_use_certificate_ASN1 106 EXIST::FUNCTION:
SSL_use_certificate_file 107 EXIST::FUNCTION:STDIO
......@@ -208,7 +208,7 @@ kssl_ctx_free 257 EXIST::FUNCTION:KRB5
kssl_krb5_free_data_contents 258 EXIST::FUNCTION:KRB5
print_krb5_data 259 EXIST::FUNCTION:KRB5
kssl_ctx_setstring 260 EXIST::FUNCTION:KRB5
SSL_CTX_has_matching_session_id 261 EXIST::FUNCTION:
SSL_CTX_has_matching_session_id 261 NOEXIST::FUNCTION:
SSL_set_generate_session_id 262 EXIST::FUNCTION:
SSL_CTX_set_generate_session_id 263 EXIST::FUNCTION:
SSL_has_matching_session_id 264 EXIST::FUNCTION:
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册