From 1de6b336bb1e2ddfbff1023a1cf6ba4fd067d1a3 Mon Sep 17 00:00:00 2001 From: Mat M Date: Mon, 26 Feb 2018 03:42:21 -0500 Subject: [PATCH] all: Make file-scope variables internally linked where applicable (#57) Narrows the scope of visible symbols to where they're actually used. Also makes it easier to see true globals in source files (ones used from multiple translation units) --- exosphere/src/configitem.c | 2 +- exosphere/src/cpu_context.c | 2 +- exosphere/src/interrupt.c | 2 +- exosphere/src/masterkey.c | 8 ++++---- exosphere/src/se.c | 6 +++--- exosphere/src/sealedkeys.c | 5 ++--- exosphere/src/smc_api.c | 6 +++--- exosphere/src/titlekey.c | 4 ++-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/exosphere/src/configitem.c b/exosphere/src/configitem.c index ed5a3221a..2e2923d82 100644 --- a/exosphere/src/configitem.c +++ b/exosphere/src/configitem.c @@ -8,7 +8,7 @@ #include "fuse.h" #include "utils.h" -int g_battery_profile = 0; +static int g_battery_profile = 0; uint32_t configitem_set(enum ConfigItem item, uint64_t value) { if (item != CONFIGITEM_BATTERYPROFILE) { diff --git a/exosphere/src/cpu_context.c b/exosphere/src/cpu_context.c index c5e84f529..d91829618 100644 --- a/exosphere/src/cpu_context.c +++ b/exosphere/src/cpu_context.c @@ -4,7 +4,7 @@ #include "timers.h" #include "utils.h" -saved_cpu_context_t g_cpu_contexts[NUM_CPU_CORES] = {0}; +static saved_cpu_context_t g_cpu_contexts[NUM_CPU_CORES] = {0}; void set_core_entrypoint_and_context_id(uint32_t core, uint64_t entrypoint_addr, uint64_t context_id) { g_cpu_contexts[core].ELR_EL3 = entrypoint_addr; diff --git a/exosphere/src/interrupt.c b/exosphere/src/interrupt.c index fd4d1df0a..52f42250c 100644 --- a/exosphere/src/interrupt.c +++ b/exosphere/src/interrupt.c @@ -5,7 +5,7 @@ #include "interrupt.h" /* Global of registered handlers. */ -struct { +static struct { unsigned int id; void (*handler)(void); } g_registered_interrupts[MAX_REGISTERED_INTERRUPTS] = { {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL} }; diff --git a/exosphere/src/masterkey.c b/exosphere/src/masterkey.c index 5288b9405..0b787c2bf 100644 --- a/exosphere/src/masterkey.c +++ b/exosphere/src/masterkey.c @@ -5,15 +5,15 @@ #include "masterkey.h" #include "se.h" -unsigned int g_mkey_revision = 0; -bool g_determined_mkey_revision = false; +static unsigned int g_mkey_revision = 0; +static bool g_determined_mkey_revision = false; -uint8_t g_old_masterkeys[MASTERKEY_REVISION_MAX][0x10]; +static uint8_t g_old_masterkeys[MASTERKEY_REVISION_MAX][0x10]; /* TODO: Dev keys. */ /* TODO: Extend with new vectors, as needed. */ -const uint8_t mkey_vectors[MASTERKEY_REVISION_MAX][0x10] = +static const uint8_t mkey_vectors[MASTERKEY_REVISION_MAX][0x10] = { {0x0C, 0xF0, 0x59, 0xAC, 0x85, 0xF6, 0x26, 0x65, 0xE1, 0xE9, 0x19, 0x55, 0xE6, 0xF2, 0x67, 0x3D}, /* Zeroes encrypted with Master Key 00. */ {0x29, 0x4C, 0x04, 0xC8, 0xEB, 0x10, 0xED, 0x9D, 0x51, 0x64, 0x97, 0xFB, 0xF3, 0x4D, 0x50, 0xDD}, /* Master key 00 encrypted with Master key 01. */ diff --git a/exosphere/src/se.c b/exosphere/src/se.c index 78c85ff4d..e828e54a7 100644 --- a/exosphere/src/se.c +++ b/exosphere/src/se.c @@ -14,10 +14,10 @@ void trigger_se_rsa_op(void *buf, size_t size); void trigger_se_blocking_op(unsigned int op, void *dst, size_t dst_size, const void *src, size_t src_size); /* Globals for driver. */ -unsigned int (*g_se_callback)(void); +static unsigned int (*g_se_callback)(void); -unsigned int g_se_modulus_sizes[KEYSLOT_RSA_MAX]; -unsigned int g_se_exp_sizes[KEYSLOT_RSA_MAX]; +static unsigned int g_se_modulus_sizes[KEYSLOT_RSA_MAX]; +static unsigned int g_se_exp_sizes[KEYSLOT_RSA_MAX]; /* Initialize a SE linked list. */ diff --git a/exosphere/src/sealedkeys.c b/exosphere/src/sealedkeys.c index 450915c0e..b71a4fe44 100644 --- a/exosphere/src/sealedkeys.c +++ b/exosphere/src/sealedkeys.c @@ -4,12 +4,11 @@ #include "sealedkeys.h" #include "se.h" -const uint8_t g_titlekey_seal_key_source[0x10] = { +static const uint8_t g_titlekey_seal_key_source[0x10] = { 0xCB, 0xB7, 0x6E, 0x38, 0xA1, 0xCB, 0x77, 0x0F, 0xB2, 0xA5, 0xB2, 0x9D, 0xD8, 0x56, 0x9F, 0x76 }; - -const uint8_t g_seal_key_sources[CRYPTOUSECASE_MAX][0x10] = { +static const uint8_t g_seal_key_sources[CRYPTOUSECASE_MAX][0x10] = { {0xF4, 0x0C, 0x16, 0x26, 0x0D, 0x46, 0x3B, 0xE0, 0x8C, 0x6A, 0x56, 0xE5, 0x82, 0xD4, 0x1B, 0xF6}, {0x7F, 0x54, 0x2C, 0x98, 0x1E, 0x54, 0x18, 0x3B, 0xBA, 0x63, 0xBD, 0x4C, 0x13, 0x5B, 0xF1, 0x06}, {0xC7, 0x3F, 0x73, 0x60, 0xB7, 0xB9, 0x9D, 0x74, 0x0A, 0xF8, 0x35, 0x60, 0x1A, 0x18, 0x74, 0x63}, diff --git a/exosphere/src/smc_api.c b/exosphere/src/smc_api.c index b5ff36168..7be80b6c3 100644 --- a/exosphere/src/smc_api.c +++ b/exosphere/src/smc_api.c @@ -62,7 +62,7 @@ typedef struct { uint32_t num_handlers; } smc_table_t; -smc_table_entry_t g_smc_user_table[SMC_USER_HANDLERS] = { +static smc_table_entry_t g_smc_user_table[SMC_USER_HANDLERS] = { {0, NULL}, {0xC3000401, smc_set_config}, {0xC3000002, smc_get_config}, @@ -84,7 +84,7 @@ smc_table_entry_t g_smc_user_table[SMC_USER_HANDLERS] = { {0xC3000012, smc_unwrap_aes_wrapped_titlekey} }; -smc_table_entry_t g_smc_priv_table[SMC_PRIV_HANDLERS] = { +static smc_table_entry_t g_smc_priv_table[SMC_PRIV_HANDLERS] = { {0, NULL}, {0xC4000001, smc_cpu_suspend}, {0x84000002, smc_cpu_off}, @@ -96,7 +96,7 @@ smc_table_entry_t g_smc_priv_table[SMC_PRIV_HANDLERS] = { {0xC3000008, smc_read_write_register} }; -smc_table_t g_smc_tables[2] = { +static smc_table_t g_smc_tables[2] = { { /* SMC_HANDLER_USER */ g_smc_user_table, SMC_USER_HANDLERS diff --git a/exosphere/src/titlekey.c b/exosphere/src/titlekey.c index a55bd21fa..845aceed3 100644 --- a/exosphere/src/titlekey.c +++ b/exosphere/src/titlekey.c @@ -8,8 +8,8 @@ #include "masterkey.h" #include "se.h" -uint64_t g_tkey_expected_label_hash[4]; -unsigned int g_tkey_master_key_rev = MASTERKEY_REVISION_MAX; +static uint64_t g_tkey_expected_label_hash[4]; +static unsigned int g_tkey_master_key_rev = MASTERKEY_REVISION_MAX; /* Set the expected db prefix. */ void tkey_set_expected_label_hash(uint64_t *label_hash) {