aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/process_32.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/process_32.c')
-rw-r--r--arch/x86/kernel/process_32.c419
1 files changed, 167 insertions, 252 deletions
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 46d391d49de..968371ab223 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -55,6 +55,7 @@
55 55
56#include <asm/tlbflush.h> 56#include <asm/tlbflush.h>
57#include <asm/cpu.h> 57#include <asm/cpu.h>
58#include <asm/kdebug.h>
58 59
59asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); 60asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
60 61
@@ -74,7 +75,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
74 */ 75 */
75unsigned long thread_saved_pc(struct task_struct *tsk) 76unsigned long thread_saved_pc(struct task_struct *tsk)
76{ 77{
77 return ((unsigned long *)tsk->thread.esp)[3]; 78 return ((unsigned long *)tsk->thread.sp)[3];
78} 79}
79 80
80/* 81/*
@@ -113,10 +114,19 @@ void default_idle(void)
113 smp_mb(); 114 smp_mb();
114 115
115 local_irq_disable(); 116 local_irq_disable();
116 if (!need_resched()) 117 if (!need_resched()) {
118 ktime_t t0, t1;
119 u64 t0n, t1n;
120
121 t0 = ktime_get();
122 t0n = ktime_to_ns(t0);
117 safe_halt(); /* enables interrupts racelessly */ 123 safe_halt(); /* enables interrupts racelessly */
118 else 124 local_irq_disable();
119 local_irq_enable(); 125 t1 = ktime_get();
126 t1n = ktime_to_ns(t1);
127 sched_clock_idle_wakeup_event(t1n - t0n);
128 }
129 local_irq_enable();
120 current_thread_info()->status |= TS_POLLING; 130 current_thread_info()->status |= TS_POLLING;
121 } else { 131 } else {
122 /* loop is done by the caller */ 132 /* loop is done by the caller */
@@ -132,7 +142,7 @@ EXPORT_SYMBOL(default_idle);
132 * to poll the ->work.need_resched flag instead of waiting for the 142 * to poll the ->work.need_resched flag instead of waiting for the
133 * cross-CPU IPI to arrive. Use this option with caution. 143 * cross-CPU IPI to arrive. Use this option with caution.
134 */ 144 */
135static void poll_idle (void) 145static void poll_idle(void)
136{ 146{
137 cpu_relax(); 147 cpu_relax();
138} 148}
@@ -188,6 +198,9 @@ void cpu_idle(void)
188 rmb(); 198 rmb();
189 idle = pm_idle; 199 idle = pm_idle;
190 200
201 if (rcu_pending(cpu))
202 rcu_check_callbacks(cpu, 0);
203
191 if (!idle) 204 if (!idle)
192 idle = default_idle; 205 idle = default_idle;
193 206
@@ -255,13 +268,13 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait);
255 * New with Core Duo processors, MWAIT can take some hints based on CPU 268 * New with Core Duo processors, MWAIT can take some hints based on CPU
256 * capability. 269 * capability.
257 */ 270 */
258void mwait_idle_with_hints(unsigned long eax, unsigned long ecx) 271void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
259{ 272{
260 if (!need_resched()) { 273 if (!need_resched()) {
261 __monitor((void *)&current_thread_info()->flags, 0, 0); 274 __monitor((void *)&current_thread_info()->flags, 0, 0);
262 smp_mb(); 275 smp_mb();
263 if (!need_resched()) 276 if (!need_resched())
264 __mwait(eax, ecx); 277 __mwait(ax, cx);
265 } 278 }
266} 279}
267 280
@@ -272,19 +285,37 @@ static void mwait_idle(void)
272 mwait_idle_with_hints(0, 0); 285 mwait_idle_with_hints(0, 0);
273} 286}
274 287
288static int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
289{
290 if (force_mwait)
291 return 1;
292 /* Any C1 states supported? */
293 return c->cpuid_level >= 5 && ((cpuid_edx(5) >> 4) & 0xf) > 0;
294}
295
275void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c) 296void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
276{ 297{
277 if (cpu_has(c, X86_FEATURE_MWAIT)) { 298 static int selected;
278 printk("monitor/mwait feature present.\n"); 299
300 if (selected)
301 return;
302#ifdef CONFIG_X86_SMP
303 if (pm_idle == poll_idle && smp_num_siblings > 1) {
304 printk(KERN_WARNING "WARNING: polling idle and HT enabled,"
305 " performance may degrade.\n");
306 }
307#endif
308 if (cpu_has(c, X86_FEATURE_MWAIT) && mwait_usable(c)) {
279 /* 309 /*
280 * Skip, if setup has overridden idle. 310 * Skip, if setup has overridden idle.
281 * One CPU supports mwait => All CPUs supports mwait 311 * One CPU supports mwait => All CPUs supports mwait
282 */ 312 */
283 if (!pm_idle) { 313 if (!pm_idle) {
284 printk("using mwait in idle threads.\n"); 314 printk(KERN_INFO "using mwait in idle threads.\n");
285 pm_idle = mwait_idle; 315 pm_idle = mwait_idle;
286 } 316 }
287 } 317 }
318 selected = 1;
288} 319}
289 320
290static int __init idle_setup(char *str) 321static int __init idle_setup(char *str)
@@ -292,10 +323,6 @@ static int __init idle_setup(char *str)
292 if (!strcmp(str, "poll")) { 323 if (!strcmp(str, "poll")) {
293 printk("using polling idle threads.\n"); 324 printk("using polling idle threads.\n");
294 pm_idle = poll_idle; 325 pm_idle = poll_idle;
295#ifdef CONFIG_X86_SMP
296 if (smp_num_siblings > 1)
297 printk("WARNING: polling idle and HT enabled, performance may degrade.\n");
298#endif
299 } else if (!strcmp(str, "mwait")) 326 } else if (!strcmp(str, "mwait"))
300 force_mwait = 1; 327 force_mwait = 1;
301 else 328 else
@@ -310,15 +337,15 @@ void __show_registers(struct pt_regs *regs, int all)
310{ 337{
311 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L; 338 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
312 unsigned long d0, d1, d2, d3, d6, d7; 339 unsigned long d0, d1, d2, d3, d6, d7;
313 unsigned long esp; 340 unsigned long sp;
314 unsigned short ss, gs; 341 unsigned short ss, gs;
315 342
316 if (user_mode_vm(regs)) { 343 if (user_mode_vm(regs)) {
317 esp = regs->esp; 344 sp = regs->sp;
318 ss = regs->xss & 0xffff; 345 ss = regs->ss & 0xffff;
319 savesegment(gs, gs); 346 savesegment(gs, gs);
320 } else { 347 } else {
321 esp = (unsigned long) (&regs->esp); 348 sp = (unsigned long) (&regs->sp);
322 savesegment(ss, ss); 349 savesegment(ss, ss);
323 savesegment(gs, gs); 350 savesegment(gs, gs);
324 } 351 }
@@ -331,17 +358,17 @@ void __show_registers(struct pt_regs *regs, int all)
331 init_utsname()->version); 358 init_utsname()->version);
332 359
333 printk("EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n", 360 printk("EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
334 0xffff & regs->xcs, regs->eip, regs->eflags, 361 0xffff & regs->cs, regs->ip, regs->flags,
335 smp_processor_id()); 362 smp_processor_id());
336 print_symbol("EIP is at %s\n", regs->eip); 363 print_symbol("EIP is at %s\n", regs->ip);
337 364
338 printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n", 365 printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
339 regs->eax, regs->ebx, regs->ecx, regs->edx); 366 regs->ax, regs->bx, regs->cx, regs->dx);
340 printk("ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n", 367 printk("ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
341 regs->esi, regs->edi, regs->ebp, esp); 368 regs->si, regs->di, regs->bp, sp);
342 printk(" DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x\n", 369 printk(" DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x\n",
343 regs->xds & 0xffff, regs->xes & 0xffff, 370 regs->ds & 0xffff, regs->es & 0xffff,
344 regs->xfs & 0xffff, gs, ss); 371 regs->fs & 0xffff, gs, ss);
345 372
346 if (!all) 373 if (!all)
347 return; 374 return;
@@ -369,12 +396,12 @@ void __show_registers(struct pt_regs *regs, int all)
369void show_regs(struct pt_regs *regs) 396void show_regs(struct pt_regs *regs)
370{ 397{
371 __show_registers(regs, 1); 398 __show_registers(regs, 1);
372 show_trace(NULL, regs, &regs->esp); 399 show_trace(NULL, regs, &regs->sp, regs->bp);
373} 400}
374 401
375/* 402/*
376 * This gets run with %ebx containing the 403 * This gets run with %bx containing the
377 * function to call, and %edx containing 404 * function to call, and %dx containing
378 * the "args". 405 * the "args".
379 */ 406 */
380extern void kernel_thread_helper(void); 407extern void kernel_thread_helper(void);
@@ -388,16 +415,16 @@ int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
388 415
389 memset(&regs, 0, sizeof(regs)); 416 memset(&regs, 0, sizeof(regs));
390 417
391 regs.ebx = (unsigned long) fn; 418 regs.bx = (unsigned long) fn;
392 regs.edx = (unsigned long) arg; 419 regs.dx = (unsigned long) arg;
393 420
394 regs.xds = __USER_DS; 421 regs.ds = __USER_DS;
395 regs.xes = __USER_DS; 422 regs.es = __USER_DS;
396 regs.xfs = __KERNEL_PERCPU; 423 regs.fs = __KERNEL_PERCPU;
397 regs.orig_eax = -1; 424 regs.orig_ax = -1;
398 regs.eip = (unsigned long) kernel_thread_helper; 425 regs.ip = (unsigned long) kernel_thread_helper;
399 regs.xcs = __KERNEL_CS | get_kernel_rpl(); 426 regs.cs = __KERNEL_CS | get_kernel_rpl();
400 regs.eflags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2; 427 regs.flags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;
401 428
402 /* Ok, create the new process.. */ 429 /* Ok, create the new process.. */
403 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL); 430 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
@@ -435,7 +462,12 @@ void flush_thread(void)
435{ 462{
436 struct task_struct *tsk = current; 463 struct task_struct *tsk = current;
437 464
438 memset(tsk->thread.debugreg, 0, sizeof(unsigned long)*8); 465 tsk->thread.debugreg0 = 0;
466 tsk->thread.debugreg1 = 0;
467 tsk->thread.debugreg2 = 0;
468 tsk->thread.debugreg3 = 0;
469 tsk->thread.debugreg6 = 0;
470 tsk->thread.debugreg7 = 0;
439 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array)); 471 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
440 clear_tsk_thread_flag(tsk, TIF_DEBUG); 472 clear_tsk_thread_flag(tsk, TIF_DEBUG);
441 /* 473 /*
@@ -460,7 +492,7 @@ void prepare_to_copy(struct task_struct *tsk)
460 unlazy_fpu(tsk); 492 unlazy_fpu(tsk);
461} 493}
462 494
463int copy_thread(int nr, unsigned long clone_flags, unsigned long esp, 495int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
464 unsigned long unused, 496 unsigned long unused,
465 struct task_struct * p, struct pt_regs * regs) 497 struct task_struct * p, struct pt_regs * regs)
466{ 498{
@@ -470,15 +502,15 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
470 502
471 childregs = task_pt_regs(p); 503 childregs = task_pt_regs(p);
472 *childregs = *regs; 504 *childregs = *regs;
473 childregs->eax = 0; 505 childregs->ax = 0;
474 childregs->esp = esp; 506 childregs->sp = sp;
475 507
476 p->thread.esp = (unsigned long) childregs; 508 p->thread.sp = (unsigned long) childregs;
477 p->thread.esp0 = (unsigned long) (childregs+1); 509 p->thread.sp0 = (unsigned long) (childregs+1);
478 510
479 p->thread.eip = (unsigned long) ret_from_fork; 511 p->thread.ip = (unsigned long) ret_from_fork;
480 512
481 savesegment(gs,p->thread.gs); 513 savesegment(gs, p->thread.gs);
482 514
483 tsk = current; 515 tsk = current;
484 if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) { 516 if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) {
@@ -491,32 +523,15 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
491 set_tsk_thread_flag(p, TIF_IO_BITMAP); 523 set_tsk_thread_flag(p, TIF_IO_BITMAP);
492 } 524 }
493 525
526 err = 0;
527
494 /* 528 /*
495 * Set a new TLS for the child thread? 529 * Set a new TLS for the child thread?
496 */ 530 */
497 if (clone_flags & CLONE_SETTLS) { 531 if (clone_flags & CLONE_SETTLS)
498 struct desc_struct *desc; 532 err = do_set_thread_area(p, -1,
499 struct user_desc info; 533 (struct user_desc __user *)childregs->si, 0);
500 int idx;
501
502 err = -EFAULT;
503 if (copy_from_user(&info, (void __user *)childregs->esi, sizeof(info)))
504 goto out;
505 err = -EINVAL;
506 if (LDT_empty(&info))
507 goto out;
508
509 idx = info.entry_number;
510 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
511 goto out;
512
513 desc = p->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
514 desc->a = LDT_entry_a(&info);
515 desc->b = LDT_entry_b(&info);
516 }
517 534
518 err = 0;
519 out:
520 if (err && p->thread.io_bitmap_ptr) { 535 if (err && p->thread.io_bitmap_ptr) {
521 kfree(p->thread.io_bitmap_ptr); 536 kfree(p->thread.io_bitmap_ptr);
522 p->thread.io_bitmap_max = 0; 537 p->thread.io_bitmap_max = 0;
@@ -529,62 +544,52 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
529 */ 544 */
530void dump_thread(struct pt_regs * regs, struct user * dump) 545void dump_thread(struct pt_regs * regs, struct user * dump)
531{ 546{
532 int i; 547 u16 gs;
533 548
534/* changed the size calculations - should hopefully work better. lbt */ 549/* changed the size calculations - should hopefully work better. lbt */
535 dump->magic = CMAGIC; 550 dump->magic = CMAGIC;
536 dump->start_code = 0; 551 dump->start_code = 0;
537 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1); 552 dump->start_stack = regs->sp & ~(PAGE_SIZE - 1);
538 dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT; 553 dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
539 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT; 554 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
540 dump->u_dsize -= dump->u_tsize; 555 dump->u_dsize -= dump->u_tsize;
541 dump->u_ssize = 0; 556 dump->u_ssize = 0;
542 for (i = 0; i < 8; i++) 557 dump->u_debugreg[0] = current->thread.debugreg0;
543 dump->u_debugreg[i] = current->thread.debugreg[i]; 558 dump->u_debugreg[1] = current->thread.debugreg1;
559 dump->u_debugreg[2] = current->thread.debugreg2;
560 dump->u_debugreg[3] = current->thread.debugreg3;
561 dump->u_debugreg[4] = 0;
562 dump->u_debugreg[5] = 0;
563 dump->u_debugreg[6] = current->thread.debugreg6;
564 dump->u_debugreg[7] = current->thread.debugreg7;
544 565
545 if (dump->start_stack < TASK_SIZE) 566 if (dump->start_stack < TASK_SIZE)
546 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT; 567 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
547 568
548 dump->regs.ebx = regs->ebx; 569 dump->regs.bx = regs->bx;
549 dump->regs.ecx = regs->ecx; 570 dump->regs.cx = regs->cx;
550 dump->regs.edx = regs->edx; 571 dump->regs.dx = regs->dx;
551 dump->regs.esi = regs->esi; 572 dump->regs.si = regs->si;
552 dump->regs.edi = regs->edi; 573 dump->regs.di = regs->di;
553 dump->regs.ebp = regs->ebp; 574 dump->regs.bp = regs->bp;
554 dump->regs.eax = regs->eax; 575 dump->regs.ax = regs->ax;
555 dump->regs.ds = regs->xds; 576 dump->regs.ds = (u16)regs->ds;
556 dump->regs.es = regs->xes; 577 dump->regs.es = (u16)regs->es;
557 dump->regs.fs = regs->xfs; 578 dump->regs.fs = (u16)regs->fs;
558 savesegment(gs,dump->regs.gs); 579 savesegment(gs,gs);
559 dump->regs.orig_eax = regs->orig_eax; 580 dump->regs.orig_ax = regs->orig_ax;
560 dump->regs.eip = regs->eip; 581 dump->regs.ip = regs->ip;
561 dump->regs.cs = regs->xcs; 582 dump->regs.cs = (u16)regs->cs;
562 dump->regs.eflags = regs->eflags; 583 dump->regs.flags = regs->flags;
563 dump->regs.esp = regs->esp; 584 dump->regs.sp = regs->sp;
564 dump->regs.ss = regs->xss; 585 dump->regs.ss = (u16)regs->ss;
565 586
566 dump->u_fpvalid = dump_fpu (regs, &dump->i387); 587 dump->u_fpvalid = dump_fpu (regs, &dump->i387);
567} 588}
568EXPORT_SYMBOL(dump_thread); 589EXPORT_SYMBOL(dump_thread);
569 590
570/*
571 * Capture the user space registers if the task is not running (in user space)
572 */
573int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
574{
575 struct pt_regs ptregs = *task_pt_regs(tsk);
576 ptregs.xcs &= 0xffff;
577 ptregs.xds &= 0xffff;
578 ptregs.xes &= 0xffff;
579 ptregs.xss &= 0xffff;
580
581 elf_core_copy_regs(regs, &ptregs);
582
583 return 1;
584}
585
586#ifdef CONFIG_SECCOMP 591#ifdef CONFIG_SECCOMP
587void hard_disable_TSC(void) 592static void hard_disable_TSC(void)
588{ 593{
589 write_cr4(read_cr4() | X86_CR4_TSD); 594 write_cr4(read_cr4() | X86_CR4_TSD);
590} 595}
@@ -599,7 +604,7 @@ void disable_TSC(void)
599 hard_disable_TSC(); 604 hard_disable_TSC();
600 preempt_enable(); 605 preempt_enable();
601} 606}
602void hard_enable_TSC(void) 607static void hard_enable_TSC(void)
603{ 608{
604 write_cr4(read_cr4() & ~X86_CR4_TSD); 609 write_cr4(read_cr4() & ~X86_CR4_TSD);
605} 610}
@@ -609,18 +614,32 @@ static noinline void
609__switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, 614__switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
610 struct tss_struct *tss) 615 struct tss_struct *tss)
611{ 616{
612 struct thread_struct *next; 617 struct thread_struct *prev, *next;
618 unsigned long debugctl;
613 619
620 prev = &prev_p->thread;
614 next = &next_p->thread; 621 next = &next_p->thread;
615 622
623 debugctl = prev->debugctlmsr;
624 if (next->ds_area_msr != prev->ds_area_msr) {
625 /* we clear debugctl to make sure DS
626 * is not in use when we change it */
627 debugctl = 0;
628 wrmsrl(MSR_IA32_DEBUGCTLMSR, 0);
629 wrmsr(MSR_IA32_DS_AREA, next->ds_area_msr, 0);
630 }
631
632 if (next->debugctlmsr != debugctl)
633 wrmsr(MSR_IA32_DEBUGCTLMSR, next->debugctlmsr, 0);
634
616 if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { 635 if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
617 set_debugreg(next->debugreg[0], 0); 636 set_debugreg(next->debugreg0, 0);
618 set_debugreg(next->debugreg[1], 1); 637 set_debugreg(next->debugreg1, 1);
619 set_debugreg(next->debugreg[2], 2); 638 set_debugreg(next->debugreg2, 2);
620 set_debugreg(next->debugreg[3], 3); 639 set_debugreg(next->debugreg3, 3);
621 /* no 4 and 5 */ 640 /* no 4 and 5 */
622 set_debugreg(next->debugreg[6], 6); 641 set_debugreg(next->debugreg6, 6);
623 set_debugreg(next->debugreg[7], 7); 642 set_debugreg(next->debugreg7, 7);
624 } 643 }
625 644
626#ifdef CONFIG_SECCOMP 645#ifdef CONFIG_SECCOMP
@@ -634,6 +653,13 @@ __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
634 } 653 }
635#endif 654#endif
636 655
656 if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS))
657 ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS);
658
659 if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS))
660 ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES);
661
662
637 if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) { 663 if (!test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) {
638 /* 664 /*
639 * Disable the bitmap via an invalid offset. We still cache 665 * Disable the bitmap via an invalid offset. We still cache
@@ -687,11 +713,11 @@ __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
687 * More important, however, is the fact that this allows us much 713 * More important, however, is the fact that this allows us much
688 * more flexibility. 714 * more flexibility.
689 * 715 *
690 * The return value (in %eax) will be the "prev" task after 716 * The return value (in %ax) will be the "prev" task after
691 * the task-switch, and shows up in ret_from_fork in entry.S, 717 * the task-switch, and shows up in ret_from_fork in entry.S,
692 * for example. 718 * for example.
693 */ 719 */
694struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct task_struct *next_p) 720struct task_struct * __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
695{ 721{
696 struct thread_struct *prev = &prev_p->thread, 722 struct thread_struct *prev = &prev_p->thread,
697 *next = &next_p->thread; 723 *next = &next_p->thread;
@@ -710,7 +736,7 @@ struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct tas
710 /* 736 /*
711 * Reload esp0. 737 * Reload esp0.
712 */ 738 */
713 load_esp0(tss, next); 739 load_sp0(tss, next);
714 740
715 /* 741 /*
716 * Save away %gs. No need to save %fs, as it was saved on the 742 * Save away %gs. No need to save %fs, as it was saved on the
@@ -774,7 +800,7 @@ struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct tas
774 800
775asmlinkage int sys_fork(struct pt_regs regs) 801asmlinkage int sys_fork(struct pt_regs regs)
776{ 802{
777 return do_fork(SIGCHLD, regs.esp, &regs, 0, NULL, NULL); 803 return do_fork(SIGCHLD, regs.sp, &regs, 0, NULL, NULL);
778} 804}
779 805
780asmlinkage int sys_clone(struct pt_regs regs) 806asmlinkage int sys_clone(struct pt_regs regs)
@@ -783,12 +809,12 @@ asmlinkage int sys_clone(struct pt_regs regs)
783 unsigned long newsp; 809 unsigned long newsp;
784 int __user *parent_tidptr, *child_tidptr; 810 int __user *parent_tidptr, *child_tidptr;
785 811
786 clone_flags = regs.ebx; 812 clone_flags = regs.bx;
787 newsp = regs.ecx; 813 newsp = regs.cx;
788 parent_tidptr = (int __user *)regs.edx; 814 parent_tidptr = (int __user *)regs.dx;
789 child_tidptr = (int __user *)regs.edi; 815 child_tidptr = (int __user *)regs.di;
790 if (!newsp) 816 if (!newsp)
791 newsp = regs.esp; 817 newsp = regs.sp;
792 return do_fork(clone_flags, newsp, &regs, 0, parent_tidptr, child_tidptr); 818 return do_fork(clone_flags, newsp, &regs, 0, parent_tidptr, child_tidptr);
793} 819}
794 820
@@ -804,7 +830,7 @@ asmlinkage int sys_clone(struct pt_regs regs)
804 */ 830 */
805asmlinkage int sys_vfork(struct pt_regs regs) 831asmlinkage int sys_vfork(struct pt_regs regs)
806{ 832{
807 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.esp, &regs, 0, NULL, NULL); 833 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.sp, &regs, 0, NULL, NULL);
808} 834}
809 835
810/* 836/*
@@ -815,18 +841,15 @@ asmlinkage int sys_execve(struct pt_regs regs)
815 int error; 841 int error;
816 char * filename; 842 char * filename;
817 843
818 filename = getname((char __user *) regs.ebx); 844 filename = getname((char __user *) regs.bx);
819 error = PTR_ERR(filename); 845 error = PTR_ERR(filename);
820 if (IS_ERR(filename)) 846 if (IS_ERR(filename))
821 goto out; 847 goto out;
822 error = do_execve(filename, 848 error = do_execve(filename,
823 (char __user * __user *) regs.ecx, 849 (char __user * __user *) regs.cx,
824 (char __user * __user *) regs.edx, 850 (char __user * __user *) regs.dx,
825 &regs); 851 &regs);
826 if (error == 0) { 852 if (error == 0) {
827 task_lock(current);
828 current->ptrace &= ~PT_DTRACE;
829 task_unlock(current);
830 /* Make sure we don't return using sysenter.. */ 853 /* Make sure we don't return using sysenter.. */
831 set_thread_flag(TIF_IRET); 854 set_thread_flag(TIF_IRET);
832 } 855 }
@@ -840,145 +863,37 @@ out:
840 863
841unsigned long get_wchan(struct task_struct *p) 864unsigned long get_wchan(struct task_struct *p)
842{ 865{
843 unsigned long ebp, esp, eip; 866 unsigned long bp, sp, ip;
844 unsigned long stack_page; 867 unsigned long stack_page;
845 int count = 0; 868 int count = 0;
846 if (!p || p == current || p->state == TASK_RUNNING) 869 if (!p || p == current || p->state == TASK_RUNNING)
847 return 0; 870 return 0;
848 stack_page = (unsigned long)task_stack_page(p); 871 stack_page = (unsigned long)task_stack_page(p);
849 esp = p->thread.esp; 872 sp = p->thread.sp;
850 if (!stack_page || esp < stack_page || esp > top_esp+stack_page) 873 if (!stack_page || sp < stack_page || sp > top_esp+stack_page)
851 return 0; 874 return 0;
852 /* include/asm-i386/system.h:switch_to() pushes ebp last. */ 875 /* include/asm-i386/system.h:switch_to() pushes bp last. */
853 ebp = *(unsigned long *) esp; 876 bp = *(unsigned long *) sp;
854 do { 877 do {
855 if (ebp < stack_page || ebp > top_ebp+stack_page) 878 if (bp < stack_page || bp > top_ebp+stack_page)
856 return 0; 879 return 0;
857 eip = *(unsigned long *) (ebp+4); 880 ip = *(unsigned long *) (bp+4);
858 if (!in_sched_functions(eip)) 881 if (!in_sched_functions(ip))
859 return eip; 882 return ip;
860 ebp = *(unsigned long *) ebp; 883 bp = *(unsigned long *) bp;
861 } while (count++ < 16); 884 } while (count++ < 16);
862 return 0; 885 return 0;
863} 886}
864 887
865/*
866 * sys_alloc_thread_area: get a yet unused TLS descriptor index.
867 */
868static int get_free_idx(void)
869{
870 struct thread_struct *t = &current->thread;
871 int idx;
872
873 for (idx = 0; idx < GDT_ENTRY_TLS_ENTRIES; idx++)
874 if (desc_empty(t->tls_array + idx))
875 return idx + GDT_ENTRY_TLS_MIN;
876 return -ESRCH;
877}
878
879/*
880 * Set a given TLS descriptor:
881 */
882asmlinkage int sys_set_thread_area(struct user_desc __user *u_info)
883{
884 struct thread_struct *t = &current->thread;
885 struct user_desc info;
886 struct desc_struct *desc;
887 int cpu, idx;
888
889 if (copy_from_user(&info, u_info, sizeof(info)))
890 return -EFAULT;
891 idx = info.entry_number;
892
893 /*
894 * index -1 means the kernel should try to find and
895 * allocate an empty descriptor:
896 */
897 if (idx == -1) {
898 idx = get_free_idx();
899 if (idx < 0)
900 return idx;
901 if (put_user(idx, &u_info->entry_number))
902 return -EFAULT;
903 }
904
905 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
906 return -EINVAL;
907
908 desc = t->tls_array + idx - GDT_ENTRY_TLS_MIN;
909
910 /*
911 * We must not get preempted while modifying the TLS.
912 */
913 cpu = get_cpu();
914
915 if (LDT_empty(&info)) {
916 desc->a = 0;
917 desc->b = 0;
918 } else {
919 desc->a = LDT_entry_a(&info);
920 desc->b = LDT_entry_b(&info);
921 }
922 load_TLS(t, cpu);
923
924 put_cpu();
925
926 return 0;
927}
928
929/*
930 * Get the current Thread-Local Storage area:
931 */
932
933#define GET_BASE(desc) ( \
934 (((desc)->a >> 16) & 0x0000ffff) | \
935 (((desc)->b << 16) & 0x00ff0000) | \
936 ( (desc)->b & 0xff000000) )
937
938#define GET_LIMIT(desc) ( \
939 ((desc)->a & 0x0ffff) | \
940 ((desc)->b & 0xf0000) )
941
942#define GET_32BIT(desc) (((desc)->b >> 22) & 1)
943#define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
944#define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
945#define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
946#define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
947#define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
948
949asmlinkage int sys_get_thread_area(struct user_desc __user *u_info)
950{
951 struct user_desc info;
952 struct desc_struct *desc;
953 int idx;
954
955 if (get_user(idx, &u_info->entry_number))
956 return -EFAULT;
957 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
958 return -EINVAL;
959
960 memset(&info, 0, sizeof(info));
961
962 desc = current->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
963
964 info.entry_number = idx;
965 info.base_addr = GET_BASE(desc);
966 info.limit = GET_LIMIT(desc);
967 info.seg_32bit = GET_32BIT(desc);
968 info.contents = GET_CONTENTS(desc);
969 info.read_exec_only = !GET_WRITABLE(desc);
970 info.limit_in_pages = GET_LIMIT_PAGES(desc);
971 info.seg_not_present = !GET_PRESENT(desc);
972 info.useable = GET_USEABLE(desc);
973
974 if (copy_to_user(u_info, &info, sizeof(info)))
975 return -EFAULT;
976 return 0;
977}
978
979unsigned long arch_align_stack(unsigned long sp) 888unsigned long arch_align_stack(unsigned long sp)
980{ 889{
981 if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) 890 if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
982 sp -= get_random_int() % 8192; 891 sp -= get_random_int() % 8192;
983 return sp & ~0xf; 892 return sp & ~0xf;
984} 893}
894
895unsigned long arch_randomize_brk(struct mm_struct *mm)
896{
897 unsigned long range_end = mm->brk + 0x02000000;
898 return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
899}