misc: Forbid variable shadowing
diff --git a/stage23/Makefile b/stage23/Makefile
index e1037cd6..4c354c41 100644
--- a/stage23/Makefile
+++ b/stage23/Makefile
@@ -59,6 +59,7 @@ INTERNAL_CFLAGS := \
-fno-lto \
-fno-pic \
-Wno-address-of-packed-member \
+ -Wshadow \
-mno-80387 \
-mno-mmx \
-mno-3dnow \
diff --git a/stage23/fs/fat32.s2.c b/stage23/fs/fat32.s2.c
index fe750d71..9626a114 100644
--- a/stage23/fs/fat32.s2.c
+++ b/stage23/fs/fat32.s2.c
@@ -206,8 +206,8 @@ static bool fat32_filename_to_8_3(char *dest, const char *src) {
int i = 0, j = 0;
bool ext = false;
- for (size_t i = 0; i < 8+3; i++)
- dest[i] = ' ';
+ for (size_t k = 0; k < 8+3; k++)
+ dest[k] = ' ';
while (src[i]) {
if (src[i] == '.') {
diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c
index bfc377aa..cc8f010d 100644
--- a/stage23/mm/pmm.s2.c
+++ b/stage23/mm/pmm.s2.c
@@ -19,7 +19,7 @@ extern symbol bss_end;
#endif
static bool allocations_disallowed = true;
-static void sanitise_entries(bool align_entries);
+static void sanitise_entries(struct e820_entry_t *, size_t *, bool);
void *conv_mem_alloc(size_t count) {
static uintptr_t base = 4096;
@@ -39,7 +39,7 @@ void *conv_mem_alloc(size_t count) {
memset(ret, 0, count);
base += count;
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
return ret;
}
@@ -101,22 +101,24 @@ static bool align_entry(uint64_t *base, uint64_t *length) {
return true;
}
-static void sanitise_entries(bool align_entries) {
+static void sanitise_entries(struct e820_entry_t *m, size_t *_count, bool align_entries) {
+ size_t count = *_count;
+
for (size_t i = 0; i < memmap_entries; i++) {
- if (memmap[i].type != MEMMAP_USABLE)
+ if (m[i].type != MEMMAP_USABLE)
continue;
// Check if the entry overlaps other entries
- for (size_t j = 0; j < memmap_entries; j++) {
+ for (size_t j = 0; j < count; j++) {
if (j == i)
continue;
- uint64_t base = memmap[i].base;
- uint64_t length = memmap[i].length;
+ uint64_t base = m[i].base;
+ uint64_t length = m[i].length;
uint64_t top = base + length;
- uint64_t res_base = memmap[j].base;
- uint64_t res_length = memmap[j].length;
+ uint64_t res_base = m[j].base;
+ uint64_t res_length = m[j].length;
uint64_t res_top = res_base + res_length;
// TODO actually handle splitting off usable chunks
@@ -133,58 +135,60 @@ static void sanitise_entries(bool align_entries) {
base = res_top;
}
- memmap[i].base = base;
- memmap[i].length = top - base;
+ m[i].base = base;
+ m[i].length = top - base;
}
- if (!memmap[i].length
- || (align_entries && !align_entry(&memmap[i].base, &memmap[i].length))) {
+ if (!m[i].length
+ || (align_entries && !align_entry(&m[i].base, &m[i].length))) {
// Eradicate from memmap
- for (size_t j = i; j < memmap_entries - 1; j++) {
- memmap[j] = memmap[j+1];
+ for (size_t j = i; j < count - 1; j++) {
+ m[j] = m[j+1];
}
- memmap_entries--;
+ count--;
i--;
}
}
// Sort the entries
- for (size_t p = 0; p < memmap_entries - 1; p++) {
- uint64_t min = memmap[p].base;
+ for (size_t p = 0; p < count - 1; p++) {
+ uint64_t min = m[p].base;
size_t min_index = p;
- for (size_t i = p; i < memmap_entries; i++) {
- if (memmap[i].base < min) {
- min = memmap[i].base;
+ for (size_t i = p; i < count; i++) {
+ if (m[i].base < min) {
+ min = m[i].base;
min_index = i;
}
}
- struct e820_entry_t min_e = memmap[min_index];
- memmap[min_index] = memmap[p];
- memmap[p] = min_e;
+ struct e820_entry_t min_e = m[min_index];
+ m[min_index] = m[p];
+ m[p] = min_e;
}
// Merge contiguous bootloader-reclaimable and usable entries
- for (size_t i = 0; i < memmap_entries - 1; i++) {
- if (memmap[i].type != MEMMAP_BOOTLOADER_RECLAIMABLE
- && memmap[i].type != MEMMAP_USABLE)
+ for (size_t i = 0; i < count - 1; i++) {
+ if (m[i].type != MEMMAP_BOOTLOADER_RECLAIMABLE
+ && m[i].type != MEMMAP_USABLE)
continue;
- if (memmap[i+1].type == memmap[i].type
- && memmap[i+1].base == memmap[i].base + memmap[i].length) {
- memmap[i].length += memmap[i+1].length;
+ if (m[i+1].type == m[i].type
+ && m[i+1].base == m[i].base + m[i].length) {
+ m[i].length += m[i+1].length;
// Eradicate from memmap
- for (size_t j = i+1; j < memmap_entries - 1; j++) {
- memmap[j] = memmap[j+1];
+ for (size_t j = i+1; j < count - 1; j++) {
+ m[j] = m[j+1];
}
- memmap_entries--;
+ count--;
i--;
}
}
+
+ *_count = count;
}
struct e820_entry_t *get_memmap(size_t *entries) {
- sanitise_entries(true);
+ sanitise_entries(memmap, &memmap_entries, true);
*entries = memmap_entries;
@@ -234,7 +238,7 @@ void init_memmap(void) {
memmap_alloc_range(4096,
ALIGN_UP((uintptr_t)bss_end, 4096) - 4096, MEMMAP_BOOTLOADER_RECLAIMABLE, true, true, false, false);
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
allocations_disallowed = false;
}
@@ -304,7 +308,7 @@ void init_memmap(void) {
memmap_entries++;
}
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
allocations_disallowed = false;
@@ -334,7 +338,7 @@ void pmm_reclaim_uefi_mem(void) {
memmap[i].type = MEMMAP_USABLE;
}
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
}
void pmm_release_uefi_mem(void) {
@@ -447,7 +451,7 @@ void *ext_mem_alloc_type(size_t count, uint32_t type) {
// Zero out allocated space
memset(ret, 0, count);
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
return ret;
}
@@ -501,7 +505,7 @@ bool memmap_alloc_range(uint64_t base, uint64_t length, uint32_t type, bool free
target->length = entry_top - top;
}
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
return true;
}
@@ -520,7 +524,7 @@ bool memmap_alloc_range(uint64_t base, uint64_t length, uint32_t type, bool free
target->base = base;
target->length = length;
- sanitise_entries(false);
+ sanitise_entries(memmap, &memmap_entries, false);
return true;
}
diff --git a/stage23/protos/linux.c b/stage23/protos/linux.c
index 9d63401c..0998fc9e 100644
--- a/stage23/protos/linux.c
+++ b/stage23/protos/linux.c
@@ -555,15 +555,15 @@ void linux_load(char *config, char *cmdline) {
struct boot_e820_entry *e820_table = boot_params->e820_table;
- size_t memmap_entries;
- struct e820_entry_t *memmap = get_raw_memmap(&memmap_entries);
+ size_t mmap_entries;
+ struct e820_entry_t *mmap = get_raw_memmap(&mmap_entries);
- boot_params->e820_entries = memmap_entries;
+ boot_params->e820_entries = mmap_entries;
- for (size_t i = 0; i < memmap_entries; i++) {
- e820_table[i].addr = memmap[i].base;
- e820_table[i].size = memmap[i].length;
- e820_table[i].type = memmap[i].type;
+ for (size_t i = 0; i < mmap_entries; i++) {
+ e820_table[i].addr = mmap[i].base;
+ e820_table[i].size = mmap[i].length;
+ e820_table[i].type = mmap[i].type;
}
///////////////////////////////////////
diff --git a/stage23/protos/multiboot1.c b/stage23/protos/multiboot1.c
index 35777d64..3de7fcad 100644
--- a/stage23/protos/multiboot1.c
+++ b/stage23/protos/multiboot1.c
@@ -137,7 +137,7 @@ void multiboot1_load(char *config, char *cmdline) {
if (!uri_open(&f, module_path))
panic("multiboot1: Failed to open module with path `%s`. Is the path correct?", module_path);
- char *cmdline = config_get_value(config, i, "MODULE_STRING");
+ char *module_cmdline = config_get_value(config, i, "MODULE_STRING");
void *module_addr = (void *)(uintptr_t)ALIGN_UP(kernel_top, 4096);
memmap_alloc_range((uintptr_t)module_addr, f.size, MEMMAP_KERNEL_AND_MODULES,
@@ -147,13 +147,13 @@ void multiboot1_load(char *config, char *cmdline) {
m->begin = (uint32_t)(size_t)module_addr;
m->end = m->begin + f.size;
- m->cmdline = (uint32_t)(size_t)cmdline;
+ m->cmdline = (uint32_t)(size_t)module_cmdline;
m->pad = 0;
if (verbose) {
print("multiboot1: Requested module %u:\n", i);
print(" Path: %s\n", module_path);
- print(" String: \"%s\"\n", cmdline ?: "");
+ print(" String: \"%s\"\n", module_cmdline ?: "");
print(" Begin: %x\n", m->begin);
print(" End: %x\n", m->end);
}
diff --git a/stage23/protos/stivale.c b/stage23/protos/stivale.c
index 73b1e3bc..a95f0e0c 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -286,11 +286,11 @@ void stivale_load(char *config, char *cmdline) {
// Reserve 32K at 0x70000
memmap_alloc_range(0x70000, 0x8000, MEMMAP_USABLE, true, true, false, false);
- size_t memmap_entries;
- struct e820_entry_t *memmap = get_memmap(&memmap_entries);
+ size_t mmap_entries;
+ struct e820_entry_t *mmap = get_memmap(&mmap_entries);
- stivale_struct.memory_map_entries = (uint64_t)memmap_entries;
- stivale_struct.memory_map_addr = REPORTED_ADDR((uint64_t)(size_t)memmap);
+ stivale_struct.memory_map_entries = (uint64_t)mmap_entries;
+ stivale_struct.memory_map_addr = REPORTED_ADDR((uint64_t)(size_t)mmap);
stivale_spinup(bits, want_5lv, &pagemap,
entry_point, REPORTED_ADDR((uint64_t)(uintptr_t)&stivale_struct),
@@ -341,8 +341,8 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null) {
uint64_t aligned_top = ALIGN_UP(top, 0x200000);
uint64_t aligned_length = aligned_top - aligned_base;
- for (uint64_t i = 0; i < aligned_length; i += 0x200000) {
- uint64_t page = aligned_base + i;
+ for (uint64_t j = 0; j < aligned_length; j += 0x200000) {
+ uint64_t page = aligned_base + j;
map_page(pagemap, page, page, 0x03, true);
map_page(pagemap, higher_half_base + page, page, 0x03, true);
}
@@ -363,7 +363,7 @@ __attribute__((noreturn)) void stivale_spinup_32(
__attribute__((noreturn)) void stivale_spinup(
int bits, bool level5pg, pagemap_t *pagemap,
- uint64_t entry_point, uint64_t stivale_struct, uint64_t stack) {
+ uint64_t entry_point, uint64_t _stivale_struct, uint64_t stack) {
#if defined (bios)
if (bits == 64) {
// If we're going 64, we might as well call this BIOS interrupt
@@ -382,6 +382,6 @@ __attribute__((noreturn)) void stivale_spinup(
common_spinup(stivale_spinup_32, 9,
bits, level5pg, (uint32_t)(uintptr_t)pagemap->top_level,
(uint32_t)entry_point, (uint32_t)(entry_point >> 32),
- (uint32_t)stivale_struct, (uint32_t)(stivale_struct >> 32),
+ (uint32_t)_stivale_struct, (uint32_t)(_stivale_struct >> 32),
(uint32_t)stack, (uint32_t)(stack >> 32));
}
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 56e16e9f..101d44a7 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -505,14 +505,14 @@ skip_modeset:;
// Reserve 32K at 0x70000
memmap_alloc_range(0x70000, 0x8000, MEMMAP_USABLE, true, true, false, false);
- size_t memmap_entries;
- struct e820_entry_t *memmap = get_memmap(&memmap_entries);
+ size_t mmap_entries;
+ struct e820_entry_t *mmap = get_memmap(&mmap_entries);
tag->tag.identifier = STIVALE2_STRUCT_TAG_MEMMAP_ID;
- tag->entries = (uint64_t)memmap_entries;
+ tag->entries = (uint64_t)mmap_entries;
memcpy((void*)tag + sizeof(struct stivale2_struct_tag_memmap),
- memmap, sizeof(struct e820_entry_t) * memmap_entries);
+ mmap, sizeof(struct e820_entry_t) * mmap_entries);
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
}
diff --git a/stage23/sys/smp.c b/stage23/sys/smp.c
index d625b9a9..5abeb993 100644
--- a/stage23/sys/smp.c
+++ b/stage23/sys/smp.c
@@ -182,10 +182,10 @@ struct smp_information *init_smp(size_t header_hack_size,
if (!x2apic)
continue;
- struct madt_x2apic *x2apic = (void *)madt_ptr;
+ struct madt_x2apic *x2lapic = (void *)madt_ptr;
// Check if we can actually try to start the AP
- if ((x2apic->flags & 1) ^ ((x2apic->flags >> 1) & 1))
+ if ((x2lapic->flags & 1) ^ ((x2lapic->flags >> 1) & 1))
max_cpus++;
continue;
@@ -242,27 +242,27 @@ struct smp_information *init_smp(size_t header_hack_size,
if (!x2apic)
continue;
- struct madt_x2apic *x2apic = (void *)madt_ptr;
+ struct madt_x2apic *x2lapic = (void *)madt_ptr;
// Check if we can actually try to start the AP
- if (!((x2apic->flags & 1) ^ ((x2apic->flags >> 1) & 1)))
+ if (!((x2lapic->flags & 1) ^ ((x2lapic->flags >> 1) & 1)))
continue;
struct smp_information *info_struct = &ret[*cpu_count];
- info_struct->acpi_processor_uid = x2apic->acpi_processor_uid;
- info_struct->lapic_id = x2apic->x2apic_id;
+ info_struct->acpi_processor_uid = x2lapic->acpi_processor_uid;
+ info_struct->lapic_id = x2lapic->x2apic_id;
// Do not try to restart the BSP
- if (x2apic->x2apic_id == bsp_x2apic_id) {
+ if (x2lapic->x2apic_id == bsp_x2apic_id) {
(*cpu_count)++;
continue;
}
- printv("smp: [x2APIC] Found candidate AP for bring-up. LAPIC ID: %u\n", x2apic->x2apic_id);
+ printv("smp: [x2APIC] Found candidate AP for bring-up. LAPIC ID: %u\n", x2lapic->x2apic_id);
// Try to start the AP
- if (!smp_start_ap(x2apic->x2apic_id, &gdtr, info_struct,
+ if (!smp_start_ap(x2lapic->x2apic_id, &gdtr, info_struct,
longmode, lv5, (uintptr_t)pagemap.top_level,
true)) {
print("smp: FAILED to bring-up AP\n");
