process_64.c 16 KB

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