⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exit.c

📁 Linux2.4.20针对三星公司的s3c2410开发板的内核改造。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/kernel/exit.c * *  Copyright (C) 1991, 1992  Linus Torvalds */#include <linux/config.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/smp_lock.h>#include <linux/module.h>#include <linux/completion.h>#include <linux/personality.h>#include <linux/tty.h>#include <linux/namespace.h>#ifdef CONFIG_BSD_PROCESS_ACCT#include <linux/acct.h>#endif#include <linux/trace.h>#include <asm/uaccess.h>#include <asm/pgtable.h>#include <asm/mmu_context.h>extern void sem_exit (void);extern struct task_struct *child_reaper;int getrusage(struct task_struct *, int, struct rusage *);static void release_task(struct task_struct * p){	if (p == current)		BUG();#ifdef CONFIG_SMP	wait_task_inactive(p);#endif	atomic_dec(&p->user->processes);	free_uid(p->user);	unhash_process(p);	release_thread(p);	current->cmin_flt += p->min_flt + p->cmin_flt;	current->cmaj_flt += p->maj_flt + p->cmaj_flt;	current->cnswap += p->nswap + p->cnswap;	sched_exit(p);	p->pid = 0;	free_task_struct(p);}/* * This checks not only the pgrp, but falls back on the pid if no * satisfactory pgrp is found. I dunno - gdb doesn't work correctly * without this... */int session_of_pgrp(int pgrp){	struct task_struct *p;	int fallback;	fallback = -1;	read_lock(&tasklist_lock);	for_each_task(p) { 		if (p->session <= 0) 			continue;		if (p->pgrp == pgrp) {			fallback = p->session;			break;		}		if (p->pid == pgrp)			fallback = p->session;	}	read_unlock(&tasklist_lock);	return fallback;}/* * Determine if a process group is "orphaned", according to the POSIX * definition in 2.2.2.52.  Orphaned process groups are not to be affected * by terminal-generated stop signals.  Newly orphaned process groups are * to receive a SIGHUP and a SIGCONT. * * "I ask you, have you ever known what it is to be an orphan?" */static int will_become_orphaned_pgrp(int pgrp, struct task_struct * ignored_task){	struct task_struct *p;	read_lock(&tasklist_lock);	for_each_task(p) {		if ((p == ignored_task) || (p->pgrp != pgrp) ||		    (p->state == TASK_ZOMBIE) ||		    (p->p_pptr->pid == 1))			continue;		if ((p->p_pptr->pgrp != pgrp) &&		    (p->p_pptr->session == p->session)) {			read_unlock(&tasklist_lock); 			return 0;		}	}	read_unlock(&tasklist_lock);	return 1;	/* (sighing) "Often!" */}int is_orphaned_pgrp(int pgrp){	return will_become_orphaned_pgrp(pgrp, 0);}static inline int has_stopped_jobs(int pgrp){	int retval = 0;	struct task_struct * p;	read_lock(&tasklist_lock);	for_each_task(p) {		if (p->pgrp != pgrp)			continue;		if (p->state != TASK_STOPPED)			continue;		retval = 1;		break;	}	read_unlock(&tasklist_lock);	return retval;}/** * reparent_to_init() - Reparent the calling kernel thread to the init task. * * If a kernel thread is launched as a result of a system call, or if * it ever exits, it should generally reparent itself to init so that * it is correctly cleaned up on exit. * * The various task state such as scheduling policy and priority may have * been inherited from a user process, so we reset them to sane values here. * * NOTE that reparent_to_init() gives the caller full capabilities. */void reparent_to_init(void){	write_lock_irq(&tasklist_lock);	/* Reparent to init */	REMOVE_LINKS(current);	current->p_pptr = child_reaper;	current->p_opptr = child_reaper;	SET_LINKS(current);	/* Set the exit signal to SIGCHLD so we signal init on exit */	current->exit_signal = SIGCHLD;	current->ptrace = 0;	if ((current->policy == SCHED_OTHER) && (task_nice(current) < 0))		set_user_nice(current, 0);	/* cpus_allowed? */	/* rt_priority? */	/* signals? */	current->cap_effective = CAP_INIT_EFF_SET;	current->cap_inheritable = CAP_INIT_INH_SET;	current->cap_permitted = CAP_FULL_SET;	current->keep_capabilities = 0;	memcpy(current->rlim, init_task.rlim, sizeof(*(current->rlim)));	current->user = INIT_USER;	write_unlock_irq(&tasklist_lock);}/* *	Put all the gunge required to become a kernel thread without *	attached user resources in one place where it belongs. */void daemonize(void){	struct fs_struct *fs;	/*	 * If we were started as result of loading a module, close all of the	 * user space pages.  We don't need them, and if we didn't close them	 * they would be locked into memory.	 */	exit_mm(current);	current->session = 1;	current->pgrp = 1;	current->tty = NULL;	/* Become as one with the init task */	exit_fs(current);	/* current->fs->count--; */	fs = init_task.fs;	current->fs = fs;	atomic_inc(&fs->count); 	exit_files(current);	current->files = init_task.files;	atomic_inc(&current->files->count);}/* * When we die, we re-parent all our children. * Try to give them to another thread in our thread * group, and if no such member exists, give it to * the global child reaper process (ie "init") */static inline void forget_original_parent(struct task_struct * father){	struct task_struct * p;	read_lock(&tasklist_lock);	for_each_task(p) {		if (p->p_opptr == father) {			/* We dont want people slaying init */			p->exit_signal = SIGCHLD;			p->self_exec_id++;			/* Make sure we're not reparenting to ourselves */			p->p_opptr = child_reaper;			p->first_time_slice = 0;			if (p->pdeath_signal) send_sig(p->pdeath_signal, p, 0);		}	}	read_unlock(&tasklist_lock);}static inline void close_files(struct files_struct * files){	int i, j;	j = 0;	for (;;) {		unsigned long set;		i = j * __NFDBITS;		if (i >= files->max_fdset || i >= files->max_fds)			break;		set = files->open_fds->fds_bits[j++];		while (set) {			if (set & 1) {				struct file * file = xchg(&files->fd[i], NULL);				if (file)					filp_close(file, files);			}			i++;			set >>= 1;			debug_lock_break(1);			conditional_schedule();		}	}}void put_files_struct(struct files_struct *files){	if (atomic_dec_and_test(&files->count)) {		close_files(files);		/*		 * Free the fd and fdset arrays if we expanded them.		 */		if (files->fd != &files->fd_array[0])			free_fd_array(files->fd, files->max_fds);		if (files->max_fdset > __FD_SETSIZE) {			free_fdset(files->open_fds, files->max_fdset);			free_fdset(files->close_on_exec, files->max_fdset);		}		kmem_cache_free(files_cachep, files);	}}static inline void __exit_files(struct task_struct *tsk){	struct files_struct * files = tsk->files;	if (files) {		task_lock(tsk);		tsk->files = NULL;		task_unlock(tsk);		put_files_struct(files);	}}void exit_files(struct task_struct *tsk){	__exit_files(tsk);}static inline void __put_fs_struct(struct fs_struct *fs){	/* No need to hold fs->lock if we are killing it */	if (atomic_dec_and_test(&fs->count)) {		dput(fs->root);		mntput(fs->rootmnt);		dput(fs->pwd);		mntput(fs->pwdmnt);		if (fs->altroot) {			dput(fs->altroot);			mntput(fs->altrootmnt);		}		kmem_cache_free(fs_cachep, fs);	}}void put_fs_struct(struct fs_struct *fs){	__put_fs_struct(fs);}static inline void __exit_fs(struct task_struct *tsk){	struct fs_struct * fs = tsk->fs;	if (fs) {		task_lock(tsk);		tsk->fs = NULL;		task_unlock(tsk);		__put_fs_struct(fs);	}}void exit_fs(struct task_struct *tsk){	__exit_fs(tsk);}/* * We can use these to temporarily drop into * "lazy TLB" mode and back. */struct mm_struct * start_lazy_tlb(void){	struct mm_struct *mm = current->mm;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -