process_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. asmlinkage extern void ret_from_fork(void);
  50. __visible DEFINE_PER_CPU(unsigned long, rsp_scratch);
  51. /* Prints also some state that isn't saved in the pt_regs */
  52. void __show_regs(struct pt_regs *regs, int all)
  53. {
  54. unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
  55. unsigned long d0, d1, d2, d3, d6, d7;
  56. unsigned int fsindex, gsindex;
  57. unsigned int ds, cs, es;
  58. printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
  59. printk_address(regs->ip);
  60. printk(KERN_DEFAULT "RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss,
  61. regs->sp, regs->flags);
  62. printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
  63. regs->ax, regs->bx, regs->cx);
  64. printk(KERN_DEFAULT "RDX: %016lx RSI: %016lx RDI: %016lx\n",
  65. regs->dx, regs->si, regs->di);
  66. printk(KERN_DEFAULT "RBP: %016lx R08: %016lx R09: %016lx\n",
  67. regs->bp, regs->r8, regs->r9);
  68. printk(KERN_DEFAULT "R10: %016lx R11: %016lx R12: %016lx\n",
  69. regs->r10, regs->r11, regs->r12);
  70. printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
  71. regs->r13, regs->r14, regs->r15);
  72. asm("movl %%ds,%0" : "=r" (ds));
  73. asm("movl %%cs,%0" : "=r" (cs));
  74. asm("movl %%es,%0" : "=r" (es));
  75. asm("movl %%fs,%0" : "=r" (fsindex));
  76. asm("movl %%gs,%0" : "=r" (gsindex));
  77. rdmsrl(MSR_FS_BASE, fs);
  78. rdmsrl(MSR_GS_BASE, gs);
  79. rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
  80. if (!all)
  81. return;
  82. cr0 = read_cr0();
  83. cr2 = read_cr2();
  84. cr3 = read_cr3();
  85. cr4 = __read_cr4();
  86. printk(KERN_DEFAULT "FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
  87. fs, fsindex, gs, gsindex, shadowgs);
  88. printk(KERN_DEFAULT "CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
  89. es, cr0);
  90. printk(KERN_DEFAULT "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
  91. cr4);
  92. get_debugreg(d0, 0);
  93. get_debugreg(d1, 1);
  94. get_debugreg(d2, 2);
  95. get_debugreg(d3, 3);
  96. get_debugreg(d6, 6);
  97. get_debugreg(d7, 7);
  98. /* Only print out debug registers if they are in their non-default state. */
  99. if ((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
  100. (d6 == DR6_RESERVED) && (d7 == 0x400))
  101. return;
  102. printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
  103. printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
  104. }
  105. void release_thread(struct task_struct *dead_task)
  106. {
  107. if (dead_task->mm) {
  108. if (dead_task->mm->context.size) {
  109. pr_warn("WARNING: dead process %s still has LDT? <%p/%d>\n",
  110. dead_task->comm,
  111. dead_task->mm->context.ldt,
  112. dead_task->mm->context.size);
  113. BUG();
  114. }
  115. }
  116. }
  117. static inline void set_32bit_tls(struct task_struct *t, int tls, u32 addr)
  118. {
  119. struct user_desc ud = {
  120. .base_addr = addr,
  121. .limit = 0xfffff,
  122. .seg_32bit = 1,
  123. .limit_in_pages = 1,
  124. .useable = 1,
  125. };
  126. struct desc_struct *desc = t->thread.tls_array;
  127. desc += tls;
  128. fill_ldt(desc, &ud);
  129. }
  130. static inline u32 read_32bit_tls(struct task_struct *t, int tls)
  131. {
  132. return get_desc_base(&t->thread.tls_array[tls]);
  133. }
  134. int copy_thread(unsigned long clone_flags, unsigned long sp,
  135. unsigned long arg, struct task_struct *p)
  136. {
  137. int err;
  138. struct pt_regs *childregs;
  139. struct task_struct *me = current;
  140. p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  141. childregs = task_pt_regs(p);
  142. p->thread.sp = (unsigned long) childregs;
  143. set_tsk_thread_flag(p, TIF_FORK);
  144. p->thread.io_bitmap_ptr = NULL;
  145. savesegment(gs, p->thread.gsindex);
  146. p->thread.gs = p->thread.gsindex ? 0 : me->thread.gs;
  147. savesegment(fs, p->thread.fsindex);
  148. p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
  149. savesegment(es, p->thread.es);
  150. savesegment(ds, p->thread.ds);
  151. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  152. if (unlikely(p->flags & PF_KTHREAD)) {
  153. /* kernel thread */
  154. memset(childregs, 0, sizeof(struct pt_regs));
  155. childregs->sp = (unsigned long)childregs;
  156. childregs->ss = __KERNEL_DS;
  157. childregs->bx = sp; /* function */
  158. childregs->bp = arg;
  159. childregs->orig_ax = -1;
  160. childregs->cs = __KERNEL_CS | get_kernel_rpl();
  161. childregs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED;
  162. return 0;
  163. }
  164. *childregs = *current_pt_regs();
  165. childregs->ax = 0;
  166. if (sp)
  167. childregs->sp = sp;
  168. err = -ENOMEM;
  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 (is_ia32_task())
  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. regs->ip = new_ip;
  210. regs->sp = new_sp;
  211. regs->cs = _cs;
  212. regs->ss = _ss;
  213. regs->flags = X86_EFLAGS_IF;
  214. force_iret();
  215. }
  216. void
  217. start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  218. {
  219. start_thread_common(regs, new_ip, new_sp,
  220. __USER_CS, __USER_DS, 0);
  221. }
  222. #ifdef CONFIG_IA32_EMULATION
  223. void start_thread_ia32(struct pt_regs *regs, u32 new_ip, u32 new_sp)
  224. {
  225. start_thread_common(regs, new_ip, new_sp,
  226. test_thread_flag(TIF_X32)
  227. ? __USER_CS : __USER32_CS,
  228. __USER_DS, __USER_DS);
  229. }
  230. #endif
  231. /*
  232. * switch_to(x,y) should switch tasks from x to y.
  233. *
  234. * This could still be optimized:
  235. * - fold all the options into a flag word and test it with a single test.
  236. * - could test fs/gs bitsliced
  237. *
  238. * Kprobes not supported here. Set the probe on schedule instead.
  239. * Function graph tracer not supported too.
  240. */
  241. __visible __notrace_funcgraph struct task_struct *
  242. __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  243. {
  244. struct thread_struct *prev = &prev_p->thread;
  245. struct thread_struct *next = &next_p->thread;
  246. int cpu = smp_processor_id();
  247. struct tss_struct *tss = &per_cpu(cpu_tss, cpu);
  248. unsigned fsindex, gsindex;
  249. fpu_switch_t fpu;
  250. fpu = switch_fpu_prepare(prev_p, next_p, cpu);
  251. /* We must save %fs and %gs before load_TLS() because
  252. * %fs and %gs may be cleared by load_TLS().
  253. *
  254. * (e.g. xen_load_tls())
  255. */
  256. savesegment(fs, fsindex);
  257. savesegment(gs, gsindex);
  258. /*
  259. * Load TLS before restoring any segments so that segment loads
  260. * reference the correct GDT entries.
  261. */
  262. load_TLS(next, cpu);
  263. /*
  264. * Leave lazy mode, flushing any hypercalls made here. This
  265. * must be done after loading TLS entries in the GDT but before
  266. * loading segments that might reference them, and and it must
  267. * be done before math_state_restore, so the TS bit is up to
  268. * date.
  269. */
  270. arch_end_context_switch(next_p);
  271. /* Switch DS and ES.
  272. *
  273. * Reading them only returns the selectors, but writing them (if
  274. * nonzero) loads the full descriptor from the GDT or LDT. The
  275. * LDT for next is loaded in switch_mm, and the GDT is loaded
  276. * above.
  277. *
  278. * We therefore need to write new values to the segment
  279. * registers on every context switch unless both the new and old
  280. * values are zero.
  281. *
  282. * Note that we don't need to do anything for CS and SS, as
  283. * those are saved and restored as part of pt_regs.
  284. */
  285. savesegment(es, prev->es);
  286. if (unlikely(next->es | prev->es))
  287. loadsegment(es, next->es);
  288. savesegment(ds, prev->ds);
  289. if (unlikely(next->ds | prev->ds))
  290. loadsegment(ds, next->ds);
  291. /*
  292. * Switch FS and GS.
  293. *
  294. * These are even more complicated than FS and GS: they have
  295. * 64-bit bases are that controlled by arch_prctl. Those bases
  296. * only differ from the values in the GDT or LDT if the selector
  297. * is 0.
  298. *
  299. * Loading the segment register resets the hidden base part of
  300. * the register to 0 or the value from the GDT / LDT. If the
  301. * next base address zero, writing 0 to the segment register is
  302. * much faster than using wrmsr to explicitly zero the base.
  303. *
  304. * The thread_struct.fs and thread_struct.gs values are 0
  305. * if the fs and gs bases respectively are not overridden
  306. * from the values implied by fsindex and gsindex. They
  307. * are nonzero, and store the nonzero base addresses, if
  308. * the bases are overridden.
  309. *
  310. * (fs != 0 && fsindex != 0) || (gs != 0 && gsindex != 0) should
  311. * be impossible.
  312. *
  313. * Therefore we need to reload the segment registers if either
  314. * the old or new selector is nonzero, and we need to override
  315. * the base address if next thread expects it to be overridden.
  316. *
  317. * This code is unnecessarily slow in the case where the old and
  318. * new indexes are zero and the new base is nonzero -- it will
  319. * unnecessarily write 0 to the selector before writing the new
  320. * base address.
  321. *
  322. * Note: This all depends on arch_prctl being the only way that
  323. * user code can override the segment base. Once wrfsbase and
  324. * wrgsbase are enabled, most of this code will need to change.
  325. */
  326. if (unlikely(fsindex | next->fsindex | prev->fs)) {
  327. loadsegment(fs, next->fsindex);
  328. /*
  329. * If user code wrote a nonzero value to FS, then it also
  330. * cleared the overridden base address.
  331. *
  332. * XXX: if user code wrote 0 to FS and cleared the base
  333. * address itself, we won't notice and we'll incorrectly
  334. * restore the prior base address next time we reschdule
  335. * the process.
  336. */
  337. if (fsindex)
  338. prev->fs = 0;
  339. }
  340. if (next->fs)
  341. wrmsrl(MSR_FS_BASE, next->fs);
  342. prev->fsindex = fsindex;
  343. if (unlikely(gsindex | next->gsindex | prev->gs)) {
  344. load_gs_index(next->gsindex);
  345. /* This works (and fails) the same way as fsindex above. */
  346. if (gsindex)
  347. prev->gs = 0;
  348. }
  349. if (next->gs)
  350. wrmsrl(MSR_KERNEL_GS_BASE, next->gs);
  351. prev->gsindex = gsindex;
  352. switch_fpu_finish(next_p, fpu);
  353. /*
  354. * Switch the PDA and FPU contexts.
  355. */
  356. this_cpu_write(current_task, next_p);
  357. /*
  358. * If it were not for PREEMPT_ACTIVE we could guarantee that the
  359. * preempt_count of all tasks was equal here and this would not be
  360. * needed.
  361. */
  362. task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
  363. this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
  364. /* Reload esp0 and ss1. This changes current_thread_info(). */
  365. load_sp0(tss, next);
  366. this_cpu_write(kernel_stack,
  367. (unsigned long)task_stack_page(next_p) + THREAD_SIZE);
  368. /*
  369. * Now maybe reload the debug registers and handle I/O bitmaps
  370. */
  371. if (unlikely(task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT ||
  372. task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV))
  373. __switch_to_xtra(prev_p, next_p, tss);
  374. if (static_cpu_has_bug(X86_BUG_SYSRET_SS_ATTRS)) {
  375. /*
  376. * AMD CPUs have a misfeature: SYSRET sets the SS selector but
  377. * does not update the cached descriptor. As a result, if we
  378. * do SYSRET while SS is NULL, we'll end up in user mode with
  379. * SS apparently equal to __USER_DS but actually unusable.
  380. *
  381. * The straightforward workaround would be to fix it up just
  382. * before SYSRET, but that would slow down the system call
  383. * fast paths. Instead, we ensure that SS is never NULL in
  384. * system call context. We do this by replacing NULL SS
  385. * selectors at every context switch. SYSCALL sets up a valid
  386. * SS, so the only way to get NULL is to re-enter the kernel
  387. * from CPL 3 through an interrupt. Since that can't happen
  388. * in the same task as a running syscall, we are guaranteed to
  389. * context switch between every interrupt vector entry and a
  390. * subsequent SYSRET.
  391. *
  392. * We read SS first because SS reads are much faster than
  393. * writes. Out of caution, we force SS to __KERNEL_DS even if
  394. * it previously had a different non-NULL value.
  395. */
  396. unsigned short ss_sel;
  397. savesegment(ss, ss_sel);
  398. if (ss_sel != __KERNEL_DS)
  399. loadsegment(ss, __KERNEL_DS);
  400. }
  401. return prev_p;
  402. }
  403. void set_personality_64bit(void)
  404. {
  405. /* inherit personality from parent */
  406. /* Make sure to be in 64bit mode */
  407. clear_thread_flag(TIF_IA32);
  408. clear_thread_flag(TIF_ADDR32);
  409. clear_thread_flag(TIF_X32);
  410. /* Ensure the corresponding mm is not marked. */
  411. if (current->mm)
  412. current->mm->context.ia32_compat = 0;
  413. /* TBD: overwrites user setup. Should have two bits.
  414. But 64bit processes have always behaved this way,
  415. so it's not too bad. The main problem is just that
  416. 32bit childs are affected again. */
  417. current->personality &= ~READ_IMPLIES_EXEC;
  418. }
  419. void set_personality_ia32(bool x32)
  420. {
  421. /* inherit personality from parent */
  422. /* Make sure to be in 32bit mode */
  423. set_thread_flag(TIF_ADDR32);
  424. /* Mark the associated mm as containing 32-bit tasks. */
  425. if (x32) {
  426. clear_thread_flag(TIF_IA32);
  427. set_thread_flag(TIF_X32);
  428. if (current->mm)
  429. current->mm->context.ia32_compat = TIF_X32;
  430. current->personality &= ~READ_IMPLIES_EXEC;
  431. /* is_compat_task() uses the presence of the x32
  432. syscall bit flag to determine compat status */
  433. current_thread_info()->status &= ~TS_COMPAT;
  434. } else {
  435. set_thread_flag(TIF_IA32);
  436. clear_thread_flag(TIF_X32);
  437. if (current->mm)
  438. current->mm->context.ia32_compat = TIF_IA32;
  439. current->personality |= force_personality32;
  440. /* Prepare the first "return" to user space */
  441. current_thread_info()->status |= TS_COMPAT;
  442. }
  443. }
  444. EXPORT_SYMBOL_GPL(set_personality_ia32);
  445. unsigned long get_wchan(struct task_struct *p)
  446. {
  447. unsigned long stack;
  448. u64 fp, ip;
  449. int count = 0;
  450. if (!p || p == current || p->state == TASK_RUNNING)
  451. return 0;
  452. stack = (unsigned long)task_stack_page(p);
  453. if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
  454. return 0;
  455. fp = *(u64 *)(p->thread.sp);
  456. do {
  457. if (fp < (unsigned long)stack ||
  458. fp >= (unsigned long)stack+THREAD_SIZE)
  459. return 0;
  460. ip = *(u64 *)(fp+8);
  461. if (!in_sched_functions(ip))
  462. return ip;
  463. fp = *(u64 *)fp;
  464. } while (count++ < 16);
  465. return 0;
  466. }
  467. long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
  468. {
  469. int ret = 0;
  470. int doit = task == current;
  471. int cpu;
  472. switch (code) {
  473. case ARCH_SET_GS:
  474. if (addr >= TASK_SIZE_OF(task))
  475. return -EPERM;
  476. cpu = get_cpu();
  477. /* handle small bases via the GDT because that's faster to
  478. switch. */
  479. if (addr <= 0xffffffff) {
  480. set_32bit_tls(task, GS_TLS, addr);
  481. if (doit) {
  482. load_TLS(&task->thread, cpu);
  483. load_gs_index(GS_TLS_SEL);
  484. }
  485. task->thread.gsindex = GS_TLS_SEL;
  486. task->thread.gs = 0;
  487. } else {
  488. task->thread.gsindex = 0;
  489. task->thread.gs = addr;
  490. if (doit) {
  491. load_gs_index(0);
  492. ret = wrmsrl_safe(MSR_KERNEL_GS_BASE, addr);
  493. }
  494. }
  495. put_cpu();
  496. break;
  497. case ARCH_SET_FS:
  498. /* Not strictly needed for fs, but do it for symmetry
  499. with gs */
  500. if (addr >= TASK_SIZE_OF(task))
  501. return -EPERM;
  502. cpu = get_cpu();
  503. /* handle small bases via the GDT because that's faster to
  504. switch. */
  505. if (addr <= 0xffffffff) {
  506. set_32bit_tls(task, FS_TLS, addr);
  507. if (doit) {
  508. load_TLS(&task->thread, cpu);
  509. loadsegment(fs, FS_TLS_SEL);
  510. }
  511. task->thread.fsindex = FS_TLS_SEL;
  512. task->thread.fs = 0;
  513. } else {
  514. task->thread.fsindex = 0;
  515. task->thread.fs = addr;
  516. if (doit) {
  517. /* set the selector to 0 to not confuse
  518. __switch_to */
  519. loadsegment(fs, 0);
  520. ret = wrmsrl_safe(MSR_FS_BASE, addr);
  521. }
  522. }
  523. put_cpu();
  524. break;
  525. case ARCH_GET_FS: {
  526. unsigned long base;
  527. if (task->thread.fsindex == FS_TLS_SEL)
  528. base = read_32bit_tls(task, FS_TLS);
  529. else if (doit)
  530. rdmsrl(MSR_FS_BASE, base);
  531. else
  532. base = task->thread.fs;
  533. ret = put_user(base, (unsigned long __user *)addr);
  534. break;
  535. }
  536. case ARCH_GET_GS: {
  537. unsigned long base;
  538. unsigned gsindex;
  539. if (task->thread.gsindex == GS_TLS_SEL)
  540. base = read_32bit_tls(task, GS_TLS);
  541. else if (doit) {
  542. savesegment(gs, gsindex);
  543. if (gsindex)
  544. rdmsrl(MSR_KERNEL_GS_BASE, base);
  545. else
  546. base = task->thread.gs;
  547. } else
  548. base = task->thread.gs;
  549. ret = put_user(base, (unsigned long __user *)addr);
  550. break;
  551. }
  552. default:
  553. ret = -EINVAL;
  554. break;
  555. }
  556. return ret;
  557. }
  558. long sys_arch_prctl(int code, unsigned long addr)
  559. {
  560. return do_arch_prctl(current, code, addr);
  561. }
  562. unsigned long KSTK_ESP(struct task_struct *task)
  563. {
  564. return task_pt_regs(task)->sp;
  565. }