Subversion Repositories shark

Rev

Rev 927 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
847 giacomo 1
#include <linuxcomp.h>
2
#include <linux/wait.h>
3
#include <linux/config.h>
4
#include <linux/list.h>
5
 
6
#include <kernel/types.h>
7
 
8
extern int task_activate(PID pid);
9
extern int exec_shadow;
10
 
11
struct task_struct {
12
        PID pid;
13
        int state;
14
        char comm[1024];
15
};
16
 
17
typedef struct task_struct task_t;
18
 
19
inline void init_waitqueue_head(wait_queue_head_t *q)
20
{
21
        q->lock = SPIN_LOCK_UNLOCKED;
22
        INIT_LIST_HEAD(&q->task_list);
23
}
24
 
25
static int try_to_wake_up(task_t * p, unsigned int state, int sync)
26
{
27
        task_activate(p->pid);
28
        return 0;
29
}
30
 
31
int default_wake_function(wait_queue_t *curr, unsigned mode, int sync)
32
{
33
        task_t *p = curr->task;
34
        return try_to_wake_up(p, mode, sync);
35
}
36
 
37
void __wake_up_common(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, int sync)
38
{
39
        struct list_head *tmp, *next;
40
 
41
        list_for_each_safe(tmp, next, &q->task_list) {
42
                wait_queue_t *curr;
43
                unsigned flags;
44
 
45
                curr = list_entry(tmp, wait_queue_t, task_list);
46
                flags = curr->flags;
47
                curr->func(curr, mode, sync);
48
        }
49
 
50
}
51
 
1056 tullio 52
// added __attribute__ for gcc4 compatibility
53
__attribute__((regparm(3))) void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
847 giacomo 54
{
55
        unsigned long flags;
56
 
57
        spin_lock_irqsave(&q->lock, flags);
58
        __wake_up_common(q, mode, nr_exclusive, 0);
59
        spin_unlock_irqrestore(&q->lock, flags);
60
}
61
 
62
inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
63
{
64
        list_add(&new->task_list, &head->task_list);
65
}
66
 
1056 tullio 67
// added __attribute__ for gcc4 compatibility
68
__attribute__((regparm(3))) void add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
847 giacomo 69
{
70
        unsigned long flags;
71
 
72
        wait->flags &= ~WQ_FLAG_EXCLUSIVE;
73
        spin_lock_irqsave(&q->lock, flags);
74
        __add_wait_queue(q, wait);
75
        spin_unlock_irqrestore(&q->lock, flags);
76
}
77
 
1056 tullio 78
// added __attribute__ for gcc4 compatibility
79
__attribute__((regparm(3))) void remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
847 giacomo 80
{
81
        unsigned long flags;
82
 
83
        spin_lock_irqsave(&q->lock, flags);
84
        __remove_wait_queue(q, wait);
85
        spin_unlock_irqrestore(&q->lock, flags);
86
}
87
 
88
inline int waitqueue_active(wait_queue_head_t *q)
89
{
90
        return !list_empty(&q->task_list);
91
}
92
 
93
inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
94
{
95
        q->flags = 0;
96
        q->task = p;
97
        q->func = default_wake_function;
98
}
99
 
100
extern void * malloc(size_t size);
101
 
102
struct task_struct * get_current26(void)
103
{
104
        struct task_struct *tsp;
105
 
106
        tsp = malloc(sizeof(struct task_struct));
107
        if (!tsp)
108
        {
109
                printk(KERN_DEBUG "@get_current26 out of memory!!!\n");
110
                //
927 pj 111
                // exit?
847 giacomo 112
                //
113
        }
114
        tsp->pid = exec_shadow;
115
 
116
        //        printk(KERN_DEBUG "File: %s Pid=%d\n", __FILE__, tsp->pid);
117
        return tsp;
118
}