blob: 7c037fa9c5b8d6bfbfbe37f9d0f7da2b8a35de44 [file] [log] [blame]
Jeff Dike995473a2006-09-27 01:50:40 -07001/*
Jeff Dikeba180fd2007-10-16 01:27:00 -07002 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
5 */
6
Jeff Dikeba180fd2007-10-16 01:27:00 -07007#include "linux/stddef.h"
8#include "linux/err.h"
9#include "linux/hardirq.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include "linux/mm.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070011#include "linux/personality.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "linux/proc_fs.h"
13#include "linux/ptrace.h"
14#include "linux/random.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070015#include "linux/sched.h"
16#include "linux/threads.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "asm/pgtable.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "asm/uaccess.h"
Jeff Dike4ff83ce2007-05-06 14:51:08 -070019#include "as-layout.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070020#include "kern_util.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "os.h"
Jeff Dike77bf4402007-10-16 01:26:58 -070022#include "skas.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070023#include "tlb.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Jeff Dikeba180fd2007-10-16 01:27:00 -070025/*
26 * This is a per-cpu array. A processor only modifies its entry and it only
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * cares about its entry, so it's OK if another processor is modifying its
28 * entry.
29 */
30struct cpu_task cpu_tasks[NR_CPUS] = { [0 ... NR_CPUS - 1] = { -1, NULL } };
31
Jeff Dike6e21aec2007-05-06 14:51:21 -070032static inline int external_pid(struct task_struct *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Jeff Dike77bf4402007-10-16 01:26:58 -070034 /* FIXME: Need to look up userspace_pid by cpu */
Jeff Dikeba180fd2007-10-16 01:27:00 -070035 return userspace_pid[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
38int pid_to_processor_id(int pid)
39{
40 int i;
41
Jeff Dikeba180fd2007-10-16 01:27:00 -070042 for(i = 0; i < ncpus; i++) {
43 if (cpu_tasks[i].pid == pid)
Jeff Dike6e21aec2007-05-06 14:51:21 -070044 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 }
Jeff Dike6e21aec2007-05-06 14:51:21 -070046 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
49void free_stack(unsigned long stack, int order)
50{
51 free_pages(stack, order);
52}
53
54unsigned long alloc_stack(int order, int atomic)
55{
56 unsigned long page;
Al Viro53f9fc92005-10-21 03:22:24 -040057 gfp_t flags = GFP_KERNEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Paolo 'Blaisorblade' Giarrusso46db4a42005-09-22 21:44:20 -070059 if (atomic)
60 flags = GFP_ATOMIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 page = __get_free_pages(flags, order);
Jeff Dike5c8aace2007-10-16 01:26:46 -070062 if (page == 0)
Jeff Dike6e21aec2007-05-06 14:51:21 -070063 return 0;
Jeff Dike5c8aace2007-10-16 01:26:46 -070064
Jeff Dike6e21aec2007-05-06 14:51:21 -070065 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
69{
70 int pid;
71
72 current->thread.request.u.thread.proc = fn;
73 current->thread.request.u.thread.arg = arg;
Jeff Dikee0877f02005-06-25 14:55:21 -070074 pid = do_fork(CLONE_VM | CLONE_UNTRACED | flags, 0,
75 &current->thread.regs, 0, NULL, NULL);
Jeff Dike6e21aec2007-05-06 14:51:21 -070076 return pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Jeff Dike6e21aec2007-05-06 14:51:21 -070079static inline void set_current(struct task_struct *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Al Viroca9bc0b2006-01-12 01:05:48 -080081 cpu_tasks[task_thread_info(task)->cpu] = ((struct cpu_task)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 { external_pid(task), task });
83}
84
Jeff Dike77bf4402007-10-16 01:26:58 -070085extern void arch_switch_to(struct task_struct *from, struct task_struct *to);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087void *_switch_to(void *prev, void *next, void *last)
88{
Jeff Dike995473a2006-09-27 01:50:40 -070089 struct task_struct *from = prev;
90 struct task_struct *to= next;
Jeff Dikef6e34c62005-09-16 19:27:43 -070091
Jeff Dike995473a2006-09-27 01:50:40 -070092 to->thread.prev_sched = from;
93 set_current(to);
Jeff Dikef6e34c62005-09-16 19:27:43 -070094
Jeff Dike3eddddc2005-09-16 19:27:46 -070095 do {
Jeff Dike6aa802c2007-10-16 01:26:56 -070096 current->thread.saved_task = NULL;
Jeff Dike77bf4402007-10-16 01:26:58 -070097
98 /* XXX need to check runqueues[cpu].idle */
Jeff Dikeba180fd2007-10-16 01:27:00 -070099 if (current->pid == 0)
Jeff Dike77bf4402007-10-16 01:26:58 -0700100 switch_timers(0);
101
102 switch_threads(&from->thread.switch_buf,
103 &to->thread.switch_buf);
104
105 arch_switch_to(current->thread.prev_sched, current);
106
Jeff Dikeba180fd2007-10-16 01:27:00 -0700107 if (current->pid == 0)
Jeff Dike77bf4402007-10-16 01:26:58 -0700108 switch_timers(1);
109
Jeff Dikeba180fd2007-10-16 01:27:00 -0700110 if (current->thread.saved_task)
Jeff Dike3eddddc2005-09-16 19:27:46 -0700111 show_regs(&(current->thread.regs));
112 next= current->thread.saved_task;
113 prev= current;
114 } while(current->thread.saved_task);
Jeff Dikef6e34c62005-09-16 19:27:43 -0700115
Jeff Dike6e21aec2007-05-06 14:51:21 -0700116 return current->thread.prev_sched;
Jeff Dikef6e34c62005-09-16 19:27:43 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120void interrupt_end(void)
121{
Jeff Dikeba180fd2007-10-16 01:27:00 -0700122 if (need_resched())
Jeff Dike6e21aec2007-05-06 14:51:21 -0700123 schedule();
Jeff Dikeba180fd2007-10-16 01:27:00 -0700124 if (test_tsk_thread_flag(current, TIF_SIGPENDING))
Jeff Dike6e21aec2007-05-06 14:51:21 -0700125 do_signal();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128void exit_thread(void)
129{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
Jeff Dike995473a2006-09-27 01:50:40 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132void *get_current(void)
133{
Jeff Dike6e21aec2007-05-06 14:51:21 -0700134 return current;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
Jeff Dike77bf4402007-10-16 01:26:58 -0700137extern void schedule_tail(struct task_struct *prev);
138
Jeff Dikeba180fd2007-10-16 01:27:00 -0700139/*
140 * This is called magically, by its address being stuffed in a jmp_buf
Jeff Dike77bf4402007-10-16 01:26:58 -0700141 * and being longjmp-d to.
142 */
143void new_thread_handler(void)
144{
145 int (*fn)(void *), n;
146 void *arg;
147
Jeff Dikeba180fd2007-10-16 01:27:00 -0700148 if (current->thread.prev_sched != NULL)
Jeff Dike77bf4402007-10-16 01:26:58 -0700149 schedule_tail(current->thread.prev_sched);
150 current->thread.prev_sched = NULL;
151
152 fn = current->thread.request.u.thread.proc;
153 arg = current->thread.request.u.thread.arg;
154
Jeff Dikeba180fd2007-10-16 01:27:00 -0700155 /*
156 * The return value is 1 if the kernel thread execs a process,
Jeff Dike77bf4402007-10-16 01:26:58 -0700157 * 0 if it just exits
158 */
159 n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
Jeff Dikeba180fd2007-10-16 01:27:00 -0700160 if (n == 1) {
Jeff Dike77bf4402007-10-16 01:26:58 -0700161 /* Handle any immediate reschedules or signals */
162 interrupt_end();
163 userspace(&current->thread.regs.regs);
164 }
165 else do_exit(0);
166}
167
168/* Called magically, see new_thread_handler above */
169void fork_handler(void)
170{
171 force_flush_all();
Jeff Dikeba180fd2007-10-16 01:27:00 -0700172 if (current->thread.prev_sched == NULL)
Jeff Dike77bf4402007-10-16 01:26:58 -0700173 panic("blech");
174
175 schedule_tail(current->thread.prev_sched);
176
Jeff Dikeba180fd2007-10-16 01:27:00 -0700177 /*
178 * XXX: if interrupt_end() calls schedule, this call to
Jeff Dike77bf4402007-10-16 01:26:58 -0700179 * arch_switch_to isn't needed. We could want to apply this to
Jeff Dikeba180fd2007-10-16 01:27:00 -0700180 * improve performance. -bb
181 */
Jeff Dike77bf4402007-10-16 01:26:58 -0700182 arch_switch_to(current->thread.prev_sched, current);
183
184 current->thread.prev_sched = NULL;
185
186 /* Handle any immediate reschedules or signals */
187 interrupt_end();
188
189 userspace(&current->thread.regs.regs);
190}
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
Jeff Dike995473a2006-09-27 01:50:40 -0700193 unsigned long stack_top, struct task_struct * p,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 struct pt_regs *regs)
195{
Jeff Dike77bf4402007-10-16 01:26:58 -0700196 void (*handler)(void);
197 int ret = 0;
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -0800198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 p->thread = (struct thread_struct) INIT_THREAD;
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -0800200
Jeff Dikeba180fd2007-10-16 01:27:00 -0700201 if (current->thread.forking) {
Jeff Dike77bf4402007-10-16 01:26:58 -0700202 memcpy(&p->thread.regs.regs, &regs->regs,
203 sizeof(p->thread.regs.regs));
204 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.regs, 0);
Jeff Dikeba180fd2007-10-16 01:27:00 -0700205 if (sp != 0)
Jeff Dike77bf4402007-10-16 01:26:58 -0700206 REGS_SP(p->thread.regs.regs.regs) = sp;
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -0800207
Jeff Dike77bf4402007-10-16 01:26:58 -0700208 handler = fork_handler;
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -0800209
Jeff Dike77bf4402007-10-16 01:26:58 -0700210 arch_copy_thread(&current->thread.arch, &p->thread.arch);
211 }
212 else {
213 init_thread_registers(&p->thread.regs.regs);
214 p->thread.request.u.thread = current->thread.request.u.thread;
215 handler = new_thread_handler;
216 }
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -0800217
Jeff Dike77bf4402007-10-16 01:26:58 -0700218 new_thread(task_stack_page(p), &p->thread.switch_buf, handler);
219
220 if (current->thread.forking) {
221 clear_flushed_tls(p);
222
223 /*
224 * Set a new TLS for the child thread?
225 */
226 if (clone_flags & CLONE_SETTLS)
227 ret = arch_copy_tls(p);
228 }
229
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -0800230 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233void initial_thread_cb(void (*proc)(void *), void *arg)
234{
235 int save_kmalloc_ok = kmalloc_ok;
236
237 kmalloc_ok = 0;
Jeff Dike6aa802c2007-10-16 01:26:56 -0700238 initial_thread_cb_skas(proc, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 kmalloc_ok = save_kmalloc_ok;
240}
Jeff Dike995473a2006-09-27 01:50:40 -0700241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242void default_idle(void)
243{
Jeff Dikeba180fd2007-10-16 01:27:00 -0700244 while(1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 /* endless idle loop with no priority at all */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 /*
248 * although we are an idle CPU, we do not want to
249 * get into the scheduler unnecessarily.
250 */
Jeff Dikeba180fd2007-10-16 01:27:00 -0700251 if (need_resched())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 schedule();
Jeff Dike995473a2006-09-27 01:50:40 -0700253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 idle_sleep(10);
255 }
256}
257
258void cpu_idle(void)
259{
Jeff Dike77bf4402007-10-16 01:26:58 -0700260 cpu_tasks[current_thread->cpu].pid = os_getpid();
261 default_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Jeff Dike995473a2006-09-27 01:50:40 -0700264void *um_virt_to_phys(struct task_struct *task, unsigned long addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 pte_t *pte_out)
266{
267 pgd_t *pgd;
268 pud_t *pud;
269 pmd_t *pmd;
270 pte_t *pte;
Hugh Dickins8f5cd762005-10-29 18:16:38 -0700271 pte_t ptent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Jeff Dikeba180fd2007-10-16 01:27:00 -0700273 if (task->mm == NULL)
Jeff Dike6e21aec2007-05-06 14:51:21 -0700274 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 pgd = pgd_offset(task->mm, addr);
Jeff Dikeba180fd2007-10-16 01:27:00 -0700276 if (!pgd_present(*pgd))
Jeff Dike6e21aec2007-05-06 14:51:21 -0700277 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 pud = pud_offset(pgd, addr);
Jeff Dikeba180fd2007-10-16 01:27:00 -0700280 if (!pud_present(*pud))
Jeff Dike6e21aec2007-05-06 14:51:21 -0700281 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 pmd = pmd_offset(pud, addr);
Jeff Dikeba180fd2007-10-16 01:27:00 -0700284 if (!pmd_present(*pmd))
Jeff Dike6e21aec2007-05-06 14:51:21 -0700285 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 pte = pte_offset_kernel(pmd, addr);
Hugh Dickins8f5cd762005-10-29 18:16:38 -0700288 ptent = *pte;
Jeff Dikeba180fd2007-10-16 01:27:00 -0700289 if (!pte_present(ptent))
Jeff Dike6e21aec2007-05-06 14:51:21 -0700290 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Jeff Dikeba180fd2007-10-16 01:27:00 -0700292 if (pte_out != NULL)
Hugh Dickins8f5cd762005-10-29 18:16:38 -0700293 *pte_out = ptent;
Jeff Dike6e21aec2007-05-06 14:51:21 -0700294 return (void *) (pte_val(ptent) & PAGE_MASK) + (addr & ~PAGE_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
297char *current_cmd(void)
298{
299#if defined(CONFIG_SMP) || defined(CONFIG_HIGHMEM)
Jeff Dike6e21aec2007-05-06 14:51:21 -0700300 return "(Unknown)";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#else
302 void *addr = um_virt_to_phys(current, current->mm->arg_start, NULL);
303 return IS_ERR(addr) ? "(Unknown)": __va((unsigned long) addr);
304#endif
305}
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307void dump_thread(struct pt_regs *regs, struct user *u)
308{
309}
310
Paolo 'Blaisorblade' Giarrussob6316292006-01-18 17:42:58 -0800311int __cant_sleep(void) {
312 return in_atomic() || irqs_disabled() || in_interrupt();
313 /* Is in_interrupt() really needed? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316int user_context(unsigned long sp)
317{
318 unsigned long stack;
319
320 stack = sp & (PAGE_MASK << CONFIG_KERNEL_STACK_ORDER);
Jeff Dike6e21aec2007-05-06 14:51:21 -0700321 return stack != (unsigned long) current_thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324extern exitcall_t __uml_exitcall_begin, __uml_exitcall_end;
325
326void do_uml_exitcalls(void)
327{
328 exitcall_t *call;
329
330 call = &__uml_exitcall_end;
331 while (--call >= &__uml_exitcall_begin)
332 (*call)();
333}
334
335char *uml_strdup(char *string)
336{
Robert Lovedfe52242005-06-23 00:09:04 -0700337 return kstrdup(string, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340int copy_to_user_proc(void __user *to, void *from, int size)
341{
Jeff Dike6e21aec2007-05-06 14:51:21 -0700342 return copy_to_user(to, from, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
345int copy_from_user_proc(void *to, void __user *from, int size)
346{
Jeff Dike6e21aec2007-05-06 14:51:21 -0700347 return copy_from_user(to, from, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350int clear_user_proc(void __user *buf, int size)
351{
Jeff Dike6e21aec2007-05-06 14:51:21 -0700352 return clear_user(buf, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355int strlen_user_proc(char __user *str)
356{
Jeff Dike6e21aec2007-05-06 14:51:21 -0700357 return strlen_user(str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
360int smp_sigio_handler(void)
361{
362#ifdef CONFIG_SMP
363 int cpu = current_thread->cpu;
364 IPI_handler(cpu);
Jeff Dikeba180fd2007-10-16 01:27:00 -0700365 if (cpu != 0)
Jeff Dike6e21aec2007-05-06 14:51:21 -0700366 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Jeff Dike6e21aec2007-05-06 14:51:21 -0700368 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371int cpu(void)
372{
Jeff Dike6e21aec2007-05-06 14:51:21 -0700373 return current_thread->cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
376static atomic_t using_sysemu = ATOMIC_INIT(0);
377int sysemu_supported;
378
379void set_using_sysemu(int value)
380{
381 if (value > sysemu_supported)
382 return;
383 atomic_set(&using_sysemu, value);
384}
385
386int get_using_sysemu(void)
387{
388 return atomic_read(&using_sysemu);
389}
390
391static int proc_read_sysemu(char *buf, char **start, off_t offset, int size,int *eof, void *data)
392{
Jeff Dikeba180fd2007-10-16 01:27:00 -0700393 if (snprintf(buf, size, "%d\n", get_using_sysemu()) < size)
394 /* No overflow */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 *eof = 1;
396
397 return strlen(buf);
398}
399
Al Viro4d338e12006-03-31 02:30:15 -0800400static int proc_write_sysemu(struct file *file,const char __user *buf, unsigned long count,void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 char tmp[2];
403
404 if (copy_from_user(tmp, buf, 1))
405 return -EFAULT;
406
407 if (tmp[0] >= '0' && tmp[0] <= '2')
408 set_using_sysemu(tmp[0] - '0');
Jeff Dikeba180fd2007-10-16 01:27:00 -0700409 /* We use the first char, but pretend to write everything */
410 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413int __init make_proc_sysemu(void)
414{
415 struct proc_dir_entry *ent;
416 if (!sysemu_supported)
417 return 0;
418
419 ent = create_proc_entry("sysemu", 0600, &proc_root);
420
421 if (ent == NULL)
422 {
Christophe Lucas30f417c2005-07-28 21:16:12 -0700423 printk(KERN_WARNING "Failed to register /proc/sysemu\n");
Jeff Dike6e21aec2007-05-06 14:51:21 -0700424 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426
427 ent->read_proc = proc_read_sysemu;
428 ent->write_proc = proc_write_sysemu;
429
430 return 0;
431}
432
433late_initcall(make_proc_sysemu);
434
435int singlestepping(void * t)
436{
437 struct task_struct *task = t ? t : current;
438
439 if ( ! (task->ptrace & PT_DTRACE) )
Jeff Dikeba180fd2007-10-16 01:27:00 -0700440 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 if (task->thread.singlestep_syscall)
Jeff Dikeba180fd2007-10-16 01:27:00 -0700443 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 return 2;
446}
447
Bodo Stroesserb8bd0222005-05-06 21:30:53 -0700448/*
449 * Only x86 and x86_64 have an arch_align_stack().
450 * All other arches have "#define arch_align_stack(x) (x)"
451 * in their asm/system.h
452 * As this is included in UML from asm-um/system-generic.h,
453 * we can use it to behave as the subarch does.
454 */
455#ifndef arch_align_stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456unsigned long arch_align_stack(unsigned long sp)
457{
Jeff Dike8f80e942006-09-25 23:33:01 -0700458 if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 sp -= get_random_int() % 8192;
460 return sp & ~0xf;
461}
Bodo Stroesserb8bd0222005-05-06 21:30:53 -0700462#endif