process_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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/cpu.h>
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/fs.h>
  19. #include <linux/kernel.h>
  20. #include <linux/mm.h>
  21. #include <linux/elfcore.h>
  22. #include <linux/smp.h>
  23. #include <linux/slab.h>
  24. #include <linux/user.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/module.h>
  28. #include <linux/ptrace.h>
  29. #include <linux/notifier.h>
  30. #include <linux/kprobes.h>
  31. #include <linux/kdebug.h>
  32. #include <linux/prctl.h>
  33. #include <linux/uaccess.h>
  34. #include <linux/io.h>
  35. #include <linux/ftrace.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/processor.h>
  38. #include <asm/i387.h>
  39. #include <asm/fpu-internal.h>
  40. #include <asm/mmu_context.h>
  41. #include <asm/prctl.h>
  42. #include <asm/desc.h>
  43. #include <asm/proto.h>
  44. #include <asm/ia32.h>
  45. #include <asm/idle.h>
  46. #include <asm/syscalls.h>
  47. #include <asm/debugreg.h>
  48. #include <asm/switch_to.h>
  49. #include <asm/xen/hypervisor.h>
  50. asmlinkage extern void ret_from_fork(void);
  51. DEFINE_PER_CPU(unsigned long, old_rsp);
  52. /* Prints also some state that isn't saved in the pt_regs */
  53. void __show_regs(struct pt_regs *regs, int all)
  54. {
  55. unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
  56. unsigned long d0, d1, d2, d3, d6, d7;
  57. unsigned int fsindex, gsindex;
  58. unsigned int ds, cs, es;
  59. show_regs_common();
  60. printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
  61. printk_address(regs->ip, 1);
  62. printk(KERN_DEFAULT "RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss,
  63. regs->sp, regs->flags);
  64. printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
  65. regs->ax, regs->bx, regs->cx);
  66. printk(KERN_DEFAULT "RDX: %016lx RSI: %016lx RDI: %016lx\n",
  67. regs->dx, regs->si, regs->di);
  68. printk(KERN_DEFAULT "RBP: %016lx R08: %016lx R09: %016lx\n",
  69. regs->bp, regs->r8, regs->r9);
  70. printk(KERN_DEFAULT "R10: %016lx R11: %016lx R12: %016lx\n",
  71. regs->r10, regs->r11, regs->r12);
  72. printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
  73. regs->r13, regs->r14, regs->r15);
  74. asm("movl %%ds,%0" : "=r" (ds));
  75. asm("movl %%cs,%0" : "=r" (cs));
  76. asm("movl %%es,%0" : "=r" (es));
  77. asm("movl %%fs,%0" : "=r" (fsindex));
  78. asm("movl %%gs,%0" : "=r" (gsindex));
  79. rdmsrl(MSR_FS_BASE, fs);
  80. rdmsrl(MSR_GS_BASE, gs);
  81. rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
  82. if (!all)
  83. return;
  84. cr0 = read_cr0();
  85. cr2 = read_cr2();
  86. cr3 = read_cr3();
  87. cr4 = read_cr4();
  88. printk(KERN_DEFAULT "FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
  89. fs, fsindex, gs, gsindex, shadowgs);
  90. printk(KERN_DEFAULT "CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
  91. es, cr0);
  92. printk(KERN_DEFAULT "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
  93. cr4);
  94. get_debugreg(d0, 0);
  95. get_debugreg(d1, 1);
  96. get_debugreg(d2, 2);
  97. printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
  98. get_debugreg(d3, 3);
  99. get_debugreg(d6, 6);
  100. get_debugreg(d7, 7);
  101. printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
  102. }
  103. void release_thread(struct task_struct *dead_task)
  104. {
  105. if (dead_task->mm) {
  106. if (dead_task->mm->context.ldt) {
  107. printk("WARNING: dead process %8s still has LDT? <%p/%d>\n",
  108. dead_task->comm,
  109. dead_task->mm->context.ldt->entries,
  110. dead_task->mm->context.ldt->size);
  111. BUG();
  112. }
  113. }
  114. }
  115. static inline void set_32bit_tls(struct task_struct *t, int tls, u32 addr)
  116. {
  117. struct user_desc ud = {
  118. .base_addr = addr,
  119. .limit = 0xfffff,
  120. .seg_32bit = 1,
  121. .limit_in_pages = 1,
  122. .useable = 1,
  123. };
  124. struct desc_struct *desc = t->thread.tls_array;
  125. desc += tls;
  126. fill_ldt(desc, &ud);
  127. }
  128. static inline u32 read_32bit_tls(struct task_struct *t, int tls)
  129. {
  130. return get_desc_base(&t->thread.tls_array[tls]);
  131. }
  132. /*
  133. * This gets called before we allocate a new thread and copy
  134. * the current task into it.
  135. */
  136. void prepare_to_copy(struct task_struct *tsk)
  137. {
  138. unlazy_fpu(tsk);
  139. }
  140. int copy_thread(unsigned long clone_flags, unsigned long sp,
  141. unsigned long unused,
  142. struct task_struct *p, struct pt_regs *regs)
  143. {
  144. int err;
  145. struct pt_regs *childregs;
  146. struct task_struct *me = current;
  147. childregs = ((struct pt_regs *)
  148. (THREAD_SIZE + task_stack_page(p))) - 1;
  149. *childregs = *regs;
  150. childregs->ax = 0;
  151. if (user_mode(regs))
  152. childregs->sp = sp;
  153. else
  154. childregs->sp = (unsigned long)childregs;
  155. p->thread.sp = (unsigned long) childregs;
  156. p->thread.sp0 = (unsigned long) (childregs+1);
  157. p->thread.usersp = me->thread.usersp;
  158. set_tsk_thread_flag(p, TIF_FORK);
  159. p->fpu_counter = 0;
  160. p->thread.io_bitmap_ptr = NULL;
  161. savesegment(gs, p->thread.gsindex);
  162. p->thread.gs = p->thread.gsindex ? 0 : me->thread.gs;
  163. savesegment(fs, p->thread.fsindex);
  164. p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
  165. savesegment(es, p->thread.es);
  166. savesegment(ds, p->thread.ds);
  167. err = -ENOMEM;
  168. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  169. if (unlikely(test_tsk_thread_flag(me, TIF_IO_BITMAP))) {
  170. p->thread.io_bitmap_ptr = kmemdup(me->thread.io_bitmap_ptr,
  171. IO_BITMAP_BYTES, GFP_KERNEL);
  172. if (!p->thread.io_bitmap_ptr) {
  173. p->thread.io_bitmap_max = 0;
  174. return -ENOMEM;
  175. }
  176. set_tsk_thread_flag(p, TIF_IO_BITMAP);
  177. }
  178. /*
  179. * Set a new TLS for the child thread?
  180. */
  181. if (clone_flags & CLONE_SETTLS) {
  182. #ifdef CONFIG_IA32_EMULATION
  183. if (test_thread_flag(TIF_IA32))
  184. err = do_set_thread_area(p, -1,
  185. (struct user_desc __user *)childregs->si, 0);
  186. else
  187. #endif
  188. err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8);
  189. if (err)
  190. goto out;
  191. }
  192. err = 0;
  193. out:
  194. if (err && p->thread.io_bitmap_ptr) {
  195. kfree(p->thread.io_bitmap_ptr);
  196. p->thread.io_bitmap_max = 0;
  197. }
  198. return err;
  199. }
  200. static void
  201. start_thread_common(struct pt_regs *regs, unsigned long new_ip,
  202. unsigned long new_sp,
  203. unsigned int _cs, unsigned int _ss, unsigned int _ds)
  204. {
  205. loadsegment(fs, 0);
  206. loadsegment(es, _ds);
  207. loadsegment(ds, _ds);
  208. load_gs_index(0);
  209. current->thread.usersp = new_sp;
  210. regs->ip = new_ip;
  211. regs->sp = new_sp;
  212. percpu_write(old_rsp, new_sp);
  213. regs->cs = _cs;
  214. regs->ss = _ss;
  215. regs->flags = X86_EFLAGS_IF;
  216. /*
  217. * Free the old FP and other extended state
  218. */
  219. free_thread_xstate(current);
  220. }
  221. void
  222. start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  223. {
  224. start_thread_common(regs, new_ip, new_sp,
  225. __USER_CS, __USER_DS, 0);
  226. }
  227. #ifdef CONFIG_IA32_EMULATION
  228. void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp)
  229. {
  230. start_thread_common(regs, new_ip, new_sp,
  231. test_thread_flag(TIF_X32)
  232. ? __USER_CS : __USER32_CS,
  233. __USER_DS, __USER_DS);
  234. }
  235. #endif
  236. /*
  237. * switch_to(x,y) should switch tasks from x to y.
  238. *
  239. * This could still be optimized:
  240. * - fold all the options into a flag word and test it with a single test.
  241. * - could test fs/gs bitsliced
  242. *
  243. * Kprobes not supported here. Set the probe on schedule instead.
  244. * Function graph tracer not supported too.
  245. */
  246. __notrace_funcgraph struct task_struct *
  247. __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  248. {
  249. struct thread_struct *prev = &prev_p->thread;
  250. struct thread_struct *next = &next_p->thread;
  251. int cpu = smp_processor_id();
  252. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  253. unsigned fsindex, gsindex;
  254. fpu_switch_t fpu;
  255. fpu = switch_fpu_prepare(prev_p, next_p, cpu);
  256. /* Reload esp0 and ss1. */
  257. load_sp0(tss, next);
  258. /* We must save %fs and %gs before load_TLS() because
  259. * %fs and %gs may be cleared by load_TLS().
  260. *
  261. * (e.g. xen_load_tls())
  262. */
  263. savesegment(fs, fsindex);
  264. savesegment(gs, gsindex);
  265. /*
  266. * Load TLS before restoring any segments so that segment loads
  267. * reference the correct GDT entries.
  268. */
  269. load_TLS(next, cpu);
  270. /*
  271. * Leave lazy mode, flushing any hypercalls made here. This
  272. * must be done after loading TLS entries in the GDT but before
  273. * loading segments that might reference them, and and it must
  274. * be done before math_state_restore, so the TS bit is up to
  275. * date.
  276. */
  277. arch_end_context_switch(next_p);
  278. /* Switch DS and ES.
  279. *
  280. * Reading them only returns the selectors, but writing them (if
  281. * nonzero) loads the full descriptor from the GDT or LDT. The
  282. * LDT for next is loaded in switch_mm, and the GDT is loaded
  283. * above.
  284. *
  285. * We therefore need to write new values to the segment
  286. * registers on every context switch unless both the new and old
  287. * values are zero.
  288. *
  289. * Note that we don't need to do anything for CS and SS, as
  290. * those are saved and restored as part of pt_regs.
  291. */
  292. savesegment(es, prev->es);
  293. if (unlikely(next->es | prev->es))
  294. loadsegment(es, next->es);
  295. savesegment(ds, prev->ds);
  296. if (unlikely(next->ds | prev->ds))
  297. loadsegment(ds, next->ds);
  298. /*
  299. * Switch FS and GS.
  300. *
  301. * These are even more complicated than FS and GS: they have
  302. * 64-bit bases are that controlled by arch_prctl. Those bases
  303. * only differ from the values in the GDT or LDT if the selector
  304. * is 0.
  305. *
  306. * Loading the segment register resets the hidden base part of
  307. * the register to 0 or the value from the GDT / LDT. If the
  308. * next base address zero, writing 0 to the segment register is
  309. * much faster than using wrmsr to explicitly zero the base.
  310. *
  311. * The thread_struct.fs and thread_struct.gs values are 0
  312. * if the fs and gs bases respectively are not overridden
  313. * from the values implied by fsindex and gsindex. They
  314. * are nonzero, and store the nonzero base addresses, if
  315. * the bases are overridden.
  316. *
  317. * (fs != 0 && fsindex != 0) || (gs != 0 && gsindex != 0) should
  318. * be impossible.
  319. *
  320. * Therefore we need to reload the segment registers if either
  321. * the old or new selector is nonzero, and we need to override
  322. * the base address if next thread expects it to be overridden.
  323. *
  324. * This code is unnecessarily slow in the case where the old and
  325. * new indexes are zero and the new base is nonzero -- it will
  326. * unnecessarily write 0 to the selector before writing the new
  327. * base address.
  328. *
  329. * Note: This all depends on arch_prctl being the only way that
  330. * user code can override the segment base. Once wrfsbase and
  331. * wrgsbase are enabled, most of this code will need to change.
  332. */
  333. if (unlikely(fsindex | next->fsindex | prev->fs)) {
  334. loadsegment(fs, next->fsindex);
  335. /*
  336. * If user code wrote a nonzero value to FS, then it also
  337. * cleared the overridden base address.
  338. *
  339. * XXX: if user code wrote 0 to FS and cleared the base
  340. * address itself, we won't notice and we'll incorrectly
  341. * restore the prior base address next time we reschdule
  342. * the process.
  343. */
  344. if (fsindex)
  345. prev->fs = 0;
  346. }
  347. if (next->fs)
  348. wrmsrl(MSR_FS_BASE, next->fs);
  349. prev->fsindex = fsindex;
  350. if (unlikely(gsindex | next->gsindex | prev->gs)) {
  351. load_gs_index(next->gsindex);
  352. /* This works (and fails) the same way as fsindex above. */
  353. if (gsindex)
  354. prev->gs = 0;
  355. }
  356. if (next->gs)
  357. wrmsrl(MSR_KERNEL_GS_BASE, next->gs);
  358. prev->gsindex = gsindex;
  359. switch_fpu_finish(next_p, fpu);
  360. /*
  361. * Switch the PDA and FPU contexts.
  362. */
  363. prev->usersp = percpu_read(old_rsp);
  364. percpu_write(old_rsp, next->usersp);
  365. percpu_write(current_task, next_p);
  366. percpu_write(kernel_stack,
  367. (unsigned long)task_stack_page(next_p) +
  368. THREAD_SIZE - KERNEL_STACK_OFFSET);
  369. /*
  370. * Now maybe reload the debug registers and handle I/O bitmaps
  371. */
  372. if (unlikely(task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT ||
  373. task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV))
  374. __switch_to_xtra(prev_p, next_p, tss);
  375. #ifdef CONFIG_XEN
  376. /*
  377. * On Xen PV, IOPL bits in pt_regs->flags have no effect, and
  378. * current_pt_regs()->flags may not match the current task's
  379. * intended IOPL. We need to switch it manually.
  380. */
  381. if (unlikely(xen_pv_domain() &&
  382. prev->iopl != next->iopl))
  383. xen_set_iopl_mask(next->iopl);
  384. #endif
  385. return prev_p;
  386. }
  387. void set_personality_64bit(void)
  388. {
  389. /* inherit personality from parent */
  390. /* Make sure to be in 64bit mode */
  391. clear_thread_flag(TIF_IA32);
  392. clear_thread_flag(TIF_ADDR32);
  393. clear_thread_flag(TIF_X32);
  394. /* Ensure the corresponding mm is not marked. */
  395. if (current->mm)
  396. current->mm->context.ia32_compat = 0;
  397. /* TBD: overwrites user setup. Should have two bits.
  398. But 64bit processes have always behaved this way,
  399. so it's not too bad. The main problem is just that
  400. 32bit childs are affected again. */
  401. current->personality &= ~READ_IMPLIES_EXEC;
  402. }
  403. void set_personality_ia32(bool x32)
  404. {
  405. /* inherit personality from parent */
  406. /* Make sure to be in 32bit mode */
  407. set_thread_flag(TIF_ADDR32);
  408. /* Mark the associated mm as containing 32-bit tasks. */
  409. if (current->mm)
  410. current->mm->context.ia32_compat = 1;
  411. if (x32) {
  412. clear_thread_flag(TIF_IA32);
  413. set_thread_flag(TIF_X32);
  414. current->personality &= ~READ_IMPLIES_EXEC;
  415. /* is_compat_task() uses the presence of the x32
  416. syscall bit flag to determine compat status */
  417. current_thread_info()->status &= ~TS_COMPAT;
  418. } else {
  419. set_thread_flag(TIF_IA32);
  420. clear_thread_flag(TIF_X32);
  421. current->personality |= force_personality32;
  422. /* Prepare the first "return" to user space */
  423. current_thread_info()->status |= TS_COMPAT;
  424. }
  425. }
  426. EXPORT_SYMBOL_GPL(set_personality_ia32);
  427. /*
  428. * Called from fs/proc with a reference on @p to find the function
  429. * which called into schedule(). This needs to be done carefully
  430. * because the task might wake up and we might look at a stack
  431. * changing under us.
  432. */
  433. unsigned long get_wchan(struct task_struct *p)
  434. {
  435. unsigned long start, bottom, top, sp, fp, ip;
  436. int count = 0;
  437. if (!p || p == current || p->state == TASK_RUNNING)
  438. return 0;
  439. start = (unsigned long)task_stack_page(p);
  440. if (!start)
  441. return 0;
  442. /*
  443. * Layout of the stack page:
  444. *
  445. * ----------- topmax = start + THREAD_SIZE - sizeof(unsigned long)
  446. * PADDING
  447. * ----------- top = topmax - TOP_OF_KERNEL_STACK_PADDING
  448. * stack
  449. * ----------- bottom = start + sizeof(thread_info)
  450. * thread_info
  451. * ----------- start
  452. *
  453. * The tasks stack pointer points at the location where the
  454. * framepointer is stored. The data on the stack is:
  455. * ... IP FP ... IP FP
  456. *
  457. * We need to read FP and IP, so we need to adjust the upper
  458. * bound by another unsigned long.
  459. */
  460. top = start + THREAD_SIZE;
  461. top -= 2 * sizeof(unsigned long);
  462. bottom = start + sizeof(struct thread_info);
  463. sp = ACCESS_ONCE(p->thread.sp);
  464. if (sp < bottom || sp > top)
  465. return 0;
  466. fp = ACCESS_ONCE(*(unsigned long *)sp);
  467. do {
  468. if (fp < bottom || fp > top)
  469. return 0;
  470. ip = ACCESS_ONCE(*(unsigned long *)(fp + sizeof(unsigned long)));
  471. if (!in_sched_functions(ip))
  472. return ip;
  473. fp = ACCESS_ONCE(*(unsigned long *)fp);
  474. } while (count++ < 16 && p->state != TASK_RUNNING);
  475. return 0;
  476. }
  477. long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
  478. {
  479. int ret = 0;
  480. int doit = task == current;
  481. int cpu;
  482. switch (code) {
  483. case ARCH_SET_GS:
  484. if (addr >= TASK_SIZE_OF(task))
  485. return -EPERM;
  486. cpu = get_cpu();
  487. /* handle small bases via the GDT because that's faster to
  488. switch. */
  489. if (addr <= 0xffffffff) {
  490. set_32bit_tls(task, GS_TLS, addr);
  491. if (doit) {
  492. load_TLS(&task->thread, cpu);
  493. load_gs_index(GS_TLS_SEL);
  494. }
  495. task->thread.gsindex = GS_TLS_SEL;
  496. task->thread.gs = 0;
  497. } else {
  498. task->thread.gsindex = 0;
  499. task->thread.gs = addr;
  500. if (doit) {
  501. load_gs_index(0);
  502. ret = checking_wrmsrl(MSR_KERNEL_GS_BASE, addr);
  503. }
  504. }
  505. put_cpu();
  506. break;
  507. case ARCH_SET_FS:
  508. /* Not strictly needed for fs, but do it for symmetry
  509. with gs */
  510. if (addr >= TASK_SIZE_OF(task))
  511. return -EPERM;
  512. cpu = get_cpu();
  513. /* handle small bases via the GDT because that's faster to
  514. switch. */
  515. if (addr <= 0xffffffff) {
  516. set_32bit_tls(task, FS_TLS, addr);
  517. if (doit) {
  518. load_TLS(&task->thread, cpu);
  519. loadsegment(fs, FS_TLS_SEL);
  520. }
  521. task->thread.fsindex = FS_TLS_SEL;
  522. task->thread.fs = 0;
  523. } else {
  524. task->thread.fsindex = 0;
  525. task->thread.fs = addr;
  526. if (doit) {
  527. /* set the selector to 0 to not confuse
  528. __switch_to */
  529. loadsegment(fs, 0);
  530. ret = checking_wrmsrl(MSR_FS_BASE, addr);
  531. }
  532. }
  533. put_cpu();
  534. break;
  535. case ARCH_GET_FS: {
  536. unsigned long base;
  537. if (task->thread.fsindex == FS_TLS_SEL)
  538. base = read_32bit_tls(task, FS_TLS);
  539. else if (doit)
  540. rdmsrl(MSR_FS_BASE, base);
  541. else
  542. base = task->thread.fs;
  543. ret = put_user(base, (unsigned long __user *)addr);
  544. break;
  545. }
  546. case ARCH_GET_GS: {
  547. unsigned long base;
  548. unsigned gsindex;
  549. if (task->thread.gsindex == GS_TLS_SEL)
  550. base = read_32bit_tls(task, GS_TLS);
  551. else if (doit) {
  552. savesegment(gs, gsindex);
  553. if (gsindex)
  554. rdmsrl(MSR_KERNEL_GS_BASE, base);
  555. else
  556. base = task->thread.gs;
  557. } else
  558. base = task->thread.gs;
  559. ret = put_user(base, (unsigned long __user *)addr);
  560. break;
  561. }
  562. default:
  563. ret = -EINVAL;
  564. break;
  565. }
  566. return ret;
  567. }
  568. long sys_arch_prctl(int code, unsigned long addr)
  569. {
  570. return do_arch_prctl(current, code, addr);
  571. }
  572. unsigned long KSTK_ESP(struct task_struct *task)
  573. {
  574. return (test_tsk_thread_flag(task, TIF_IA32)) ?
  575. (task_pt_regs(task)->sp) : ((task)->thread.usersp);
  576. }