aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/cdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/cdev.c')
0 files changed, 0 insertions, 0 deletions
ption value='wip-nested-locking'>wip-nested-locking The LITMUS^RT kernel.Bjoern Brandenburg
aboutsummaryrefslogblamecommitdiffstats
path: root/kernel/signal.c
blob: bded65187780f5f288bd779920a5c04c190528dc (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                  

                         







                           
                         
                           
                            
                            
                             
                          

                                

                                
 



                        
                                                 




                               
                                          
 

                                      
                                                               
 

                                                         
 

                                                             
                                                     


                                                               
 

                                                           
 
                             
 


                                                             
                                                                




                                                 
                                                                            
 




                                                       
                                                                                

                         
                                                        




                                                               
                                                          

































                                                                          
                                                       


                                                
                                                               
                                                       

                         




                                                                               










                                                                              



                            


                                                                       

                                                  



                                                                              



                                                                 
                                                           


                                   
 

                                












                                                              

                              






                                                        

                      


                                 
                              
                                              

                      

                                   

                      
 


                   













                                                                                 


                                                                               
                                                                      
   

                                                                                  

                                  
                                 
 
          

                                                                      
           
                        
                                             
                                      
                          
 
                              
                                             
                                                            
                                                             



                                          
                                  
                                              
                               


                                         
                               
         

                 

 
                                               







                                            
                                             













                                                                         






                                                   
                                         



                                                       
                           


                                                            

































                                                              









                                                              
  
















                                                                  

                                                      
                                                                         
                                
                         
                                                     
                         
                                                          

 


































                                                                           
                                                                             

                                          
 





                                                                    

                                                   


                                  


                                      
                    
              


                                                 
                



                                                             

                                     
                                        


                                 




                                                                       
                                             
 









                                                                                   
                                                   
         











                                                                            
                  



                                                                       
                                                            
                     

                                                                      























                                                                           
 
                            



                                               











                                                                           
                                                           
         
                                                                                






























                                                                      

                                                                             





                                                                           
                                      








                                                         


























                                                                   


















                                                                  










                                                            

                                         
                                           



                                                               
                                        
                        

                  
                               

                               
                               
                         
 

                                                                                
                             
 
                              
                               

                                             


                                         


                                 
                                              









                                                                          
 
                                                   

 
  

                                                                     

                                                                      



                                                                     
   
                                                                               
 
                                                 

                              
                                                          
                  
                                                                        
                   
                                          


                                                                          
                                                                         


                                                                     
                                          
                                    
                                 



                                                           
                                                                             



                                                                         








                                                                          
                                              



                                                                     
                                               




                                                                                                 
                                          
 








                                                                           
                                                        
                                                    
                                                  


                                                  
                          
                                                                               


                                                                           


                                                                    





                                                                         
                                                               
                 
         
 
                                                      

 




















                                                                           
                                                                      











                                                                             
                                                 


























                                                                             

                                                                         
                                                  
                              
                                                         





























                                                                       




                                                                      

                                                                              
 
                                   
                           
                            
 
                                            
 
                                                 

                                                      
                         

                                                                   
          



                                                              
                                       
                         
          


                                                                      
                                    









                                                                   




                                                                              
                                                                               
                                 
                
                                                        
                                               
                                                     


                                                  
                                                                 
                                                                               
                                                       
                              
                                                   







                                                     

                                                   

                              
                                          






                                                                         
                                       






                                                                          


         
                                
                                         

                                       

 


                                                                            


                                 

                                                                           


                                                                    

 


                                                                  
                                                            
 
                                              
                                            




                                           

                                                                            




                                              
                          
                        
                         









                                                           
 





                                                                           


                                                                            
                                            

 













                                                                          


                                                             




                                                                 

                                                              
   



                                                                    

                                   

                                                       






                                                    
                                                      
                 
         

                                                       





                                                            


                                       
                                            
 

                                  
 

                                        



                                                            

                                  
                                                       

                                     

                     

 



                                                                                       
                        









                                                                  
                          



                       

                                                 
   

                                                                             




                                                  
 

                                                           




                   
                                                                             
                                     
                                                              
   
                                                                     



                                     

                        
                                                 


                                                            
                                                     


                                    
                                                                 
 
                           

                              
                        
      
                                       
                
                                                          








                                                                       
                          
 


                     

                                                        


                        
                                                         



                          

                                                                        
                                                       


                              
                                 
                            



                               
                        
                                       



                                
                               
                                

                                                        


                                


                                                      






                                                                

           
                          

                   
                                        







                                                                              
                                                                        
 
                












                                                                            


                                          
                                     

                                                                         





                                                                            
                                              
         

                                    
                   





                                                                           


                                                                   



                                                                 
                               

                               
                                                     

 


                                                  


                                                  
                                                         

 


                                         
                                              




















                                                                    

                                                 






                                                             








                                                           



                                                                      
                                                                



                                                                        

                                     
                                                                          
 
              
                                              

                 




                                      

                                                      

                                                

                                                       
                                             
           
                                       




                                                          
                                  
                         

                                            

                                   

 
                                                                       
 
                                   
                                   

                            
 
                                                




                                                  
                                            
                                       


                         




                                                                       

                                                    
                         
         
                               
 
                                
                                                                   

                                                
                                       



                                       

 
  

                                                                               


                                                               
   
                                                      



                                    
                      



                                                                        
                                               
 
                                   



                                                                       













                                                                        
                                            

                          



                                                                  












                                                     
                                                  
















                                                                           
                                            
                                                                     
                                 
         
                                         


                                                               
 
                   

 
                                                                      


                            
                                   

                                       
                             





                                          

                                



                                                                       
                                                                   
                                            

                          

                                                       



























                                                                         

                                       
                                          
                         





                                                                     
                                                                   

                                       
                                                





                                                         
  




                                                                    

                                                                          


  






                                                           

                                                              
   
                                                                       
 














                                                                               

                                             

         










                                                    
                                         

                                                    
                                
                                                               






                                                               
                                            
                                            



                                                                     
                                                                    
                   
                                                  

                                               
                                            


          






                                                                         









                                                                          
                                                         
           
                                       










                                                          
                                            
                                    


                                                  
                                         


                                                    





                                                                      
                                    

                                                    
                   
 
                                     

                                      
                                                                 
                                                     
                                 

                                                              
                                            
                   
                                             
 
                                          
                                                                                
                          


                                                                     
                           
                                                       
                                                            
                                                        

                                                     
         


















                                                                       
 












                                                                      
 


                 


                                                            
                                  






















                                                             
                                                         










                                                              


                                                                         


                                                          
 






                                                                               

                        
                                         




                                                                       

                                                                 
                                                              
                                                  
 

                                                                
 




                                                                             


                            

                                       










                                                                               



                                                                     

                                                                          
 
                                   









                                                                    

                 


                                                       

















                                                                       
                  
                                                               






                                                                              
                   
                                                                  
                                                        













                                                                               
                                                                   


                                                                              
                                                               

                                                    
                                                                 

                         
                                                                     










                                                                 
                                                   




                                                                  
 
                                                 
                                                
                                                                         







                                                                           
                                                                          




                                               
                                              

                                
                                           


                     


                                          
                              
 


                                                                        

         
                                              




                                                                    













                                                                   
                                                                             

         

                                                
                                   
                                          
                                                          



                                            



                                  










                                   
                                


























                                                                              

                                                  


                                           















                                                                       
 


                     

                                                                 

























































                                                                           
                                                                          

















                                                                  

                                                                     

















































                                                                          


                                                                               













































                                                                                 
                                                                          
 























                                                                     
                                           





                               
                                             
                                    



                                                    

                                                                      
 
                              
                           
 
                        
                                   
                                                           
                                                            



                                                                         








                                                                               

                 
                          
 


                     












                                                       





                                                   
                                                                         


                                                                         
                                                          







                                                 


                                                                     
                                            
 



                                                 
                                     

 

                                                      















                                                                         

























                                                                          
                                                                            
 
                                        
                              
                      
 
                                                                           

                               
                                       

                                                  



                           

                                                                   
                          










                                                                              
                                                                    


                                                                              
                            
                                                                       

                                                   
                 











                                                                                  


                                                       






                                   





                                                               






























                                                                                      
                  

                                
                                                                  
                                 


                                                                  

         





                                 
                                                       









                                                                      

                                                                  
















































                                                                  



                                                     




























                                                                             
                         




                                       
                                       


















                                                                       
                                                          





                                                    
                                        








                                                               
                      







                                            
                                    
                                                                              


















                                                                       
                              



                                          




                                                                           

                              
                                                           
 







































                                                                              
/*
 *  linux/kernel/signal.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *
 *  1997-11-02  Modified for POSIX.1b signals by Richard Henderson
 *
 *  2003-06-02  Jim Houston - Concurrent Computer Corp.
 *		Changes to use preallocated sigqueue structures
 *		to allow signals to be sent reliably.
 */

#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/tty.h>
#include <linux/binfmts.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/ptrace.h>
#include <linux/signal.h>
#include <linux/signalfd.h>
#include <linux/ratelimit.h>
#include <linux/tracehook.h>
#include <linux/capability.h>
#include <linux/freezer.h>
#include <linux/pid_namespace.h>
#include <linux/nsproxy.h>
#define CREATE_TRACE_POINTS
#include <trace/events/signal.h>

#include <asm/param.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <asm/siginfo.h>
#include "audit.h"	/* audit_signal_info() */

/*
 * SLAB caches for signal bits.
 */

static struct kmem_cache *sigqueue_cachep;

int print_fatal_signals __read_mostly;

static void __user *sig_handler(struct task_struct *t, int sig)
{
	return t->sighand->action[sig - 1].sa.sa_handler;
}

static int sig_handler_ignored(void __user *handler, int sig)
{
	/* Is it explicitly or implicitly ignored? */
	return handler == SIG_IGN ||
		(handler == SIG_DFL && sig_kernel_ignore(sig));
}

static int sig_task_ignored(struct task_struct *t, int sig,
		int from_ancestor_ns)
{
	void __user *handler;

	handler = sig_handler(t, sig);

	if (unlikely(t->signal->flags & SIGNAL_UNKILLABLE) &&
			handler == SIG_DFL && !from_ancestor_ns)
		return 1;

	return sig_handler_ignored(handler, sig);
}

static int sig_ignored(struct task_struct *t, int sig, int from_ancestor_ns)
{
	/*
	 * Blocked signals are never ignored, since the
	 * signal handler may change by the time it is
	 * unblocked.
	 */
	if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig))
		return 0;

	if (!sig_task_ignored(t, sig, from_ancestor_ns))
		return 0;

	/*
	 * Tracers may want to know about even ignored signals.
	 */
	return !tracehook_consider_ignored_signal(t, sig);
}

