Академический Документы
Профессиональный Документы
Культура Документы
Set up
The process descriptor Any other kernel data structure required for a child's execution
Its parameters are the same as do_fork( ), plus the PID of the child.
Security Checks
invoke security_task_create( )
dup_task_struct( )
Get the process descriptor for the child
Executes the alloc_thread_info macro to get a free memory area to store the thread_info structure and the Kernel Mode stack of the new process, and saves its address in the ti local variable.
The size of this memory area is either 8 KB or 4 KB
..
..
copy_process( )- Check the Number of Processes Belonging to the Owner of the Parent Process
Checks whether the value stored in current->signal>rlim[RLIMIT_NPROC].rlim_cur is smaller than or equal to the current number of processes owned by the user.
If so, an error code is returned, unless the process has root privileges.
The function gets the current number of processes owned by the user from a per-user data structure named user_struct.
This data structure can be found through a pointer in the user field of the process descriptor.
..
if (atomic_read(&p->user->processes) >= p->signal->rlim[RLIMIT_NPROC].rlim_cur) { if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && p->user != current->nsproxy->user_ns->root_user) goto bad_fork_free; }
..
copy_process( )- Make Sure That the Number of Processes in the System Doesnt Pass Limitation
Checks that the number of processes in the system (nr_threads) does not exceed the value of the max_threads variable.
The default value of max_threads depends on the amount of RAM in the system. The system administrator may change this value by writing in the /proc/sys/kernel/threads-max file.
Updates some of the flags included in the tsk>flags field that have been copied from the parent process:
clears the PF_SUPERPRIV flag This flag indicates whether the process has used any of its superuser privileges, sets the PF_FORKNOEXEC flag This flag indicates that the child has not yet issued an execve( ) system call.
copy_process( )- Initializes Childs list_head data structures and the spin locks
Initializes the list_head data structures and the spin locks included in the child's process descriptor, and sets up several other fields related to
pending signals timers time statistics
The thread.rsp0 field in the descriptor of the child process is initialized with the base address of the child's Kernel Mode stack
top of stack
copy_thread( ) Set I/O Permission Bitmap and TLS(Thread Local Storage) Segment
If the parent process makes use of an I/O Permission Bitmap, the child gets a copy of such bitmap
29
Finally, if the CLONE_SETTLS flag is set, the child gets the TLS segment specified by the User Mode data structure pointed to by the tls parameter of the clone( ) system call
copy_process( )- child_tidptr
If either CLONE_CHILD_SETTID or CLONE_CHILD_CLEARTID is set in the clone_flags parameter, it copies the value of the child_tidptr parameter in the tsk->set_child_tid or tsk->clear_child_tid field, respectively.
31
These flags specify that the value of the variable pointed to by child_tidptr in the User Mode address space of the child has to be changed, although the actual write operations will be done later
33
copy_process( )- sched_fork( )
Invokes sched_fork( ) to complete the initialization of the scheduler data structure of the new process. The function also
sets the state of the new process to TASK_RUNNING sets the preempt_count field of the thread_info structure to 1, thus disabling kernel preemption
. /* Perform scheduler related setup. Assign this task to a CPU. */
sched_fork(p, clone_flags);
..
34
Moreover, in order to keep process scheduling fair, the function shares the remaining time slice of the parent between the parent and the child (scheduler_tick( ))
36
38
40
41
42
attach_pid(p, PIDTYPE_PID, pid); nr_threads++; } total_forks++; spin_unlock(¤t->sighand->siglock); write_unlock_irq(&tasklist_lock); proc_fork_connector(p); cgroup_post_fork(p); return p;
}
43