This source file includes following definitions.
- ret_from_sys_call
- start_thread
- exit_thread
- flush_thread
- copy_thread
- dump_thread
- sys_execve
1
2
3
4
5
6
7
8
9
10
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/stddef.h>
16 #include <linux/unistd.h>
17 #include <linux/ptrace.h>
18 #include <linux/malloc.h>
19 #include <linux/ldt.h>
20 #include <linux/user.h>
21 #include <linux/a.out.h>
22
23 #include <asm/segment.h>
24 #include <asm/system.h>
25
26
27
28
29 char hard_math = 0;
30 char x86 = 0;
31 char x86_model = 0;
32 char x86_mask = 0;
33 int x86_capability = 0;
34 int fdiv_bug = 0;
35
36 char x86_vendor_id[13] = "Unknown";
37
38 char ignore_irq13 = 0;
39 char wp_works_ok = 0;
40 char hlt_works_ok = 1;
41
42
43
44
45 int EISA_bus = 0;
46
47 asmlinkage void ret_from_sys_call(void) __asm__("ret_from_sys_call");
48
49
50
51
52 asmlinkage int sys_idle(void)
53 {
54 int i;
55
56 if (current->pid != 0)
57 return -EPERM;
58
59
60 for (i = 0 ; i < 768 ; i++)
61 swapper_pg_dir[i] = 0;
62
63
64 current->counter = -100;
65 for (;;) {
66 if (hlt_works_ok && !need_resched)
67 __asm__("hlt");
68 schedule();
69 }
70 }
71
72
73
74
75 void start_thread(struct pt_regs * regs, unsigned long eip, unsigned long esp)
76 {
77 regs->eip = eip;
78 regs->esp = esp;
79 }
80
81
82
83
84 void exit_thread(void)
85 {
86
87 __asm__ __volatile__("mov %w0,%%fs ; mov %w0,%%gs ; lldt %w0"
88 :
89 : "r" (0));
90 current->tss.ldt = 0;
91 if (current->ldt) {
92 void * ldt = current->ldt;
93 current->ldt = NULL;
94 vfree(ldt);
95 }
96 }
97
98 void flush_thread(void)
99 {
100 int i;
101
102 if (current->ldt) {
103 free_page((unsigned long) current->ldt);
104 current->ldt = NULL;
105 for (i=1 ; i<NR_TASKS ; i++) {
106 if (task[i] == current) {
107 set_ldt_desc(gdt+(i<<1)+
108 FIRST_LDT_ENTRY,&default_ldt, 1);
109 load_ldt(i);
110 }
111 }
112 }
113
114 for (i=0 ; i<8 ; i++)
115 current->debugreg[i] = 0;
116 }
117
118 #define IS_CLONE (regs->orig_eax == __NR_clone)
119
120 unsigned long copy_thread(int nr, unsigned long clone_flags, struct task_struct * p, struct pt_regs * regs)
121 {
122 int i;
123 struct pt_regs * childregs;
124
125 p->tss.es = KERNEL_DS;
126 p->tss.cs = KERNEL_CS;
127 p->tss.ss = KERNEL_DS;
128 p->tss.ds = KERNEL_DS;
129 p->tss.fs = USER_DS;
130 p->tss.gs = KERNEL_DS;
131 p->tss.ss0 = KERNEL_DS;
132 p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
133 p->tss.tr = _TSS(nr);
134 childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
135 p->tss.esp = (unsigned long) childregs;
136 p->tss.eip = (unsigned long) ret_from_sys_call;
137 *childregs = *regs;
138 childregs->eax = 0;
139 p->tss.back_link = 0;
140 p->tss.eflags = regs->eflags & 0xffffcfff;
141 if (IS_CLONE) {
142 if (regs->ebx)
143 childregs->esp = regs->ebx;
144 clone_flags = regs->ecx;
145 if (childregs->esp == regs->esp)
146 clone_flags |= COPYVM;
147 }
148 p->tss.ldt = _LDT(nr);
149 if (p->ldt) {
150 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
151 if (p->ldt != NULL)
152 memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
153 }
154 set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
155 if (p->ldt)
156 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
157 else
158 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
159 p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
160 for (i = 0; i < IO_BITMAP_SIZE+1 ; i++)
161 p->tss.io_bitmap[i] = ~0;
162 if (last_task_used_math == current)
163 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
164 return clone_flags;
165 }
166
167
168
169
170 void dump_thread(struct pt_regs * regs, struct user * dump)
171 {
172 int i;
173
174
175 dump->magic = CMAGIC;
176 dump->start_code = 0;
177 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
178 dump->u_tsize = ((unsigned long) current->mm->end_code) >> 12;
179 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> 12;
180 dump->u_dsize -= dump->u_tsize;
181 dump->u_ssize = 0;
182 for (i = 0; i < 8; i++)
183 dump->u_debugreg[i] = current->debugreg[i];
184
185 if (dump->start_stack < TASK_SIZE)
186 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> 12;
187
188 dump->regs = *regs;
189
190
191
192 if (hard_math) {
193 if ((dump->u_fpvalid = current->used_math) != 0) {
194 if (last_task_used_math == current)
195 __asm__("clts ; fnsave %0": :"m" (dump->i387));
196 else
197 memcpy(&dump->i387,¤t->tss.i387.hard,sizeof(dump->i387));
198 }
199 } else {
200
201
202 dump->u_fpvalid = 0;
203 }
204 }
205
206
207
208
209 asmlinkage int sys_execve(struct pt_regs regs)
210 {
211 int error;
212 char * filename;
213
214 error = getname((char *) regs.ebx, &filename);
215 if (error)
216 return error;
217 error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, ®s);
218 putname(filename);
219 return error;
220 }