/*
 * Re-calculate pending state from the set of locally pending
 * signals, globally pending signals, and blocked signals.
 */
static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
{
	unsigned long ready;
	long i;

	switch (_NSIG_WORDS) {
	default:
		for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
			ready |= signal->sig[i] &~ blocked->sig[i];
		break;

	case 4: ready  = signal->sig[3] &~ blocked->sig[3];
		ready |= signal->sig[2] &~ blocked->sig[2];
		ready |= signal->sig[1] &~ blocked->sig[1];
		ready |= signal->sig[0] &~ blocked->sig[0];
		break;

	case 2: ready  = signal->sig[1] &~ blocked->sig[1];
		ready |= signal->sig[0] &~ blocked->sig[0];
		break;

	case 1: ready  = signal->sig[0] &~ blocked->sig[0];
	}
	return ready !=	0;
}

#define PENDING(p,b) has_pending_signals(&(p)->signal, (b))

static int recalc_sigpending_tsk(struct task_struct *t)
{
	if (t->signal->group_stop_count > 0 ||
	    PENDING(&t->pending, &t->blocked) ||
	    PENDING(&t->signal->shared_pending, &t->blocked)) {
		set_tsk_thread_flag(t, TIF_SIGPENDING);
		return 1;
	}
	/*
	 * We must never clear the flag in another thread, or in current
	 * when it's possible the current syscall is returning -ERESTART*.
	 * So we don't clear it here, and only callers who know they should do.
	 */
	return 0;
}

