OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:17 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Please help me solve the problem with fork
PostPosted: Wed Jul 31, 2019 6:33 am 
Offline

Joined: Wed Jul 31, 2019 6:18 am
Posts: 5
Good day to all.
I am learning from the tutorial by jamesmolloy (http://www.jamesmolloy.co.uk/tutorial_html/). Thank him for a good tutorial. I wrote my own heap to fix some errors. Fork works fine in kernel mode. But I see errors in user mode (sys_fork()). If the fork first returns 0, the child process will stop working, and the parent process and the rest will continue. Otherwise, everything works correctly. How can I find out where the error is?
Please help me find a bug.


Top
 Profile  
 
 Post subject: Re: Please help me solve the problem with fork
PostPosted: Wed Jul 31, 2019 6:40 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
I see you wrote your own heap implementation to fix some bugs in the tutorial. Did you fix the other bugs in the tutorial too?


Top
 Profile  
 
 Post subject: Re: Please help me solve the problem with fork
PostPosted: Wed Jul 31, 2019 6:47 am 
Offline

Joined: Wed Jul 31, 2019 6:18 am
Posts: 5
Octocontrabass wrote:
I see you wrote your own heap implementation to fix some bugs in the tutorial. Did you fix the other bugs in the tutorial too?

Yes. I corrected the errors described there. But I didn’t know where to start rewriting multitasking. It also worked well in kernel mode. Then I got rid of the move_stack () function. According to my observations, I often get the right job, but the problem has not yet been solved.

Code:
   if (current_task == parent_task)
   {
      uint32_t esp; asm volatile("mov %%esp, %0" : "=r"(esp));
      uint32_t ebp; asm volatile("mov %%ebp, %0" : "=r"(ebp));

      if (current_task->kernel_stack > new_task->kernel_stack) {
         new_task->esp = esp - (current_task->kernel_stack - new_task->kernel_stack);
         new_task->ebp = ebp - (current_task->kernel_stack - new_task->kernel_stack);
      } else {
         new_task->esp = esp + (new_task->kernel_stack - current_task->kernel_stack);
         new_task->ebp = ebp - (current_task->kernel_stack - new_task->kernel_stack);
      }
      memcpy((void *)(new_task->kernel_stack - 2048), (void *)(current_task->kernel_stack - 2048), 2048);

   //   new_task->esp            = esp;
   //   new_task->ebp            = ebp;
      new_task->eip            = eip;

      asm volatile("sti");

      return new_task->id;
   }


Top
 Profile  
 
 Post subject: Re: Please help me solve the problem with fork
PostPosted: Wed Jul 31, 2019 8:27 am 
Offline

Joined: Wed Jul 31, 2019 6:18 am
Posts: 5
Image
Image
When system/init launched, the init goes into user mode. system/init calls the system call fork. Then either the child breaks down or works correctly. In 3, the fork is called again.

Code:
void switch_to_user_mode(uintptr_t location)
{
   asm volatile("sti");

   set_kernel_stack(current_task->kernel_stack);

   asm volatile(      "mov $0x23, %%ax\n"
               "mov %%ax, %%ds\n"
               "mov %%ax, %%es\n"
               "mov %%ax, %%fs\n"
               "mov %%ax, %%gs\n"
               "mov %%esp, %%eax\n"
               "pushl $0x23\n"
               "pushl %%eax\n"
               "pushf\n"
               "popl %%eax\n"
               "orl  $0x200, %%eax\n"
               "pushl %%eax\n"
               "pushl $0x1B\n"
               "pushl %0\n"
               "iret\n"
               : : "m"(location));
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group