Strange problem

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.
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Strange problem

Post by finarfin »

Hi all,

I use for all testing commands a data structure:

Code: Select all

struct devel {
	const char cmd_testname[CMD_LEN];
	void (*func)(void);
}
And i use an array of these structures every time i launch a test command.
So that array has 11 elements, and everithing working fine. But now i adde a new command, and something goes wrong.

In fact now, when i try to log-in my os (with a very basic login method based on a username a simply file passwd) the function called for user checking is called (and i'm sure of it) but two strange thing happens:
1. printf doesn't work
2. when i call:

Code: Select all

fd=open("/passwd", O_RDONLY, 0);
the function open didn't receive the path, in fact if i try to print it on the screen (into open function printf restarts to work) i receive an empty string.

if i force the user_check function to success (so every username inserted is accepted) the rest of the operatiing system works fine.

I don't have any idea why it happen, probably a memory problem, but where to start?
Any help?

:shock:

P.s. sorry for my bad english
Last edited by finarfin on Mon Jul 19, 2010 6:39 am, edited 1 time in total.
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Strange problem :)

Post by Combuster »

Due to the lack of useful information and excess of smileys, I'll resort to my crystal ball.

Custom bootloader reading a fixed amount of sectors?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Strange problem :)

Post by Solar »

Good one.

Simple memory corruption would be my #2 guess.
Every good solution is obvious once you've found it.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Strange problem :)

Post by gerryg400 »

P.s. sorry for my bad english

_________________
Elen sila lumen omentielvo
Your English is better than your Elvish. Try...
Elen sila lumenn' omentielvo
If a trainstation is where trains stop, what is a workstation ?
Fanael
Member
Member
Posts: 38
Joined: Fri Oct 16, 2009 9:20 am

Re: Strange problem :)

Post by Fanael »

gerryg400 wrote:
P.s. sorry for my bad english

_________________
Elen sila lumen omentielvo
Your English is better than your Elvish. Try...
Elen sila lumenn' omentielvo
Better still:
Elen síla lúmenn' omentielvo
Also, there's no such thing as "Elvish language". There are many elvish languages, and this one is called Quenya.</offtopic>
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: Strange problem

Post by finarfin »

1. removed emoticons (only 1 left)
2. Corrected mi signature

And now, back to my problem,
i use grub as bootloader.

Memory corruption? is possible.
Here you find where the code user_chk is called.

Code: Select all

  do {		
    printf(LNG_USER);
    scanf ("%23s",current_user.username);
    printf(LNG_USER_R);
    #ifdef PWD_CHECK
    printf(LNG_PWD);
    scanf ("%23s",password);
    #endif
    printf("Vediamo %s\n", current_user.username);
    ret_val = user_chk(current_user.username, password);
  } while ((!strlen(current_user.username) || ret_val!=1));
and the function user_chk:

Code: Select all

int user_chk(char *username, char* usr_pwd){
	int fd = -1;
	struct passwd_user checking_user;
	printf("Username provided: %s\n", username);		
	fd = open("/passwd", O_RDONLY,0);
	if(fd<0) return 0;
	while(user_get(fd, &checking_user)==2){
		#ifdef PWD_CHECK
		if(!strcmp(username, checking_user.username) && !strcmp(usr_pwd, checking_user.password)) return 1;
		#else
		if(!strcmp(username, checking_user.username)) return 1;
		#endif
		
	}
	close(fd);
	return 0;
}
This printf:
printf("Username provided: %s\n", username);
isn't showed.
And inside open(...) "/passwd" became empty string :)
And the structure checking_user:

Code: Select all

struct passwd_user {
	char username[50];
	char password[50];
};
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Strange problem

Post by Combuster »

Still not enough information. Right now, my crystal ball says: "Solar's right"

How do you know for sure that the problem lies within the piece of code you posted? Is the problem actually in that piece of code?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: Strange problem

Post by finarfin »

I only showed where the problem happens. For showing where

Not that the problem is there. That pieces of code are involved.

the problem is that i don't know who is involved in the problem, why i have now some strings that are emptied and why all that happens only inside one function.

And probably is a memory corruption problem.
So any suggestion on how to find where, when it happens? :|
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Strange problem

Post by Brynet-Inc »

finarfin wrote:...the problem is that i don't know who is involved in the problem..
I have my suspicions about Combuster, practising magic, wizards are always up to such tricks.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Strange problem

Post by Solar »

finarfin wrote:So any suggestion on how to find where, when it happens? :|
Solar's Machete.
Every good solution is obvious once you've found it.
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: Strange problem

Post by finarfin »

The problem appear when the kernel dimension grow of 4096 bytes.

For example the kernel work until it is 80061 bytes, and it stop to work when it became 84157 bytes
(the dimension grow by 4k each time).

So i can't figure why it happens. Surely it's a memory problem. And doing some memory dump i notice that the memory area where my strings are supposed to be, are full of 0's.
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Strange problem

Post by JohnnyTheDon »

Check your linker script.
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: Strange problem

Post by finarfin »

Here, is my linker script:

Code: Select all

OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386)
ENTRY(start)
SECTIONS
{
    .text 0x100000 :
    {
        code = .; _code = .; __code = .;
        *(.text)
        . = ALIGN(4096);
    }
    .data :
    {
        data = .; _data = .; __data = .;
        *(.data)
        *(.rodata)
        . = ALIGN(4096);
    }
    .bss :
    {
        bss = .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
    }
    end = .; _end = .; __end = .;
}

Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Strange problem

Post by JohnnyTheDon »

You might want to try running objdump on your kernel image to see if anything looks messed up (pay attention to any LOAD program headers). Also check any code that might be trashing large amounts of memory (a broken memcpy implementation, for example).
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Strange problem

Post by gerryg400 »

I don't know what your problem is but let me recommend that you use ELF file format instead of binary. Grub will still load it. But the best thing is, you can inspect your code with objdump and see symbols in the disassembled code.
If a trainstation is where trains stop, what is a workstation ?
Post Reply