/*
 * After recalculating TIF_SIGPENDING, we need to make sure the task wakes up.
 * This is superfluous when called on current, the wakeup is a harmless no-op.
 */
void recalc_sigpending_and_wake(struct task_struct *t)
{
	if (recalc_sigpending_tsk(t))
		signal_wake_up(t, 0);
}

void recalc_sigpending(void)
{
	if (unlikely(tracehook_force_sigpending()))
		set_thread_flag(TIF_SIGPENDING);
	else if (!recalc_sigpending_tsk(current) && !freezing(current))
		clear_thread_flag(TIF_SIGPENDING);

}

/* Given the mask, find the first available signal that should be serviced. */

#define SYNCHRONOUS_MASK \
	(sigmask(SIGSEGV) | sigmask(SIGBUS) | sigmask(SIGILL) | \
	 sigmask(SIGTRAP) | sigmask(SIGFPE))

int next_signal(struct sigpending *pending, sigset_t *mask)
{
	unsigned long i, *s, *m, x;
	int sig = 0;

	s = pending->signal.sig;
	m = mask->sig;

	/*
	 * Handle the first word specially: it contains the
	 * synchronous signals that need to be dequeued first.
	 */
	x = *s &~ *m;
	if (x) {
		if (x & SYNCHRONOUS_MASK)
			x &= SYNCHRONOUS_MASK;
		sig = ffz(~x) + 1;
		return sig;
	}

	switch (_NSIG_WORDS) {
	default:
		for (i = 1; i < _NSIG_WORDS; ++i) {
			x = *++s &~ *++m;
			if (!x)
				continue;
			sig = ffz(~x) + i*_NSIG_BPW + 1;
			break;
		}
		break;

	case 2:
		x = s[1] &~ m[1];
		if (!x)
			break;
		sig = ffz(~x) + _NSIG_BPW + 1;
		break;

	case 1:
		/* Nothing to do */
		break;
	}

	return sig;
}

