First of all the following loop causes the actual overrun (determined via bochs)
Code: Select all
for (i=0; i<NUM_DEV; i++)
{
if (file_used[i])
continue;
print_num(i);
print("\n");
file_used[i] = 1;
files[i] = *file;
return 0;
}
Code: Select all
#define NUM_DEV 128
struct devicefile files[NUM_DEV];
int file_used[NUM_DEV];
the struct devicefile has a size of 40 bytes.
It runs over another variable called freeHead (static to some module).
Definition:
Code: Select all
static struct timer freeHead, freeTail;
Next I went through the output of readelf -w for the final executable
Relevant for the loop file
Code: Select all
...
<1><5b2>: Abbrev Number: 7 (DW_TAG_structure_type)
<5b3> DW_AT_name : (indirect string, offset: 0x109): devicefile
<5b7> DW_AT_byte_size : 40
<5b8> DW_AT_decl_file : 4
<5b9> DW_AT_decl_line : 7
<5ba> DW_AT_sibling : <0x5f7>
<2><5be>: Abbrev Number: 9 (DW_TAG_member)
<5bf> DW_AT_name : (indirect string, offset: 0xf56): name
<5c3> DW_AT_decl_file : 4
<5c4> DW_AT_decl_line : 13
<5c5> DW_AT_type : <0x5f7>
<5c9> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<2><5cc>: Abbrev Number: 9 (DW_TAG_member)
<5cd> DW_AT_name : (indirect string, offset: 0x2a0): open
<5d1> DW_AT_decl_file : 4
<5d2> DW_AT_decl_line : 14
<5d3> DW_AT_type : <0x581>
<5d7> DW_AT_data_member_location: 2 byte block: 23 10 (DW_OP_plus_uconst: 16)
<2><5da>: Abbrev Number: 9 (DW_TAG_member)
<5db> DW_AT_name : (indirect string, offset: 0x23f): perm
<5df> DW_AT_decl_file : 4
<5e0> DW_AT_decl_line : 15
<5e1> DW_AT_type : <0x22e>
<5e5> DW_AT_data_member_location: 2 byte block: 23 14 (DW_OP_plus_uconst: 20)
<2><5e8>: Abbrev Number: 9 (DW_TAG_member)
<5e9> DW_AT_name : (indirect string, offset: 0x1135): data
<5ed> DW_AT_decl_file : 4
<5ee> DW_AT_decl_line : 17
<5ef> DW_AT_type : <0x607>
<5f3> DW_AT_data_member_location: 2 byte block: 23 18 (DW_OP_plus_uconst: 24)
...
<1><94b>: Abbrev Number: 13 (DW_TAG_array_type)
<94c> DW_AT_type : <0x5b2>
<950> DW_AT_sibling : <0x95b>
...
<1><95b>: Abbrev Number: 25 (DW_TAG_variable)
<95c> DW_AT_name : (indirect string, offset: 0x2c0): files
<960> DW_AT_decl_file : 1
<961> DW_AT_decl_line : 9
<962> DW_AT_type : <0x94b>
<966> DW_AT_external : 1
<967> DW_AT_location : 5 byte block: 3 d4 c 14 0 (DW_OP_addr: 140cd4)
...
For the file where the variable which is overrun resides
Code: Select all
...
<1><1804>: Abbrev Number: 3 (DW_TAG_structure_type)
<1805> DW_AT_name : (indirect string, offset: 0x609): timer
<1809> DW_AT_byte_size : 24
<180a> DW_AT_decl_file : 1
<180b> DW_AT_decl_line : 9
<180c> DW_AT_sibling : <0x1856>
<2><1810>: Abbrev Number: 4 (DW_TAG_member)
<1811> DW_AT_name : ID
<1814> DW_AT_decl_file : 1
<1815> DW_AT_decl_line : 10
<1816> DW_AT_type : <0x17fd>
<181a> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<2><181d>: Abbrev Number: 4 (DW_TAG_member)
<181e> DW_AT_name : TID
<1822> DW_AT_decl_file : 1
<1823> DW_AT_decl_line : 11
<1824> DW_AT_type : <0x17fd>
<1828> DW_AT_data_member_location: 2 byte block: 23 4 (DW_OP_plus_uconst: 4)
<2><182b>: Abbrev Number: 5 (DW_TAG_member)
<182c> DW_AT_name : (indirect string, offset: 0x66d): alarmtime
<1830> DW_AT_decl_file : 1
<1831> DW_AT_decl_line : 12
<1832> DW_AT_type : <0x1856>
<1836> DW_AT_data_member_location: 2 byte block: 23 8 (DW_OP_plus_uconst: 8)
<2><1839>: Abbrev Number: 5 (DW_TAG_member)
<183a> DW_AT_name : (indirect string, offset: 0x5fd): next
<183e> DW_AT_decl_file : 1
<183f> DW_AT_decl_line : 13
<1840> DW_AT_type : <0x185d>
<1844> DW_AT_data_member_location: 2 byte block: 23 10 (DW_OP_plus_uconst: 16)
<2><1847>: Abbrev Number: 5 (DW_TAG_member)
<1848> DW_AT_name : (indirect string, offset: 0x6a2): prev
<184c> DW_AT_decl_file : 1
<184d> DW_AT_decl_line : 14
<184e> DW_AT_type : <0x185d>
<1852> DW_AT_data_member_location: 2 byte block: 23 14 (DW_OP_plus_uconst: 20)
...
<1><198a>: Abbrev Number: 14 (DW_TAG_variable)
<198b> DW_AT_name : (indirect string, offset: 0x627): freeHead
<198f> DW_AT_decl_file : 1
<1990> DW_AT_decl_line : 18
<1991> DW_AT_type : <0x1804>
<1995> DW_AT_location : 5 byte block: 3 30 d 14 0 (DW_OP_addr: 140d30)
...
Makefile used:
Code: Select all
SRCFILES = $(shell find ./ -mindepth 1 -maxdepth 5 -name "*.c")
ASMFILES = $(shell find ./ -mindepth 1 -maxdepth 5 -name "*.s")
OBJFILES = $(patsubst %.s,%.o,$(ASMFILES)) $(patsubst %.c,%.o,$(SRCFILES))
DFILES = $(patsubst %.c,%.d,$(SRCFILES))
AS = nasm
ASFLAGS = -f elf
CC = gcc
CFLAGS = -MMD -MT "$*.d" -MP -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs -I./include/ -m32 -g
floppy.img: kernel.bin stage1 stage2 pad asmdum
cat stage1 stage2 pad kernel.bin >floppy.img
kernel.bin: $(OBJFILES)
ld -T linker.ld -o kernel.bin $(OBJFILES) -melf_i386 `gcc -m32 -print-libgcc-file-name`
asmdum: kernel.bin
objdump -S kernel.bin >asmdum
.PHONY clean:
rm -f $(OBJFILES) $(DFILES) kernel.bin floppy.img asmdum
Code: Select all
ENTRY (loader)
SECTIONS{
. = 0x00100000;
.text ALIGN (0x1000) : {
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss ALIGN (0x1000) : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
kernel_end = .;
}