process_64.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. *
  4. * Pentium III FXSR, SSE support
  5. * Gareth Hughes <gareth@valinux.com>, May 2000
  6. *
  7. * X86-64 port
  8. * Andi Kleen.
  9. *
  10. * CPU hotplug support - ashok.raj@intel.com
  11. */
  12. /*
  13. * This file handles the architecture-dependent parts of process handling..
  14. */
  15. #include <linux/stackprotector.h>
  16. #include <linux/cpu.h>
  17. #include <linux/errno.h>
  18. #include <linux/sched.h>
  19. #include <linux/fs.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/elfcore.h>
  23. #include <linux/smp.h>
  24. #include <linux/slab.h>
  25. #include <linux/user.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/delay.h>
  28. #include <linux/module.h>
  29. #include <linux/ptrace.h>
  30. #include <linux/notifier.h>
  31. #include <linux/kprobes.h>
  32. #include <linux/kdebug.h>
  33. #include <linux/tick.h>
  34. #include <linux/prctl.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/io.h>
  37. #include <linux/ftrace.h>
  38. #include <linux/cpuidle.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/system.h>
  41. #include <asm/processor.h>
  42. #include <asm/i387.h>
  43. #include <asm/mmu_context.h>
  44. #include <asm/prctl.h>
  45. #include <asm/desc.h>
  46. #include <asm/proto.h>
  47. #include <asm/ia32.h>
  48. #include <asm/idle.h>
  49. #include <asm/syscalls.h>
  50. #include <asm/debugreg.h>
  51. asmlinkage extern void ret_from_fork(void);
  52. DEFINE_PER_CPU(unsigned long, old_rsp);
  53. static DEFINE_PER_CPU(unsigned char, is_idle);
  54. static ATOMIC_NOTIFIER_HEAD(idle_notifier);
  55. void idle_notifier_register(struct notifier_block *n)
  56. {
  57. atomic_notifier_chain_register(&idle_notifier, n);
  58. }
  59. EXPORT_SYMBOL_GPL(idle_notifier_register);
  60. void idle_notifier_unregister(struct notifier_block *n)
  61. {
  62. atomic_notifier_chain_unregister(&idle_notifier, n);
  63. }
  64. EXPORT_SYMBOL_GPL(idle_notifier_unregister);
  65. void enter_idle(void)
  66. {
  67. percpu_write(is_idle, 1);
  68. atomic_notifier_call_chain(&idle_notifier, IDLE_START, NULL);
  69. }
  70. static void __exit_idle(void)
  71. {
  72. if (x86_test_and_clear_bit_percpu(0, is_idle) == 0)
  73. return;
  74. atomic_notifier_call_chain(&idle_notifier, IDLE_END, NULL);
  75. }
  76. /* Called from interrupts to signify idle end */
  77. void exit_idle(void)
  78. {
  79. /* idle loop has pid 0 */
  80. if (current->pid)
  81. return;
  82. __exit_idle();
  83. }
  84. #ifndef CONFIG_SMP
  85. static inline void play_dead(void)
  86. {
  87. BUG();
  88. }
  89. #endif
  90. /*
  91. * The idle thread. There's no useful work to be
  92. * done, so just try to conserve power and have a
  93. * low exit latency (ie sit in a loop waiting for
  94. * somebody to say that they'd like to reschedule)
  95. */
  96. void cpu_idle(void)
  97. {
  98. current_thread_info()->status |= TS_POLLING;
  99. /*
  100. * If we're the non-boot CPU, nothing set the stack canary up
  101. * for us. CPU0 already has it initialized but no harm in
  102. * doing it again. This is a good place for updating it, as
  103. * we wont ever return from this function (so the invalid
  104. * canaries already on the stack wont ever trigger).
  105. */
  106. boot_init_stack_canary();
  107. /* endless idle loop with no priority at all */
  108. while (1) {
  109. tick_nohz_stop_sched_tick(1);
  110. while (!need_resched()) {
  111. rmb();
  112. if (cpu_is_offline(smp_processor_id()))
  113. play_dead();
  114. /*
  115. * Idle routines should keep interrupts disabled
  116. * from here on, until they go to idle.
  117. * Otherwise, idle callbacks can misfire.
  118. */
  119. local_irq_disable();
  120. enter_idle();
  121. /* Don't trace irqs off for idle */
  122. stop_critical_timings();
  123. if (cpuidle_idle_call())
  124. pm_idle();
  125. start_critical_timings();
  126. /* In many cases the interrupt that ended idle
  127. has already called exit_idle. But some idle
  128. loops can be woken up without interrupt. */
  129. __exit_idle();
  130. }
  131. tick_nohz_restart_sched_tick();
  132. preempt_enable_no_resched();
  133. schedule();
  134. preempt_disable();
  135. }
  136. }
  137. /* Prints also some state that isn't saved in the pt_regs */
  138. void __show_regs(struct pt_regs *regs, int all)
  139. {
  140. unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
  141. unsigned long d0, d1, d2, d3, d6, d7;
  142. unsigned int fsindex, gsindex;
  143. unsigned int ds, cs, es;
  144. show_regs_common();
  145. printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
  146. printk_address(regs->ip, 1);
  147. printk(KERN_DEFAULT "RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss,
  148. regs->sp, regs->flags);
  149. printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
  150. regs->ax, regs->bx, regs->cx);
  151. printk(KERN_DEFAULT "RDX: %016lx RSI: %016lx RDI: %016lx\n",
  152. regs->dx, regs->si, regs->di);
  153. printk(KERN_DEFAULT "RBP: %016lx R08: %016lx R09: %016lx\n",
  154. regs->bp, regs->r8, regs->r9);
  155. printk(KERN_DEFAULT "R10: %016lx R11: %016lx R12: %016lx\n",
  156. regs->r10, regs->r11, regs->r12);
  157. printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
  158. regs->r13, regs->r14, regs->r15);
  159. asm("movl %%ds,%0" : "=r" (ds));
  160. asm("movl %%cs,%0" : "=r" (cs));
  161. asm("movl %%es,%0" : "=r" (es));
  162. asm("movl %%fs,%0" : "=r" (fsindex));
  163. asm("movl %%gs,%0" : "=r" (gsindex));
  164. rdmsrl(MSR_FS_BASE, fs);
  165. rdmsrl(MSR_GS_BASE, gs);
  166. rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
  167. if (!all)
  168. return;
  169. cr0 = read_cr0();
  170. cr2 = read_cr2();
  171. cr3 = read_cr3();
  172. cr4 = read_cr4();
  173. printk(KERN_DEFAULT "FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
  174. fs, fsindex, gs, gsindex, shadowgs);
  175. printk(KERN_DEFAULT "CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
  176. es, cr0);
  177. printk(KERN_DEFAULT "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
  178. cr4);
  179. get_debugreg(d0, 0);
  180. get_debugreg(d1, 1);
  181. get_debugreg(d2, 2);
  182. printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
  183. get_debugreg(d3, 3);
  184. get_debugreg(d6, 6);
  185. get_debugreg(d7, 7);
  186. printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
  187. }
  188. void release_thread(struct task_struct *dead_task)
  189. {
  190. if (dead_task->mm) {
  191. if (dead_task->mm->context.size) {
  192. printk("WARNING: dead process %8s still has LDT? <%p/%d>\n",
  193. dead_task->comm,
  194. dead_task->mm->context.ldt,
  195. dead_task->mm->context.size);
  196. BUG();
  197. }
  198. }
  199. }
  200. static inline void set_32bit_tls(struct task_struct *t, int tls, u32 addr)
  201. {
  202. struct user_desc ud = {
  203. .base_addr = addr,
  204. .limit = 0xfffff,
  205. .seg_32bit = 1,
  206. .limit_in_pages = 1,
  207. .useable = 1,
  208. };
  209. struct desc_struct *desc = t->thread.tls_array;
  210. desc += tls;
  211. fill_ldt(desc, &ud);
  212. }
  213. static inline u32 read_32bit_tls(struct task_struct *t, int tls)
  214. {
  215. return get_desc_base(&t->thread.tls_array[tls]);
  216. }
  217. /*
  218. * This gets called before we allocate a new thread and copy
  219. * the current task into it.
  220. */
  221. void prepare_to_copy(struct task_struct *tsk)
  222. {
  223. unlazy_fpu(tsk);
  224. }
  225. int copy_thread(unsigned long clone_flags, unsigned long sp,
  226. unsigned long unused,
  227. struct task_struct *p, struct pt_regs *regs)
  228. {
  229. int err;
  230. struct pt_regs *childregs;
  231. struct task_struct *me = current;
  232. childregs = ((struct pt_regs *)
  233. (THREAD_SIZE + task_stack_page(p))) - 1;
  234. *childregs = *regs;
  235. childregs->ax = 0;
  236. if (user_mode(regs))
  237. childregs->sp = sp;
  238. else
  239. childregs->sp = (unsigned long)childregs;
  240. p->thread.sp = (unsigned long) childregs;
  241. p->thread.sp0 = (unsigned long) (childregs+1);
  242. p->thread.usersp = me->thread.usersp;
  243. set_tsk_thread_flag(p, TIF_FORK);
  244. p->thread.io_bitmap_ptr = NULL;
  245. savesegment(gs, p->thread.gsindex);
  246. p->thread.gs = p->thread.gsindex ? 0 : me->thread.gs;
  247. savesegment(fs, p->thread.fsindex);
  248. p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
  249. savesegment(es, p->thread.es);
  250. savesegment(ds, p->thread.ds);
  251. err = -ENOMEM;
  252. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  253. if (unlikely(test_tsk_thread_flag(me, TIF_IO_BITMAP))) {
  254. p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
  255. if (!p->thread.io_bitmap_ptr) {
  256. p->thread.io_bitmap_max = 0;
  257. return -ENOMEM;
  258. }
  259. memcpy(p->thread.io_bitmap_ptr, me->thread.io_bitmap_ptr,
  260. IO_BITMAP_BYTES);
  261. set_tsk_thread_flag(p, TIF_IO_BITMAP);
  262. }
  263. /*
  264. * Set a new TLS for the child thread?
  265. */
  266. if (clone_flags & CLONE_SETTLS) {
  267. #ifdef CONFIG_IA32_EMULATION
  268. if (test_thread_flag(TIF_IA32))
  269. err = do_set_thread_area(p, -1,
  270. (struct user_desc __user *)childregs->si, 0);
  271. else
  272. #endif
  273. err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8);
  274. if (err)
  275. goto out;
  276. }
  277. err = 0;
  278. out:
  279. if (err && p->thread.io_bitmap_ptr) {
  280. kfree(p->thread.io_bitmap_ptr);
  281. p->thread.io_bitmap_max = 0;
  282. }
  283. return err;
  284. }
  285. static void
  286. start_thread_common(struct pt_regs *regs, unsigned long new_ip,
  287. unsigned long new_sp,
  288. unsigned int _cs, unsigned int _ss, unsigned int _ds)
  289. {
  290. loadsegment(fs, 0);
  291. loadsegment(es, _ds);
  292. loadsegment(ds, _ds);
  293. load_gs_index(0);
  294. regs->ip = new_ip;
  295. regs->sp = new_sp;
  296. percpu_write(old_rsp, new_sp);
  297. regs->cs = _cs;
  298. regs->ss = _ss;
  299. regs->flags = X86_EFLAGS_IF;
  300. /*
  301. * Free the old FP and other extended state
  302. */
  303. free_thread_xstate(current);
  304. }
  305. void
  306. start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  307. {
  308. start_thread_common(regs, new_ip, new_sp,
  309. __USER_CS, __USER_DS, 0);
  310. }
  311. #ifdef CONFIG_IA32_EMULATION
  312. void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp)
  313. {
  314. start_thread_common(regs, new_ip, new_sp,
  315. __USER32_CS, __USER32_DS, __USER32_DS);
  316. }
  317. #endif
  318. /*
  319. * switch_to(x,y) should switch tasks from x to y.
  320. *
  321. * This could still be optimized:
  322. * - fold all the options into a flag word and test it with a single test.
  323. * - could test fs/gs bitsliced
  324. *
  325. * Kprobes not supported here. Set the probe on schedule instead.
  326. * Function graph tracer not supported too.
  327. */
  328. __notrace_funcgraph struct task_struct *
  329. __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  330. {
  331. struct thread_struct *prev = &prev_p->thread;
  332. struct thread_struct *next = &next_p->thread;
  333. int cpu = smp_processor_id();
  334. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  335. unsigned fsindex, gsindex;
  336. bool preload_fpu;
  337. /*
  338. * If the task has used fpu the last 5 timeslices, just do a full
  339. * restore of the math state immediately to avoid the trap; the
  340. * chances of needing FPU soon are obviously high now
  341. */
  342. preload_fpu = tsk_used_math(next_p) && next_p->fpu_counter > 5;
  343. /* we're going to use this soon, after a few expensive things */
  344. if (preload_fpu)
  345. prefetch(next->fpu.state);
  346. /*
  347. * Reload esp0, LDT and the page table pointer:
  348. */
  349. load_sp0(tss, next);
  350. /*
  351. * Switch DS and ES.
  352. * This won't pick up thread selector changes, but I guess that is ok.
  353. */
  354. savesegment(es, prev->es);
  355. if (unlikely(next->es | prev->es))
  356. loadsegment(es, next->es);
  357. savesegment(ds, prev->ds);
  358. if (unlikely(next->ds | prev->ds))
  359. loadsegment(ds, next->ds);
  360. /* We must save %fs and %gs before load_TLS() because
  361. * %fs and %gs may be cleared by load_TLS().
  362. *
  363. * (e.g. xen_load_tls())
  364. */
  365. savesegment(fs, fsindex);
  366. savesegment(gs, gsindex);
  367. load_TLS(next, cpu);
  368. /* Must be after DS reload */
  369. __unlazy_fpu(prev_p);
  370. /* Make sure cpu is ready for new context */
  371. if (preload_fpu)
  372. clts();
  373. /*
  374. * Leave lazy mode, flushing any hypercalls made here.
  375. * This must be done before restoring TLS segments so
  376. * the GDT and LDT are properly updated, and must be
  377. * done before math_state_restore, so the TS bit is up
  378. * to date.
  379. */
  380. arch_end_context_switch(next_p);
  381. /*
  382. * Switch FS and GS.
  383. *
  384. * Segment register != 0 always requires a reload. Also
  385. * reload when it has changed. When prev process used 64bit
  386. * base always reload to avoid an information leak.
  387. */
  388. if (unlikely(fsindex | next->fsindex | prev->fs)) {
  389. loadsegment(fs, next->fsindex);
  390. /*
  391. * Check if the user used a selector != 0; if yes
  392. * clear 64bit base, since overloaded base is always
  393. * mapped to the Null selector
  394. */
  395. if (fsindex)
  396. prev->fs = 0;
  397. }
  398. /* when next process has a 64bit base use it */
  399. if (next->fs)
  400. wrmsrl(MSR_FS_BASE, next->fs);
  401. prev->fsindex = fsindex;
  402. if (unlikely(gsindex | next->gsindex | prev->gs)) {
  403. load_gs_index(next->gsindex);
  404. if (gsindex)
  405. prev->gs = 0;
  406. }
  407. if (next->gs)
  408. wrmsrl(MSR_KERNEL_GS_BASE, next->gs);
  409. prev->gsindex = gsindex;
  410. /*
  411. * Switch the PDA and FPU contexts.
  412. */
  413. prev->usersp = percpu_read(old_rsp);
  414. percpu_write(old_rsp, next->usersp);
  415. percpu_write(current_task, next_p);
  416. percpu_write(kernel_stack,
  417. (unsigned long)task_stack_page(next_p) +
  418. THREAD_SIZE - KERNEL_STACK_OFFSET);
  419. /*
  420. * Now maybe reload the debug registers and handle I/O bitmaps
  421. */
  422. if (unlikely(task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT ||
  423. task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV))
  424. __switch_to_xtra(prev_p, next_p, tss);
  425. /*
  426. * Preload the FPU context, now that we've determined that the
  427. * task is likely to be using it.
  428. */
  429. if (preload_fpu)
  430. __math_state_restore();
  431. return prev_p;
  432. }
  433. void set_personality_64bit(void)
  434. {
  435. /* inherit personality from parent */
  436. /* Make sure to be in 64bit mode */
  437. clear_thread_flag(TIF_IA32);
  438. /* Ensure the corresponding mm is not marked. */
  439. if (current->mm)
  440. current->mm->context.ia32_compat = 0;
  441. /* TBD: overwrites user setup. Should have two bits.
  442. But 64bit processes have always behaved this way,
  443. so it's not too bad. The main problem is just that
  444. 32bit childs are affected again. */
  445. current->personality &= ~READ_IMPLIES_EXEC;
  446. }
  447. void set_personality_ia32(void)
  448. {
  449. /* inherit personality from parent */
  450. /* Make sure to be in 32bit mode */
  451. set_thread_flag(TIF_IA32);
  452. current->personality |= force_personality32;
  453. /* Mark the associated mm as containing 32-bit tasks. */
  454. if (current->mm)
  455. current->mm->context.ia32_compat = 1;
  456. /* Prepare the first "return" to user space */
  457. current_thread_info()->status |= TS_COMPAT;
  458. }
  459. unsigned long get_wchan(struct task_struct *p)
  460. {
  461. unsigned long stack;
  462. u64 fp, ip;
  463. int count = 0;
  464. if (!p || p == current || p->state == TASK_RUNNING)
  465. return 0;
  466. stack = (unsigned long)task_stack_page(p);
  467. if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
  468. return 0;
  469. fp = *(u64 *)(p->thread.sp);
  470. do {
  471. if (fp < (unsigned long)stack ||
  472. fp >= (unsigned long)stack+THREAD_SIZE)
  473. return 0;
  474. ip = *(u64 *)(fp+8);
  475. if (!in_sched_functions(ip))
  476. return ip;
  477. fp = *(u64 *)fp;
  478. } while (count++ < 16);
  479. return 0;
  480. }
  481. long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
  482. {
  483. int ret = 0;
  484. int doit = task == current;
  485. int cpu;
  486. switch (code) {
  487. case ARCH_SET_GS:
  488. if (addr >= TASK_SIZE_OF(task))
  489. return -EPERM;
  490. cpu = get_cpu();
  491. /* handle small bases via the GDT because that's faster to
  492. switch. */
  493. if (addr <= 0xffffffff) {
  494. set_32bit_tls(task, GS_TLS, addr);
  495. if (doit) {
  496. load_TLS(&task->thread, cpu);
  497. load_gs_index(GS_TLS_SEL);
  498. }
  499. task->thread.gsindex = GS_TLS_SEL;
  500. task->thread.gs = 0;
  501. } else {
  502. task->thread.gsindex = 0;
  503. task->thread.gs = addr;
  504. if (doit) {
  505. load_gs_index(0);
  506. ret = checking_wrmsrl(MSR_KERNEL_GS_BASE, addr);
  507. }
  508. }
  509. put_cpu();
  510. break;
  511. case ARCH_SET_FS:
  512. /* Not strictly needed for fs, but do it for symmetry
  513. with gs */
  514. if (addr >= TASK_SIZE_OF(task))
  515. return -EPERM;
  516. cpu = get_cpu();
  517. /* handle small bases via the GDT because that's faster to
  518. switch. */
  519. if (addr <= 0xffffffff) {
  520. set_32bit_tls(task, FS_TLS, addr);
  521. if (doit) {
  522. load_TLS(&task->thread, cpu);
  523. loadsegment(fs, FS_TLS_SEL);
  524. }
  525. task->thread.fsindex = FS_TLS_SEL;
  526. task->thread.fs = 0;
  527. } else {
  528. task->thread.fsindex = 0;
  529. task->thread.fs = addr;
  530. if (doit) {
  531. /* set the selector to 0 to not confuse
  532. __switch_to */
  533. loadsegment(fs, 0);
  534. ret = checking_wrmsrl(MSR_FS_BASE, addr);
  535. }
  536. }
  537. put_cpu();
  538. break;
  539. case ARCH_GET_FS: {
  540. unsigned long base;
  541. if (task->thread.fsindex == FS_TLS_SEL)
  542. base = read_32bit_tls(task, FS_TLS);
  543. else if (doit)
  544. rdmsrl(MSR_FS_BASE, base);
  545. else
  546. base = task->thread.fs;
  547. ret = put_user(base, (unsigned long __user *)addr);
  548. break;
  549. }
  550. case ARCH_GET_GS: {
  551. unsigned long base;
  552. unsigned gsindex;
  553. if (task->thread.gsindex == GS_TLS_SEL)
  554. base = read_32bit_tls(task, GS_TLS);
  555. else if (doit) {
  556. savesegment(gs, gsindex);
  557. if (gsindex)
  558. rdmsrl(MSR_KERNEL_GS_BASE, base);
  559. else
  560. base = task->thread.gs;
  561. } else
  562. base = task->thread.gs;
  563. ret = put_user(base, (unsigned long __user *)addr);
  564. break;
  565. }
  566. default:
  567. ret = -EINVAL;
  568. break;
  569. }
  570. return ret;
  571. }
  572. long sys_arch_prctl(int code, unsigned long addr)
  573. {
  574. return do_arch_prctl(current, code, addr);
  575. }
  576. unsigned long KSTK_ESP(struct task_struct *task)
  577. {
  578. return (test_tsk_thread_flag(task, TIF_IA32)) ?
  579. (task_pt_regs(task)->sp) : ((task)->thread.usersp);
  580. }