[uClinux-dev] execve function of linux-2.4.x of uClinux-dist-20070130 misbehavior

=?gb2312?B?y84gaHo=?= chinadldz2002 at hotmail.com
Sat Feb 24 08:43:22 EST 2007


Hi everybody,

I modified the dispargv.c, so it can show both argv and envp:

############
dispargv.c
############
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[], char *envp[])
{
        int tmp = 0;

        printf("argv = %p\n", argv);
        while(argv[tmp] != NULL)
        {
                printf("arg[%d]: %s\n", tmp, argv[tmp]);
                tmp++;
        }

        tmp = 0;
        while(envp[tmp] != NULL)
        {
                printf("env[%d]: %s\n", tmp, envp[tmp]);
                tmp++;
        }
        return 0;
}
###################################
And now the result is (without showing the address of argv):
/> diapargv haha xixi wuwu
arg[0]: >
arg[1]: >
arg[2]: dispargv
arg[3]: haha
arg[4]: xixi
arg[5]: wuwu
env[0]: wuwu

We could see that envp[0] point to the last argument of argv, so we can 
know both argv and envp pointers are offset backward by 2. I began to 
suspect the fs/binfmt_flat.c: create_flat_tables() function, but no logic 
errors can be found. I tried to modified it to see if it's that function's 
problem:
133:        put_user(argc,--sp);
               // Added by Song
               printk("fs/binfmt_flat.c: create_flat_tables(): 
argv=0x%p\n", argv);
               p+=2;
               // Added by Song: above
134:        current->mm->arg_start = (unsigned long) p;

And now:
/> diapargv haha xixi wuwu
arg[0]: >
arg[1]: >
arg[2]: spargv       // NOTE: NO "di" here
arg[3]: haha
arg[4]: xixi
arg[5]: wuwu
env[0]: wuwu
So it won't be that function's problem.

After adding the address display:
/> dispargv haha xixi wuwu
fs/binfmt_flat.c: create_flat_tables(): argv=0x003fff7c
argv = 0x3fff74    // argv in dispargv
arg[0]: ?
arg[1]: ?
arg[2]: spargv
arg[3]: haha
arg[4]: xixi
arg[5]: wuwu
env[0]: wuwu

0x003fff7c - 0x3fff74 = 8 just equals 2*sizeof(char *).

So what is the problem?

Regards,
Song

_________________________________________________________________
Ãâ·ÑÏÂÔØ MSN Explorer:   http://explorer.msn.com/lccn  



More information about the uClinux-dev mailing list