-
Notifications
You must be signed in to change notification settings - Fork 0
/
stoogecalls.c
95 lines (86 loc) · 2.16 KB
/
stoogecalls.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <linux/linkage.h>
#include <linux/kernel.h>
#include <linux/syscalls.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/wait.h>
// Test syscall that does nothing
SYSCALL_DEFINE1(goober, int, myarg){
printk(KERN_ALERT "Hello from %d\n", myarg);
return(1);
}
// Initialize count for each signal under a process
SYSCALL_DEFINE1(init_sigcounter, pid_t, pid){
unsigned long flags;
int i;
struct task_struct *p;
p = pid_task(find_vpid(pid), PIDTYPE_PID);
lock_task_sighand(p, &flags);
for(i = 0; i < 64; i++){
p->sighand->sigcounter[i] = 0;
}
unlock_task_sighand(p, &flags);
return(1);
}
// Return count of each signal under a process
SYSCALL_DEFINE1(get_sigcounter, int, signumber){
unsigned long flags;
struct task_struct *p;
pid_t pid = current->pid;
p = pid_task(find_vpid(pid), PIDTYPE_PID);
lock_task_sighand(p, &flags);
pr_alert("%d\n", p->sighand->sigcounter[signumber]);
unlock_task_sighand(p, &flags);
return(1);
}
// Deep-sleeper
__sched sleep_on(wait_queue_head_t *q){
unsigned long flags;
wait_queue_t wait;
init_waitqueue_entry(&wait, current);
__set_current_state(TASK_UNINTERRUPTIBLE);
spin_lock_irqsave(&q->lock, flags);
__add_wait_queue(q, &wait);
spin_unlock(&q->lock);
schedule();
spin_lock_irq(&q->lock);
__remove_wait_queue(q, &wait);
spin_unlock_irqrestore(&q->lock, flags);
return;
}
DECLARE_WAIT_QUEUE_HEAD(gone);
SYSCALL_DEFINE0(deepsleep){
sleep_on(&gone);
}
SYSCALL_DEFINE2(smunch, pid_t,pid, long, bit_pattern){
//Check if multi threaded
struct task_struct *p;
bool ret;
p = pid_task(find_vpid(pid), PIDTYPE_PID);
if(!p){
pr_alert("\nprocess table is null");
return -1;
}
ret = current_is_single_threaded();
if(ret == false){
pr_alert("\nError : Multithreaded process, cannot proceed\n");
return -1;
}
//Check if traced
if(p->ptrace & PT_PTRACED){
pr_alert("\nError : Traced process, cannot proceed\n");
return -1;
}
//Check if zombie state
if(p->exit_state == EXIT_ZOMBIE){
if((1 << (SIGKILL-1)) & bit_pattern){
release_task(p);
}
return 0;
}
else{
p->pending.signal.sig[0] |= bit_pattern;
wake_up_process(p);
}
return 0;
}