process_64.c 16 KB

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