Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Langley <agl@chromium.org>2015-02-06 22:52:16 +0300
committerAdam Langley <agl@chromium.org>2015-02-10 04:35:31 +0300
commit29b186736c1e95e2005b13674a6930b282b55e21 (patch)
tree02ddb5e6055c305410dcea5f9730e7e294d18702 /crypto/err/err_impl.c
parent65226257c1c49eac4a739b9d57409b52dfbb5d45 (diff)
Precompute sorted array for error strings.
Previously, error strings were kept in arrays for each subdirectory and err.c would iterate over them all and insert them at init time to a hash table. This means that, even if you have a shared library and lots of processes using that, each process has ~30KB of private memory from building that hash table. This this change, all the error strings are built into a sorted list and are thus static data. This means that processes can share the error information and it actually saves binary space because of all the pointer overhead in the old scheme. Also it saves the time taken building the hash table at startup. This removes support for externally-supplied error string data. Change-Id: Ifca04f335c673a048e1a3e76ff2b69c7264635be
Diffstat (limited to 'crypto/err/err_impl.c')
-rw-r--r--crypto/err/err_impl.c83
1 files changed, 0 insertions, 83 deletions
diff --git a/crypto/err/err_impl.c b/crypto/err/err_impl.c
index 32cff35a..0c36f82e 100644
--- a/crypto/err/err_impl.c
+++ b/crypto/err/err_impl.c
@@ -122,84 +122,9 @@ DEFINE_LHASH_OF(ERR_STRING_DATA);
* storage. */
static LHASH_OF(ERR_STATE) *state_hash = NULL;
-/* error_hash maps from a packed error to the string for that library /
- * function / reason. */
-static LHASH_OF(ERR_STRING_DATA) *error_hash = NULL;
-
/* global_next_library contains the next custom library value to return. */
static int global_next_library = ERR_NUM_LIBS;
-/* err_string_data_hash is an lhash hash function for ERR_STRING_DATA. */
-static uint32_t err_string_data_hash(const ERR_STRING_DATA *a) {
- return OPENSSL_hash32(&a->error, sizeof(a->error));
-}
-
-/* err_string_data_cmp is an lhash compare function for ERR_STRING_DATA. */
-static int err_string_data_cmp(const ERR_STRING_DATA *a,
- const ERR_STRING_DATA *b) {
- return ((int)a->error) - ((int)b->error);
-}
-
-/* error_hash_get_write_locked returns the hash that maps from packed error to
- * error string and creates it if need be. The caller must hold a write lock on
- * LOCK_ERR. */
-static LHASH_OF(ERR_STRING_DATA) * error_hash_get_write_locked(void) {
- if (!error_hash) {
- error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash, err_string_data_cmp);
- }
-
- return error_hash;
-}
-
-/* err_get_item returns an ERR_STRING_DATA with an |error| member that
- * equals |packed_error|, or NULL if none can be found. */
-static ERR_STRING_DATA *err_get_item(uint32_t packed_error) {
- ERR_STRING_DATA *ret = NULL, pattern;
-
- pattern.error = packed_error;
-
- CRYPTO_r_lock(CRYPTO_LOCK_ERR);
- if (error_hash) {
- ret = lh_ERR_STRING_DATA_retrieve(error_hash, &pattern);
- }
- CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
-
- return ret;
-}
-
-/* err_set_item adds an ERR_STRING_DATA to the global hash of error strings and
- * returns the previous entry with the same |err->error| value, if any. */
-static ERR_STRING_DATA *err_set_item(const ERR_STRING_DATA *err) {
- ERR_STRING_DATA *old_item = NULL;
- LHASH_OF(ERR_STRING_DATA) *hash;
-
- CRYPTO_w_lock(CRYPTO_LOCK_ERR);
- hash = error_hash_get_write_locked();
- if (hash) {
- lh_ERR_STRING_DATA_insert(hash, &old_item, (ERR_STRING_DATA*) err);
- }
- CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
- return old_item;
-}
-
-/* err_set_item removes an item from the global hash of error strings for
- * |packed_error| and returns the removed entry, if any. */
-static ERR_STRING_DATA *err_del_item(uint32_t packed_error) {
- ERR_STRING_DATA *old_item = NULL, pattern;
-
- pattern.error = packed_error;
-
- CRYPTO_w_lock(CRYPTO_LOCK_ERR);
- if (error_hash) {
- old_item = lh_ERR_STRING_DATA_delete(error_hash, &pattern);
- }
- CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
-
- return old_item;
-}
-
-
/* err_state_hash is an lhash hash function for ERR_STATE. */
static uint32_t err_state_hash(const ERR_STATE *a) {
return CRYPTO_THREADID_hash(&a->tid);
@@ -210,7 +135,6 @@ static int err_state_cmp(const ERR_STATE *a, const ERR_STATE *b) {
return CRYPTO_THREADID_cmp(&a->tid, &b->tid);
}
-
static ERR_STATE *err_get_state(void) {
CRYPTO_THREADID tid;
ERR_STATE pattern, *state, *race_state;
@@ -290,10 +214,6 @@ static ERR_STATE *err_release_state(const CRYPTO_THREADID *tid) {
static void err_shutdown(void (*err_state_free_cb)(ERR_STATE*)) {
CRYPTO_w_lock(CRYPTO_LOCK_ERR);
- if (error_hash) {
- lh_ERR_STRING_DATA_free(error_hash);
- error_hash = NULL;
- }
if (state_hash) {
lh_ERR_STATE_doall(state_hash, err_state_free_cb);
lh_ERR_STATE_free(state_hash);
@@ -314,9 +234,6 @@ static int err_get_next_library(void) {
const struct ERR_FNS_st openssl_err_default_impl = {
err_shutdown,
- err_get_item,
- err_set_item,
- err_del_item,
err_get_state,
err_release_state,
err_get_next_library,