Fork & Exec inside Kernel

Fork & Exec inside Kernel

Post by Roland de Gilea » Sat, 01 Jul 2000 04:00:00



I have done a new system-call named spawn.
Kernel and glibc are correctly updated and both know "spawn".

     spawn(char *filename, char **argv, char **envp, unsigned int args)

This system call first do a fork and then an execve in the created child.

My problem is when i call spawn: spawn("/bin/ls", argv, envp, FLAGS);
execve succeeds (return value is 0) but in fact nothing appends !!! ?

i have tried to make this in two different ways.

*********************
*    FIRST WAY             *
*********************

1.) sys_spawn call do_spawn
---------------------------

2.) do_spawn call my_fork
-------------------------

3.) my_fork  (/usr/src/linux/kernel/fork.c)
-------------------------------------------

my_fork is exactly the same as do_fork but call mycopy_thread in place of
copy_thread

i have
 => retval = mycopy_thread(nr, clone_flags, usp, p, regs);

in place of
 => retval = copy_thread(nr, clone_flags, usp, p, regs);

3.) mycopy_thread (/usr/src/linux/arch/i386/kernel/process.c)
-------------------------------------------------------------
 mycopy_thread is exactly the same as copy_thread except two lines

i have
 => memcpy(&my_regs, childregs, sizeof(struct pt_regs));
 => p->tss.eip = (unsigned long) my_last_function;

in place of

 => p->tss.eip = (unsigned long) ret_from_fork

where my_regs is "actually" an "ugly" global variable.

4.) my_last_function
--------------------

void   my_last_function(void)
{
  char  *filename;
  int  error;

  filename = getname((char*)my_regs.ebx);
  error = do_execve(filename, (char**) my_regs.ecx, (char**) my_regs.edx,
&my_regs);
  ret_from_fork();

Quote:}

So error is zero .. but do_execve does nothing at all.

*********************
*    SECOND WAY     *
*********************

1.) sys_spawn call do_spawn
---------------------------

2.) do_spawn
-------------

do_spawn uses kernel_thread

   waitpid = kernel_thread(my_execve, spawnstr, CLONE_FS | CLONE_FILES |
CLONE_SIGHAND | CLONE_VFORK);

3.) my_execve (/usr/src/linux/fs/exec.c)
-----------------------------------------

my_execve is exactly the same as do_execve but the function prototype is

 my_execve(struct s_spawn *spawnstr)

and the structure s_spawn is

 struct   s_spawn
 {
   char         *filename;
   char    **argv;
   char    **envp;
   struct pt_regs  *regs;
 }

of course i have changed in my_execve

 filename  to  spawnstr->filename
 argv    to spawnstr->argv
 envp  to spawnstr->envp
 regs  to spawnstr->regs

Finally the result is the same .. execve returns zero but doesn't execute
anything.

NOTES
--------

I tried to check the different parms do_execve takes, and all of
them where correct: like the filename, argv and envp.

I also tried to check if the flag current->flags was alright.
(like cheking if PF_FORKNOEXEC was set)

I need help :)
Thanx

 
 
 

1. Efficiency: fork() w/ shared libraries vs. fork()/exec()

I want to create a multiprocess application where each process has
a specialized and distinct function.

I can either fork()/exec() separate programs for each process
or link of the separate programs into a single dynamically linked image
and fork() multiple instances of it.

Question: which approach is the more efficient (under SunOS 4.1.x and 5.x)?

-Paul O'Keefe

2. QUE: IIS 4.0 log file analysis using a Linux tool

3. Q: fork() & exec() question

4. Need a DOS Telnet commerical program!

5. exec & fork in a system call

6. Kmail and gpg / pgp

7. fork & exec

8. where is WINOS2.ZIP at tsx-11.mit.edu?

9. exec & fork in a system call

10. Concurrent, non-(blocking&&threaded&&forking) server

11. What's the difference between in Exec and Exec exec ...

12. pipes inside find -exec

13. Using pipes inside of find -exec