process_64.c 17 KB

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