process_32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. *
  4. * Pentium III FXSR, SSE support
  5. * Gareth Hughes <gareth@valinux.com>, May 2000
  6. */
  7. /*
  8. * This file handles the architecture-dependent parts of process handling..
  9. */
  10. #include <stdarg.h>
  11. #include <linux/stackprotector.h>
  12. #include <linux/cpu.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/fs.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/elfcore.h>
  19. #include <linux/smp.h>
  20. #include <linux/stddef.h>
  21. #include <linux/slab.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/user.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/utsname.h>
  26. #include <linux/delay.h>
  27. #include <linux/reboot.h>
  28. #include <linux/init.h>
  29. #include <linux/mc146818rtc.h>
  30. #include <linux/module.h>
  31. #include <linux/kallsyms.h>
  32. #include <linux/ptrace.h>
  33. #include <linux/random.h>
  34. #include <linux/personality.h>
  35. #include <linux/tick.h>
  36. #include <linux/percpu.h>
  37. #include <linux/prctl.h>
  38. #include <linux/dmi.h>
  39. #include <linux/ftrace.h>
  40. #include <linux/uaccess.h>
  41. #include <linux/io.h>
  42. #include <linux/kdebug.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/system.h>
  45. #include <asm/ldt.h>
  46. #include <asm/processor.h>
  47. #include <asm/i387.h>
  48. #include <asm/desc.h>
  49. #ifdef CONFIG_MATH_EMULATION
  50. #include <asm/math_emu.h>
  51. #endif
  52. #include <linux/err.h>
  53. #include <asm/tlbflush.h>
  54. #include <asm/cpu.h>
  55. #include <asm/idle.h>
  56. #include <asm/syscalls.h>
  57. #include <asm/ds.h>
  58. asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
  59. DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
  60. EXPORT_PER_CPU_SYMBOL(current_task);
  61. /*
  62. * Return saved PC of a blocked thread.
  63. */
  64. unsigned long thread_saved_pc(struct task_struct *tsk)
  65. {
  66. return ((unsigned long *)tsk->thread.sp)[3];
  67. }
  68. #ifndef CONFIG_SMP
  69. static inline void play_dead(void)
  70. {
  71. BUG();
  72. }
  73. #endif
  74. /*
  75. * The idle thread. There's no useful work to be
  76. * done, so just try to conserve power and have a
  77. * low exit latency (ie sit in a loop waiting for
  78. * somebody to say that they'd like to reschedule)
  79. */
  80. void cpu_idle(void)
  81. {
  82. int cpu = smp_processor_id();
  83. /*
  84. * If we're the non-boot CPU, nothing set the stack canary up
  85. * for us. CPU0 already has it initialized but no harm in
  86. * doing it again. This is a good place for updating it, as
  87. * we wont ever return from this function (so the invalid
  88. * canaries already on the stack wont ever trigger).
  89. */
  90. boot_init_stack_canary();
  91. current_thread_info()->status |= TS_POLLING;
  92. /* endless idle loop with no priority at all */
  93. while (1) {
  94. tick_nohz_stop_sched_tick(1);
  95. while (!need_resched()) {
  96. check_pgt_cache();
  97. rmb();
  98. if (cpu_is_offline(cpu))
  99. play_dead();
  100. local_irq_disable();
  101. /* Don't trace irqs off for idle */
  102. stop_critical_timings();
  103. pm_idle();
  104. start_critical_timings();
  105. }
  106. tick_nohz_restart_sched_tick();
  107. preempt_enable_no_resched();
  108. schedule();
  109. preempt_disable();
  110. }
  111. }
  112. void __show_regs(struct pt_regs *regs, int all)
  113. {
  114. unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
  115. unsigned long d0, d1, d2, d3, d6, d7;
  116. unsigned long sp;
  117. unsigned short ss, gs;
  118. const char *board;
  119. if (user_mode_vm(regs)) {
  120. sp = regs->sp;
  121. ss = regs->ss & 0xffff;
  122. gs = get_user_gs(regs);
  123. } else {
  124. sp = (unsigned long) (&regs->sp);
  125. savesegment(ss, ss);
  126. savesegment(gs, gs);
  127. }
  128. printk("\n");
  129. board = dmi_get_system_info(DMI_PRODUCT_NAME);
  130. if (!board)
  131. board = "";
  132. printk("Pid: %d, comm: %s %s (%s %.*s) %s\n",
  133. task_pid_nr(current), current->comm,
  134. print_tainted(), init_utsname()->release,
  135. (int)strcspn(init_utsname()->version, " "),
  136. init_utsname()->version, board);
  137. printk("EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
  138. (u16)regs->cs, regs->ip, regs->flags,
  139. smp_processor_id());
  140. print_symbol("EIP is at %s\n", regs->ip);
  141. printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
  142. regs->ax, regs->bx, regs->cx, regs->dx);
  143. printk("ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
  144. regs->si, regs->di, regs->bp, sp);
  145. printk(" DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x\n",
  146. (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss);
  147. if (!all)
  148. return;
  149. cr0 = read_cr0();
  150. cr2 = read_cr2();
  151. cr3 = read_cr3();
  152. cr4 = read_cr4_safe();
  153. printk("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n",
  154. cr0, cr2, cr3, cr4);
  155. get_debugreg(d0, 0);
  156. get_debugreg(d1, 1);
  157. get_debugreg(d2, 2);
  158. get_debugreg(d3, 3);
  159. printk("DR0: %08lx DR1: %08lx DR2: %08lx DR3: %08lx\n",
  160. d0, d1, d2, d3);
  161. get_debugreg(d6, 6);
  162. get_debugreg(d7, 7);
  163. printk("DR6: %08lx DR7: %08lx\n",
  164. d6, d7);
  165. }
  166. void show_regs(struct pt_regs *regs)
  167. {
  168. __show_regs(regs, 1);
  169. show_trace(NULL, regs, &regs->sp, regs->bp);
  170. }
  171. /*
  172. * This gets run with %bx containing the
  173. * function to call, and %dx containing
  174. * the "args".
  175. */
  176. extern void kernel_thread_helper(void);
  177. /*
  178. * Create a kernel thread
  179. */
  180. int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
  181. {
  182. struct pt_regs regs;
  183. memset(&regs, 0, sizeof(regs));
  184. regs.bx = (unsigned long) fn;
  185. regs.dx = (unsigned long) arg;
  186. regs.ds = __USER_DS;
  187. regs.es = __USER_DS;
  188. regs.fs = __KERNEL_PERCPU;
  189. regs.gs = __KERNEL_STACK_CANARY;
  190. regs.orig_ax = -1;
  191. regs.ip = (unsigned long) kernel_thread_helper;
  192. regs.cs = __KERNEL_CS | get_kernel_rpl();
  193. regs.flags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;
  194. /* Ok, create the new process.. */
  195. return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
  196. }
  197. EXPORT_SYMBOL(kernel_thread);
  198. /*
  199. * Free current thread data structures etc..
  200. */
  201. void exit_thread(void)
  202. {
  203. /* The process may have allocated an io port bitmap... nuke it. */
  204. if (unlikely(test_thread_flag(TIF_IO_BITMAP))) {
  205. struct task_struct *tsk = current;
  206. struct thread_struct *t = &tsk->thread;
  207. int cpu = get_cpu();
  208. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  209. kfree(t->io_bitmap_ptr);
  210. t->io_bitmap_ptr = NULL;
  211. clear_thread_flag(TIF_IO_BITMAP);
  212. /*
  213. * Careful, clear this in the TSS too:
  214. */
  215. memset(tss->io_bitmap, 0xff, t->io_bitmap_max);
  216. t->io_bitmap_max = 0;
  217. put_cpu();
  218. }
  219. ds_exit_thread(current);
  220. }
  221. void flush_thread(void)
  222. {
  223. struct task_struct *tsk = current;
  224. tsk->thread.debugreg0 = 0;
  225. tsk->thread.debugreg1 = 0;
  226. tsk->thread.debugreg2 = 0;
  227. tsk->thread.debugreg3 = 0;
  228. tsk->thread.debugreg6 = 0;
  229. tsk->thread.debugreg7 = 0;
  230. memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
  231. clear_tsk_thread_flag(tsk, TIF_DEBUG);
  232. /*
  233. * Forget coprocessor state..
  234. */
  235. tsk->fpu_counter = 0;
  236. clear_fpu(tsk);
  237. clear_used_math();
  238. }
  239. void release_thread(struct task_struct *dead_task)
  240. {
  241. BUG_ON(dead_task->mm);
  242. release_vm86_irqs(dead_task);
  243. }
  244. /*
  245. * This gets called before we allocate a new thread and copy
  246. * the current task into it.
  247. */
  248. void prepare_to_copy(struct task_struct *tsk)
  249. {
  250. unlazy_fpu(tsk);
  251. }
  252. int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
  253. unsigned long unused,
  254. struct task_struct *p, struct pt_regs *regs)
  255. {
  256. struct pt_regs *childregs;
  257. struct task_struct *tsk;
  258. int err;
  259. childregs = task_pt_regs(p);
  260. *childregs = *regs;
  261. childregs->ax = 0;
  262. childregs->sp = sp;
  263. p->thread.sp = (unsigned long) childregs;
  264. p->thread.sp0 = (unsigned long) (childregs+1);
  265. p->thread.ip = (unsigned long) ret_from_fork;
  266. task_user_gs(p) = get_user_gs(regs);
  267. tsk = current;
  268. if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) {
  269. p->thread.io_bitmap_ptr = kmemdup(tsk->thread.io_bitmap_ptr,
  270. IO_BITMAP_BYTES, GFP_KERNEL);
  271. if (!p->thread.io_bitmap_ptr) {
  272. p->thread.io_bitmap_max = 0;
  273. return -ENOMEM;
  274. }
  275. set_tsk_thread_flag(p, TIF_IO_BITMAP);
  276. }
  277. err = 0;
  278. /*
  279. * Set a new TLS for the child thread?
  280. */
  281. if (clone_flags & CLONE_SETTLS)
  282. err = do_set_thread_area(p, -1,
  283. (struct user_desc __user *)childregs->si, 0);
  284. if (err && p->thread.io_bitmap_ptr) {
  285. kfree(p->thread.io_bitmap_ptr);
  286. p->thread.io_bitmap_max = 0;
  287. }
  288. ds_copy_thread(p, current);
  289. clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR);
  290. p->thread.debugctlmsr = 0;
  291. return err;
  292. }
  293. void
  294. start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  295. {
  296. set_user_gs(regs, 0);
  297. regs->fs = 0;
  298. set_fs(USER_DS);
  299. regs->ds = __USER_DS;
  300. regs->es = __USER_DS;
  301. regs->ss = __USER_DS;
  302. regs->cs = __USER_CS;
  303. regs->ip = new_ip;
  304. regs->sp = new_sp;
  305. /*
  306. * Free the old FP and other extended state
  307. */
  308. free_thread_xstate(current);
  309. }
  310. EXPORT_SYMBOL_GPL(start_thread);
  311. static void hard_disable_TSC(void)
  312. {
  313. write_cr4(read_cr4() | X86_CR4_TSD);
  314. }
  315. void disable_TSC(void)
  316. {
  317. preempt_disable();
  318. if (!test_and_set_thread_flag(TIF_NOTSC))
  319. /*
  320. * Must flip the CPU state synchronously with
  321. * TIF_NOTSC in the current running context.
  322. */
  323. hard_disable_TSC();
  324. preempt_enable();
  325. }
  326. static void hard_enable_TSC(void)
  327. {
  328. write_cr4(read_cr4() & ~X86_CR4_TSD);
  329. }
  330. static void enable_TSC(void)
  331. {
  332. preempt_disable();
  333. if (test_and_clear_thread_flag(TIF_NOTSC))
  334. /*
  335. * Must flip the CPU state synchronously with
  336. * TIF_NOTSC in the current running context.
  337. */
  338. hard_enable_TSC();
  339. preempt_enable();
  340. }
  341. int get_tsc_mode(unsigned long adr)
  342. {
  343. unsigned int val;
  344. if (test_thread_flag(TIF_NOTSC))
  345. val = PR_TSC_SIGSEGV;
  346. else
  347. val = PR_TSC_ENABLE;
  348. return put_user(val, (unsigned int __user *)adr);
  349. }
  350. int set_tsc_mode(unsigned int val)
  351. {
  352. if (val == PR_TSC_SIGSEGV)
  353. disable_TSC();
  354. else if (val == PR_TSC_ENABLE)
  355. enable_TSC();
  356. else
  357. return -EINVAL;
  358. return 0;
  359. }
  360. static noinline void
  361. __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
  362. struct tss_struct *tss)
  363. {
  364. struct thread_struct *prev, *next;
  365. prev = &prev_p->thread;
  366. next = &next_p->thread;
  367. if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) ||
  368. test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR))
  369. ds_switch_to(prev_p, next_p);
  370. else if (next->debugctlmsr != prev->debugctlmsr)
  371. update_debugctlmsr(next->debugctlmsr);
  372. if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
  373. set_debugreg(next->debugreg0, 0);
  374. set_debugreg(next->debugreg1, 1);
  375. set_debugreg(next->debugreg2, 2);
  376. set_debugreg(next->debugreg3, 3);
  377. /* no 4 and 5 */
  378. set_debugreg(next->debugreg6, 6);
  379. set_debugreg(next->debugreg7, 7);
  380. }
  381. if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^
  382. test_tsk_thread_flag(next_p, TIF_NOTSC)) {
  383. /* prev and next are different */
  384. if (test_tsk_thread_flag(next_p, TIF_NOTSC))
  385. hard_disable_TSC();
  386. else
  387. hard_enable_TSC();
  388. }
  389. if (test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) {
  390. /*
  391. * Copy the relevant range of the IO bitmap.
  392. * Normally this is 128 bytes or less:
  393. */
  394. memcpy(tss->io_bitmap, next->io_bitmap_ptr,
  395. max(prev->io_bitmap_max, next->io_bitmap_max));
  396. } else if (test_tsk_thread_flag(prev_p, TIF_IO_BITMAP)) {
  397. /*
  398. * Clear any possible leftover bits:
  399. */
  400. memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
  401. }
  402. }
  403. /*
  404. * switch_to(x,yn) should switch tasks from x to y.
  405. *
  406. * We fsave/fwait so that an exception goes off at the right time
  407. * (as a call from the fsave or fwait in effect) rather than to
  408. * the wrong process. Lazy FP saving no longer makes any sense
  409. * with modern CPU's, and this simplifies a lot of things (SMP
  410. * and UP become the same).
  411. *
  412. * NOTE! We used to use the x86 hardware context switching. The
  413. * reason for not using it any more becomes apparent when you
  414. * try to recover gracefully from saved state that is no longer
  415. * valid (stale segment register values in particular). With the
  416. * hardware task-switch, there is no way to fix up bad state in
  417. * a reasonable manner.
  418. *
  419. * The fact that Intel documents the hardware task-switching to
  420. * be slow is a fairly red herring - this code is not noticeably
  421. * faster. However, there _is_ some room for improvement here,
  422. * so the performance issues may eventually be a valid point.
  423. * More important, however, is the fact that this allows us much
  424. * more flexibility.
  425. *
  426. * The return value (in %ax) will be the "prev" task after
  427. * the task-switch, and shows up in ret_from_fork in entry.S,
  428. * for example.
  429. */
  430. __notrace_funcgraph struct task_struct *
  431. __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  432. {
  433. struct thread_struct *prev = &prev_p->thread,
  434. *next = &next_p->thread;
  435. int cpu = smp_processor_id();
  436. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  437. /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
  438. __unlazy_fpu(prev_p);
  439. /* we're going to use this soon, after a few expensive things */
  440. if (next_p->fpu_counter > 5)
  441. prefetch(next->xstate);
  442. /*
  443. * Reload esp0.
  444. */
  445. load_sp0(tss, next);
  446. /*
  447. * Save away %gs. No need to save %fs, as it was saved on the
  448. * stack on entry. No need to save %es and %ds, as those are
  449. * always kernel segments while inside the kernel. Doing this
  450. * before setting the new TLS descriptors avoids the situation
  451. * where we temporarily have non-reloadable segments in %fs
  452. * and %gs. This could be an issue if the NMI handler ever
  453. * used %fs or %gs (it does not today), or if the kernel is
  454. * running inside of a hypervisor layer.
  455. */
  456. lazy_save_gs(prev->gs);
  457. /*
  458. * Load the per-thread Thread-Local Storage descriptor.
  459. */
  460. load_TLS(next, cpu);
  461. /*
  462. * Restore IOPL if needed. In normal use, the flags restore
  463. * in the switch assembly will handle this. But if the kernel
  464. * is running virtualized at a non-zero CPL, the popf will
  465. * not restore flags, so it must be done in a separate step.
  466. */
  467. if (get_kernel_rpl() && unlikely(prev->iopl != next->iopl))
  468. set_iopl_mask(next->iopl);
  469. /*
  470. * Now maybe handle debug registers and/or IO bitmaps
  471. */
  472. if (unlikely(task_thread_info(prev_p)->flags & _TIF_WORK_CTXSW_PREV ||
  473. task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT))
  474. __switch_to_xtra(prev_p, next_p, tss);
  475. /*
  476. * Leave lazy mode, flushing any hypercalls made here.
  477. * This must be done before restoring TLS segments so
  478. * the GDT and LDT are properly updated, and must be
  479. * done before math_state_restore, so the TS bit is up
  480. * to date.
  481. */
  482. arch_leave_lazy_cpu_mode();
  483. /* If the task has used fpu the last 5 timeslices, just do a full
  484. * restore of the math state immediately to avoid the trap; the
  485. * chances of needing FPU soon are obviously high now
  486. *
  487. * tsk_used_math() checks prevent calling math_state_restore(),
  488. * which can sleep in the case of !tsk_used_math()
  489. */
  490. if (tsk_used_math(next_p) && next_p->fpu_counter > 5)
  491. math_state_restore();
  492. /*
  493. * Restore %gs if needed (which is common)
  494. */
  495. if (prev->gs | next->gs)
  496. lazy_load_gs(next->gs);
  497. percpu_write(current_task, next_p);
  498. return prev_p;
  499. }
  500. int sys_fork(struct pt_regs *regs)
  501. {
  502. return do_fork(SIGCHLD, regs->sp, regs, 0, NULL, NULL);
  503. }
  504. int sys_clone(struct pt_regs *regs)
  505. {
  506. unsigned long clone_flags;
  507. unsigned long newsp;
  508. int __user *parent_tidptr, *child_tidptr;
  509. clone_flags = regs->bx;
  510. newsp = regs->cx;
  511. parent_tidptr = (int __user *)regs->dx;
  512. child_tidptr = (int __user *)regs->di;
  513. if (!newsp)
  514. newsp = regs->sp;
  515. return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
  516. }
  517. /*
  518. * This is trivial, and on the face of it looks like it
  519. * could equally well be done in user mode.
  520. *
  521. * Not so, for quite unobvious reasons - register pressure.
  522. * In user mode vfork() cannot have a stack frame, and if
  523. * done by calling the "clone()" system call directly, you
  524. * do not have enough call-clobbered registers to hold all
  525. * the information you need.
  526. */
  527. int sys_vfork(struct pt_regs *regs)
  528. {
  529. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->sp, regs, 0, NULL, NULL);
  530. }
  531. /*
  532. * sys_execve() executes a new program.
  533. */
  534. int sys_execve(struct pt_regs *regs)
  535. {
  536. int error;
  537. char *filename;
  538. filename = getname((char __user *) regs->bx);
  539. error = PTR_ERR(filename);
  540. if (IS_ERR(filename))
  541. goto out;
  542. error = do_execve(filename,
  543. (char __user * __user *) regs->cx,
  544. (char __user * __user *) regs->dx,
  545. regs);
  546. if (error == 0) {
  547. /* Make sure we don't return using sysenter.. */
  548. set_thread_flag(TIF_IRET);
  549. }
  550. putname(filename);
  551. out:
  552. return error;
  553. }
  554. #define top_esp (THREAD_SIZE - sizeof(unsigned long))
  555. #define top_ebp (THREAD_SIZE - 2*sizeof(unsigned long))
  556. unsigned long get_wchan(struct task_struct *p)
  557. {
  558. unsigned long bp, sp, ip;
  559. unsigned long stack_page;
  560. int count = 0;
  561. if (!p || p == current || p->state == TASK_RUNNING)
  562. return 0;
  563. stack_page = (unsigned long)task_stack_page(p);
  564. sp = p->thread.sp;
  565. if (!stack_page || sp < stack_page || sp > top_esp+stack_page)
  566. return 0;
  567. /* include/asm-i386/system.h:switch_to() pushes bp last. */
  568. bp = *(unsigned long *) sp;
  569. do {
  570. if (bp < stack_page || bp > top_ebp+stack_page)
  571. return 0;
  572. ip = *(unsigned long *) (bp+4);
  573. if (!in_sched_functions(ip))
  574. return ip;
  575. bp = *(unsigned long *) bp;
  576. } while (count++ < 16);
  577. return 0;
  578. }
  579. unsigned long arch_align_stack(unsigned long sp)
  580. {
  581. if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  582. sp -= get_random_int() % 8192;
  583. return sp & ~0xf;
  584. }
  585. unsigned long arch_randomize_brk(struct mm_struct *mm)
  586. {
  587. unsigned long range_end = mm->brk + 0x02000000;
  588. return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
  589. }