Segmentation Fault

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
zecarlos
Posts: 11
Joined: Tue Feb 18, 2020 8:20 am

Segmentation Fault

Post by zecarlos »

HI, all the best for you


I'm trying to compile the code from /klange/toaruos in windows environment.
All code is in https://github.com/zecarlos1957/learnos in develop branch.

I started with a small piece of code to which i was adding functions
and now i can compile the kernel without errors after making some changes
to satisfy my compiler that is MinGW32-gcc.
Now the problems arise.
After compiling the kernel and modules for pei-i386, I used <objcopy -O elf32-i386 ...> so that grub/stage2_eltorito recognizes the format.

After loading the kernel and the <vgadbg.ko> module and relocating all addresses, in <module.c: module_load_direct (...)>, and within the function "vgadbg_init ()" of this module, calls to global functions "create_kernel_tasklet (...)", "memset (...)" and sprintf (...) fail with "Segmentation Fault"

Consulting the memory map of the linker, I created pointers for these functions, and it turns out that by making calls through these, they occurred successfully.

Also when I make the call using the function name, the relocation to this reference appears with type R_386_PC32.

Can anyone help solving this problem?

Code: Select all

typedef int (*func)(tasklet_t tasklet, char * name, void * argp);
typedef int(*sprt)(char*, const char*, ...);

static int vgadbg_init(void)
{
	char buf[128];
     sprt sprint = (sprt)0x10cd92;
//	memset(textmemptr, 0x00, sizeof(unsigned short) * 80 * 25);

	write_string("VGA Text-Mode Debugger\n");
	write_string(" If you're seeing this, module loading completed successfully.\n");
	write_string(" We'll now do some checks to see what may be wrong with the system.\n");
 
    sprint(buf,"Addr %x\n",(uint32_t)&create_kernel_tasklet);
    write_string(buf);
 
    func f1 = create_kernel_tasklet;
    f1(tasklet, "[[vgadbg]]", NULL);
   
 ///   create_kernel_tasklet(tasklet, "[[vgadbg]]", NULL); -> SEGMENTATION FAULT
	return 0;
}
Thank you so much.
Attachments
LearnOS_OK.png
LearnOS-err.png
zecarlos
Posts: 11
Joined: Tue Feb 18, 2020 8:20 am

Re: Segmentation Fault

Post by zecarlos »

I believe I have found the problem.
When the relocation is of type R_386_PC32, (function call), the value of "addend" is zero.
Now, I think that this value should be the local address from which the call was made.
Am I correct?
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Segmentation Fault

Post by Octocontrabass »

zecarlos wrote:making some changes to satisfy my compiler that is MinGW32-gcc.
Why not use the correct compiler instead of modifying the code to build with a compiler targeting Windows? The ToaruOS repository includes scripts to build a dedicated i686-pc-toaru-gcc that can compile everything correctly. The scripts should run unmodified in WSL, and I suspect they won't require many changes to also run under MSYS2 in case you prefer that.
Post Reply