Main Page | Directories | File List | Globals

fork.c File Reference

#include <agnix/agnix.h>
#include <asm/types.h>
#include <agnix/sched.h>
#include <asm/tss.h>
#include <agnix/memory.h>
#include <agnix/tasks.h>
#include <agnix/fs.h>
#include <agnix/list.h>
#include <agnix/data_structures.h>
#include <agnix/spinlock.h>
#include <agnix/errno.h>
#include <agnix/console.h>

Include dependency graph for fork.c:

Go to the source code of this file.

Functions

int fork_add_hash_entry (int pid, struct task_s *task)
task_s * fork_find_hash_entry (int pid)
int get_free_pid (void)
void put_free_pid (int pid)
int do_sys_fork (struct regs_s *regs)
int do_task_exit (struct task_s *task, int exit_code)
int do_sys_exit (int exit_code)
int fork_init (void)

Variables

list_head tasks_list
spinlock_t tasks_list_lock
list_head running_tasks_list
spinlock_t running_list_lock
int fork_hashd


Function Documentation

int do_sys_exit int  exit_code  ) 
 

Definition at line 123 of file fork.c.

References do_task_exit().

Referenced by SYS_CALL().

00124 {
00125     do_task_exit(current_task, exit_code);
00126 
00127     return 0;
00128 }

Here is the call graph for this function:

int do_sys_fork struct regs_s *  regs  ) 
 

Definition at line 59 of file fork.c.

References files_fork(), fork_add_hash_entry(), get_free_pages(), get_free_pid(), kernel_panic(), sched_activate_task(), sched_add_task(), signals_fork(), and task_fork().

Referenced by SYS_CALL().

00060 {
00061     struct task_s *cur_task = current_task;
00062     struct task_s *new_task;
00063     struct tss_wrap_s *new_tss_wrap;
00064     int pid;
00065     int ret;
00066 
00067     new_task = (struct task_s *)get_free_pages(1);
00068 
00069     ret = -EAGAIN;
00070     if ((pid = get_free_pid()) < 0)
00071         goto do_sys_fork_error;
00072         
00073     new_task->t_pid = pid;
00074 
00075     ret = -ENOMEM;
00076     if ((new_tss_wrap = task_fork(regs, (u32)new_task + 0x1000)) == 0)
00077         goto do_sys_fork_error;
00078         
00079     new_task->tss_wrap  = new_tss_wrap;    
00080     new_task->t_state   = TASK_STAT_STARTING;
00081     new_task->t_count   = INIT_COUNT;
00082     new_task->term      = current_task->term;
00083     new_tss_wrap->task  = new_task;
00084 
00085     if (files_fork(cur_task, new_task) != 0)
00086         goto do_sys_fork_error;
00087 
00088     if (signals_fork(cur_task, new_task) != 0)
00089         goto do_sys_fork_error;
00090 
00091     if (fork_add_hash_entry(pid, new_task) == -1) {
00092         kernel_panic("Cannot add task's pid to hash table!\n");
00093         return -1;
00094     }
00095 
00096     INIT_LIST_HEAD(&(new_task->task_list));
00097     
00098     sched_add_task(new_task);    
00099     sched_activate_task(new_task);
00100 
00101     ret = 0;
00102     
00103 do_sys_fork_error:
00104 
00105     return ret;
00106 }

Here is the call graph for this function:

int do_task_exit struct task_s *  task,
int  exit_code
 

Definition at line 108 of file fork.c.

References flags, put_free_pid(), running_list_lock, and task_exit().

Referenced by do_sys_exit(), and execute_signals().

00109 {
00110     u32 flags;
00111 
00112     spin_lock_irqsave(&running_list_lock, flags);
00113     list_del(&(task->task_list));
00114     spin_unlock_irqrestore(&running_list_lock, flags);
00115 
00116     put_free_pid(task->t_pid);
00117 
00118     task_exit(task->tss_wrap);
00119 
00120     return 0;
00121 }

Here is the call graph for this function:

int fork_add_hash_entry int  pid,
struct task_s *  task
 

Definition at line 35 of file fork.c.

References fork_hashd, and hash_entry_add().

Referenced by do_sys_fork(), and fork_init().

00036 {
00037     return hash_entry_add(fork_hashd, (u32)pid, (u32)task);
00038 }

Here is the call graph for this function:

struct task_s* fork_find_hash_entry int  pid  ) 
 

Definition at line 40 of file fork.c.

References fork_hashd, and hash_entry_find().

Referenced by send_signal_to_pid().

00041 {
00042     u32 task_ptr;
00043     
00044     task_ptr = hash_entry_find(fork_hashd, (u32)pid);
00045     
00046     return (struct task_s *)task_ptr;
00047 }

Here is the call graph for this function:

int fork_init void   ) 
 

Definition at line 130 of file fork.c.

References fork_add_hash_entry(), fork_hashd, kernel_panic(), and register_hash_table().

Referenced by start_kernel().

00131 {
00132     if ((fork_hashd = register_hash_table("fork", 1024, NULL)) < 0) {
00133         kernel_panic("Can not create hash table for fork!\n");
00134         
00135         return -1;
00136     }
00137 
00138     fork_add_hash_entry(0, current_task);
00139 
00140     return 0;
00141 }

Here is the call graph for this function:

int get_free_pid void   ) 
 

Definition at line 49 of file fork.c.

Referenced by do_sys_fork().

00050 {
00051     return ++last_pid;
00052 }

void put_free_pid int  pid  ) 
 

Definition at line 54 of file fork.c.

Referenced by do_task_exit().

00055 {
00056     return;
00057 }


Variable Documentation

int fork_hashd
 

Definition at line 32 of file fork.c.

Referenced by fork_add_hash_entry(), fork_find_hash_entry(), and fork_init().

spinlock_t running_list_lock
 

Definition at line 27 of file sched.c.

Referenced by do_task_exit(), sched_activate_task(), sched_add_task(), sched_deactivate_task(), schedule_task(), scheduler_init(), and scheduler_print_tasks().

struct list_head running_tasks_list
 

Definition at line 25 of file sched.c.

Referenced by reschedule_task(), sched_activate_task_lock(), schedule_task(), and scheduler_init().

struct list_head tasks_list
 

Definition at line 26 of file sched.c.

Referenced by sched_add_task_lock(), scheduler_init(), and scheduler_print_tasks().

spinlock_t tasks_list_lock
 

Definition at line 28 of file sched.c.

Referenced by scheduler_init().

Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix