-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_child_pids.c
57 lines (49 loc) · 1.27 KB
/
get_child_pids.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<linux/linkage.h>
#include<linux/sched.h>
#include<linux/kernel.h>
#include<linux/uaccess.h>
#include<linux/slab.h>
#include<linux/gfp.h>
asmlinkage long sys_get_child_pids(pid_t* list, size_t limit, size_t* num_children)
{
pid_t* tmpList = NULL;
pid_t* tmpListHead = NULL;
struct list_head *position = NULL;
struct task_struct *child = NULL;
int nbP = 0;
int returnVal = 0;
if(list == NULL && limit != 0) {
return -EFAULT;
}
tmpListHead = kmalloc(sizeof(pid_t) * limit, GFP_KERNEL);
if(tmpListHead == NULL && limit != 0) {
return -EFAULT;
}
tmpList = tmpListHead;
read_lock(&tasklist_lock);
list_for_each(position, ¤t->children) {
child = list_entry(position, struct task_struct, sibling);
nbP++;
if(nbP <= limit) {
*tmpList = child->pid;
tmpList++;
} else {
returnVal = -ENOBUFS;
}
}
read_unlock(&tasklist_lock);
if(put_user(nbP, num_children)){
return -EFAULT;
}
tmpList = tmpListHead;
while(limit > 0) {
if(put_user(*tmpList, list)){
return -EFAULT;
}
tmpList++;
list++;
limit--;
}
kfree(tmpListHead);
return returnVal;
}