static inline void print_dropped_signal(int sig)
{
	static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10);

	if (!print_fatal_signals)
		return;

	if (!__ratelimit(&ratelimit_state))
		return;

	printk(KERN_INFO "%s/%d: reached RLIMIT_SIGPENDING, dropped signal %d\n",
				current->comm, current->pid, sig);
}

/*
 * allocate a new signal queue record
 * - this may be called without locks if and only if t == current, otherwise an
 *   appopriate lock must be held to stop the target task from exiting
 */
static struct sigqueue *
__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
{
	struct sigqueue *q = NULL;
	struct user_struct *user;

	/*
	 * Protect access to @t credentials. This can go away when all
	 * callers hold rcu read lock.
	 */
	rcu_read_lock();
	user = get_uid(__task_cred(t)->user);
	atomic_inc(&user->sigpending);
	rcu_read_unlock();

	if (override_rlimit ||
	    atomic_read(&user->sigpending) <=
			task_rlimit(t, RLIMIT_SIGPENDING)) {
		q = kmem_cache_alloc(sigqueue_cachep, flags);
	} else {
		print_dropped_signal(sig);
	}

	if (unlikely(q == NULL)) {
		atomic_dec(&user->sigpending);
		free_uid(user);
	} else {
		INIT_LIST_HEAD(&q->list);
		q->flags = 0;
		q->user = user;
	}

	return q;
}

static void __sigqueue_free(struct sigqueue *q)
{
	if (q->flags & SIGQUEUE_PREALLOC)
		return;
	atomic_dec(&q->user->sigpending);
	free_uid(q->user);
	kmem_cache_free(sigqueue_cachep, q);
}

void flush_sigqueue(struct sigpending *queue)
{
	struct sigqueue *q;

	sigemptyset(&queue->signal);
	while (!list_empty(&queue->list)) {
		q = list_entry(queue->list.next, struct sigqueue , list);
		list_del_init(&q->list);
		__sigqueue_free(q);
	}
}

/*
 * Flush all pending signals for a task.
 */
void __flush_signals(struct task_struct *t)
{
	clear_tsk_thread_flag(t, TIF_SIGPENDING);
	flush_sigqueue(&t->pending);
	flush_sigqueue(&t->signal->shared_pending);
}

void flush_signals(struct task_struct *t)
{
	unsigned long flags;

	spin_lock_irqsave(&t->sighand->siglock, flags);