From 598d188af1a0645dc75c9541eff0017a4f6d9987 Mon Sep 17 00:00:00 2001 From: Tyler Date: Mon, 10 Jul 2006 04:45:03 -0700 Subject: [PATCH] uml: clean up address space limits code I was looking at the code of the UML and more precisely at the functions set_task_sizes_tt and set_task_sizes_skas. I noticed that these 2 functions take a paramater (arg) which is not used : the function is always called with the value 0. I suppose that this value might change in the future (or even can be configured), so I added a constant in mem_user.h file. Also, I rounded CONFIG_HOST_TASk_SIZE to a 4M. Signed-off-by: Tyler Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/kernel/skas/mem.c | 19 ++++--------------- arch/um/kernel/tt/mem.c | 17 +++-------------- arch/um/kernel/um_arch.c | 2 +- 3 files changed, 8 insertions(+), 30 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/kernel/skas/mem.c b/arch/um/kernel/skas/mem.c index 88ab96c609ce..7e5b8f165cf2 100644 --- a/arch/um/kernel/skas/mem.c +++ b/arch/um/kernel/skas/mem.c @@ -9,14 +9,14 @@ #include "mem_user.h" #include "skas.h" -unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out, +unsigned long set_task_sizes_skas(unsigned long *host_size_out, unsigned long *task_size_out) { /* Round up to the nearest 4M */ - unsigned long top = ROUND_4M((unsigned long) &arg); + unsigned long top = ROUND_4M((unsigned long) &host_size_out); #ifdef CONFIG_HOST_TASK_SIZE - *host_size_out = CONFIG_HOST_TASK_SIZE; + *host_size_out = ROUND_4M(CONFIG_HOST_TASK_SIZE); *task_size_out = CONFIG_HOST_TASK_SIZE; #else *host_size_out = top; @@ -24,16 +24,5 @@ unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out, *task_size_out = top; else *task_size_out = CONFIG_STUB_START & PGDIR_MASK; #endif - return(((unsigned long) set_task_sizes_skas) & ~0xffffff); + return ((unsigned long) set_task_sizes_skas) & ~0xffffff; } - -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * Emacs will notice this stuff at the end of the file and automatically - * adjust the settings for this buffer only. This must remain at the end - * of the file. - * --------------------------------------------------------------------------- - * Local variables: - * c-file-style: "linux" - * End: - */ diff --git a/arch/um/kernel/tt/mem.c b/arch/um/kernel/tt/mem.c index bcb8796c3cb1..4ae8c5c1e3b3 100644 --- a/arch/um/kernel/tt/mem.c +++ b/arch/um/kernel/tt/mem.c @@ -24,22 +24,11 @@ void before_mem_tt(unsigned long brk_start) #define SIZE ((CONFIG_NEST_LEVEL + CONFIG_KERNEL_HALF_GIGS) * 0x20000000) #define START (CONFIG_TOP_ADDR - SIZE) -unsigned long set_task_sizes_tt(int arg, unsigned long *host_size_out, +unsigned long set_task_sizes_tt(unsigned long *host_size_out, unsigned long *task_size_out) { /* Round up to the nearest 4M */ - *host_size_out = ROUND_4M((unsigned long) &arg); + *host_size_out = ROUND_4M((unsigned long) &host_size_out); *task_size_out = START; - return(START); + return START; } - -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * Emacs will notice this stuff at the end of the file and automatically - * adjust the settings for this buffer only. This must remain at the end - * of the file. - * --------------------------------------------------------------------------- - * Local variables: - * c-file-style: "linux" - * End: - */ diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 37cfe7701f06..a50a0aac8faa 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -374,7 +374,7 @@ int linux_main(int argc, char **argv) printf("UML running in %s mode\n", mode); - uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, 0, + uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, &host_task_size, &task_size); /* -- cgit v1.2.3-55-g7522 From aceb343464a136e1c0de5294b097a1f9ab018870 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:05 -0700 Subject: [PATCH] uml: timer initialization cleanup This cleans up the mess that is the timer initialization. There used to be two timer handlers - one that basically ran during delay loop calibration and one that handled the timer afterwards. There were also two sets of timer initialization code - one that starts in user code and calls into the kernel side of the house, and one that starts in kernel code and calls user code. This eliminates one timer handler and consolidates the two sets of initialization code. [akpm@osdl.org: use new INTF_ flags] Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/kern_util.h | 1 - arch/um/kernel/time_kern.c | 64 ++++++++++++++++++--------------------------- arch/um/os-Linux/irq.c | 11 +++----- arch/um/os-Linux/signal.c | 23 ---------------- arch/um/os-Linux/time.c | 16 ------------ 5 files changed, 30 insertions(+), 85 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/kern_util.h b/arch/um/include/kern_util.h index 310980b32173..7a64190c1e53 100644 --- a/arch/um/include/kern_util.h +++ b/arch/um/include/kern_util.h @@ -75,7 +75,6 @@ extern int hz(void); extern void uml_idle_timer(void); extern unsigned int do_IRQ(int irq, union uml_pt_regs *regs); extern int external_pid(void *t); -extern void boot_timer_handler(int sig); extern void interrupt_end(void); extern void initial_thread_cb(void (*proc)(void *), void *arg); extern int debugger_signal(int status, int pid); diff --git a/arch/um/kernel/time_kern.c b/arch/um/kernel/time_kern.c index d7e044b5e5ee..8e56c58320ba 100644 --- a/arch/um/kernel/time_kern.c +++ b/arch/um/kernel/time_kern.c @@ -84,29 +84,6 @@ void timer_irq(union uml_pt_regs *regs) } } - -void time_init_kern(void) -{ - long long nsecs; - - nsecs = os_nsecs(); - set_normalized_timespec(&wall_to_monotonic, -nsecs / BILLION, - -nsecs % BILLION); -} - -void do_boot_timer_handler(struct sigcontext * sc) -{ - unsigned long flags; - struct pt_regs regs; - - CHOOSE_MODE((void) (UPT_SC(®s.regs) = sc), - (void) (regs.regs.skas.is_user = 0)); - - write_seqlock_irqsave(&xtime_lock, flags); - do_timer(®s); - write_sequnlock_irqrestore(&xtime_lock, flags); -} - static DEFINE_SPINLOCK(timer_spinlock); static unsigned long long local_offset = 0; @@ -142,6 +119,32 @@ irqreturn_t um_timer(int irq, void *dev, struct pt_regs *regs) return IRQ_HANDLED; } +static void register_timer(void) +{ + int err; + + err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL); + if(err != 0) + printk(KERN_ERR "timer_init : request_irq failed - " + "errno = %d\n", -err); + + timer_irq_inited = 1; + + user_time_init(); +} + +extern void (*late_time_init)(void); + +void time_init(void) +{ + long long nsecs; + + nsecs = os_nsecs(); + set_normalized_timespec(&wall_to_monotonic, -nsecs / BILLION, + -nsecs % BILLION); + late_time_init = register_timer; +} + void do_gettimeofday(struct timeval *tv) { unsigned long long nsecs = get_time(); @@ -189,18 +192,3 @@ void timer_handler(int sig, union uml_pt_regs *regs) if(current_thread->cpu == 0) timer_irq(regs); } - -int __init timer_init(void) -{ - int err; - - user_time_init(); - err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL); - if(err != 0) - printk(KERN_ERR "timer_init : request_irq failed - " - "errno = %d\n", -err); - timer_irq_inited = 1; - return(0); -} - -arch_initcall(timer_init); diff --git a/arch/um/os-Linux/irq.c b/arch/um/os-Linux/irq.c index 3788d4568d33..64c114b02701 100644 --- a/arch/um/os-Linux/irq.c +++ b/arch/um/os-Linux/irq.c @@ -142,17 +142,14 @@ void os_set_ioignore(void) void init_irq_signals(int on_sigstack) { - __sighandler_t h; int flags; flags = on_sigstack ? SA_ONSTACK : 0; - if (timer_irq_inited) - h = (__sighandler_t)alarm_handler; - else - h = boot_timer_handler; - set_handler(SIGVTALRM, h, flags | SA_RESTART, - SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1); + set_handler(SIGVTALRM, (__sighandler_t) alarm_handler, + flags | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1); + set_handler(SIGALRM, (__sighandler_t) alarm_handler, + flags | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1); set_handler(SIGIO, (__sighandler_t) sig_handler, flags | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); signal(SIGWINCH, SIG_IGN); diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index f11b3124a0c8..60e4faedf254 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -106,29 +106,6 @@ void alarm_handler(ARCH_SIGHDLR_PARAM) set_signals(enabled); } -extern void do_boot_timer_handler(struct sigcontext * sc); - -void boot_timer_handler(ARCH_SIGHDLR_PARAM) -{ - struct sigcontext *sc; - int enabled; - - ARCH_GET_SIGCONTEXT(sc, sig); - - enabled = signals_enabled; - if(!enabled){ - if(sig == SIGVTALRM) - pending |= SIGVTALRM_MASK; - else pending |= SIGALRM_MASK; - return; - } - - block_signals(); - - do_boot_timer_handler(sc); - set_signals(enabled); -} - void set_sigstack(void *sig_stack, int size) { stack_t stack = ((stack_t) { .ss_flags = 0, diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c index 280c4fb9b585..beb7f9666de3 100644 --- a/arch/um/os-Linux/time.c +++ b/arch/um/os-Linux/time.c @@ -81,14 +81,6 @@ void uml_idle_timer(void) set_interval(ITIMER_REAL); } -void time_init(void) -{ - if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR) - panic("Couldn't set SIGVTALRM handler"); - set_interval(ITIMER_VIRTUAL); - time_init_kern(); -} - unsigned long long os_nsecs(void) { struct timeval tv; @@ -106,15 +98,7 @@ void idle_sleep(int secs) nanosleep(&ts, NULL); } -/* XXX This partly duplicates init_irq_signals */ - void user_time_init(void) { - set_handler(SIGVTALRM, (__sighandler_t) alarm_handler, - SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, - SIGALRM, SIGUSR2, -1); - set_handler(SIGALRM, (__sighandler_t) alarm_handler, - SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, - SIGVTALRM, SIGUSR2, -1); set_interval(ITIMER_VIRTUAL); } -- cgit v1.2.3-55-g7522 From 8633c2331e738218c7356633e1c4adb75726225f Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:05 -0700 Subject: [PATCH] uml: remove some useless exports Spotted by Al Viro - eliminate a couple useless exports. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/kernel/ksyms.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/kernel/ksyms.c b/arch/um/kernel/ksyms.c index 432cf0b97a13..c97045d6d89f 100644 --- a/arch/um/kernel/ksyms.c +++ b/arch/um/kernel/ksyms.c @@ -88,12 +88,6 @@ EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(do_gettimeofday); EXPORT_SYMBOL(do_settimeofday); -/* This is here because UML expands lseek to sys_lseek, not to a system - * call instruction. - */ -EXPORT_SYMBOL(sys_lseek); -EXPORT_SYMBOL(sys_wait4); - #ifdef CONFIG_SMP /* required for SMP */ -- cgit v1.2.3-55-g7522 From 23bbd586ed7894982fd9323f63b2065afbb77773 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:06 -0700 Subject: [PATCH] uml: fix static binary segfault When UML is built as a static binary, it segfaults when run. The reason is that a memory hole that is present in dynamic binaries isn't there in static binaries, and it contains essential stuff. This fix removes the code which maps some anonymous memory into that hole and cleans up some related code. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/skas/mode_kern_skas.h | 3 +-- arch/um/include/tt/mode_kern_tt.h | 3 +-- arch/um/kernel/mem.c | 11 ----------- arch/um/kernel/physmem.c | 2 +- arch/um/kernel/skas/mem.c | 11 +++++------ arch/um/kernel/tt/mem.c | 10 ++++++---- arch/um/kernel/um_arch.c | 9 ++++++--- arch/um/kernel/uml.lds.S | 13 ++++++++----- 8 files changed, 28 insertions(+), 34 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/skas/mode_kern_skas.h b/arch/um/include/skas/mode_kern_skas.h index 651350adfe03..9cd9c6ec9a63 100644 --- a/arch/um/include/skas/mode_kern_skas.h +++ b/arch/um/include/skas/mode_kern_skas.h @@ -29,8 +29,7 @@ extern void flush_tlb_mm_skas(struct mm_struct *mm); extern void force_flush_all_skas(void); extern long execute_syscall_skas(void *r); extern void before_mem_skas(unsigned long unused); -extern unsigned long set_task_sizes_skas(unsigned long *host_size_out, - unsigned long *task_size_out); +extern unsigned long set_task_sizes_skas(unsigned long *task_size_out); extern int start_uml_skas(void); extern int external_pid_skas(struct task_struct *task); extern int thread_pid_skas(struct task_struct *task); diff --git a/arch/um/include/tt/mode_kern_tt.h b/arch/um/include/tt/mode_kern_tt.h index fb2d3d76685a..a4fc63057195 100644 --- a/arch/um/include/tt/mode_kern_tt.h +++ b/arch/um/include/tt/mode_kern_tt.h @@ -30,8 +30,7 @@ extern void flush_tlb_mm_tt(struct mm_struct *mm); extern void force_flush_all_tt(void); extern long execute_syscall_tt(void *r); extern void before_mem_tt(unsigned long brk_start); -extern unsigned long set_task_sizes_tt(unsigned long *host_size_out, - unsigned long *task_size_out); +extern unsigned long set_task_sizes_tt(unsigned long *task_size_out); extern int start_uml_tt(void); extern int external_pid_tt(struct task_struct *task); extern int thread_pid_tt(struct task_struct *task); diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 44e41a35f000..61280167c560 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -24,8 +24,6 @@ #include "init.h" #include "kern_constants.h" -extern char __binary_start; - /* Changed during early boot */ unsigned long *empty_zero_page = NULL; unsigned long *empty_bad_page = NULL; @@ -65,8 +63,6 @@ static void setup_highmem(unsigned long highmem_start, void mem_init(void) { - unsigned long start; - max_low_pfn = (high_physmem - uml_physmem) >> PAGE_SHIFT; /* clear the zero-page */ @@ -81,13 +77,6 @@ void mem_init(void) free_bootmem(__pa(brk_end), uml_reserved - brk_end); uml_reserved = brk_end; - /* Fill in any hole at the start of the binary */ - start = (unsigned long) &__binary_start & PAGE_MASK; - if(uml_physmem != start){ - map_memory(uml_physmem, __pa(uml_physmem), start - uml_physmem, - 1, 1, 0); - } - /* this will put all low memory onto the freelists */ totalram_pages = free_all_bootmem(); totalhigh_pages = highmem >> PAGE_SHIFT; diff --git a/arch/um/kernel/physmem.c b/arch/um/kernel/physmem.c index 166cb09cae4c..abafa64b8727 100644 --- a/arch/um/kernel/physmem.c +++ b/arch/um/kernel/physmem.c @@ -317,7 +317,7 @@ void map_memory(unsigned long virt, unsigned long phys, unsigned long len, } } -extern int __syscall_stub_start, __binary_start; +extern int __syscall_stub_start; void setup_physmem(unsigned long start, unsigned long reserve_end, unsigned long len, unsigned long long highmem) diff --git a/arch/um/kernel/skas/mem.c b/arch/um/kernel/skas/mem.c index 7e5b8f165cf2..27bbf54b1e52 100644 --- a/arch/um/kernel/skas/mem.c +++ b/arch/um/kernel/skas/mem.c @@ -9,20 +9,19 @@ #include "mem_user.h" #include "skas.h" -unsigned long set_task_sizes_skas(unsigned long *host_size_out, - unsigned long *task_size_out) +unsigned long set_task_sizes_skas(unsigned long *task_size_out) { /* Round up to the nearest 4M */ - unsigned long top = ROUND_4M((unsigned long) &host_size_out); + unsigned long host_task_size = ROUND_4M((unsigned long) + &host_task_size); #ifdef CONFIG_HOST_TASK_SIZE *host_size_out = ROUND_4M(CONFIG_HOST_TASK_SIZE); *task_size_out = CONFIG_HOST_TASK_SIZE; #else - *host_size_out = top; if (!skas_needs_stub) - *task_size_out = top; + *task_size_out = host_task_size; else *task_size_out = CONFIG_STUB_START & PGDIR_MASK; #endif - return ((unsigned long) set_task_sizes_skas) & ~0xffffff; + return host_task_size; } diff --git a/arch/um/kernel/tt/mem.c b/arch/um/kernel/tt/mem.c index 4ae8c5c1e3b3..84a23b14f770 100644 --- a/arch/um/kernel/tt/mem.c +++ b/arch/um/kernel/tt/mem.c @@ -24,11 +24,13 @@ void before_mem_tt(unsigned long brk_start) #define SIZE ((CONFIG_NEST_LEVEL + CONFIG_KERNEL_HALF_GIGS) * 0x20000000) #define START (CONFIG_TOP_ADDR - SIZE) -unsigned long set_task_sizes_tt(unsigned long *host_size_out, - unsigned long *task_size_out) +unsigned long set_task_sizes_tt(unsigned long *task_size_out) { + unsigned long host_task_size; + /* Round up to the nearest 4M */ - *host_size_out = ROUND_4M((unsigned long) &host_size_out); + host_task_size = ROUND_4M((unsigned long) &host_task_size); *task_size_out = START; - return START; + + return host_task_size; } diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index a50a0aac8faa..7896cf98232d 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -330,6 +330,8 @@ EXPORT_SYMBOL(end_iomem); #define MIN_VMALLOC (32 * 1024 * 1024) +extern char __binary_start; + int linux_main(int argc, char **argv) { unsigned long avail, diff; @@ -374,8 +376,9 @@ int linux_main(int argc, char **argv) printf("UML running in %s mode\n", mode); - uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, - &host_task_size, &task_size); + uml_start = (unsigned long) &__binary_start; + host_task_size = CHOOSE_MODE_PROC(set_task_sizes_tt, + set_task_sizes_skas, &task_size); /* * Setting up handlers to 'sig_info' struct @@ -395,7 +398,7 @@ int linux_main(int argc, char **argv) physmem_size += UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end); } - uml_physmem = uml_start; + uml_physmem = uml_start & PAGE_MASK; /* Reserve up to 4M after the current brk */ uml_reserved = ROUND_4M(brk_start) + (1 << 22); diff --git a/arch/um/kernel/uml.lds.S b/arch/um/kernel/uml.lds.S index af11915ce0a8..8eca47a6ff08 100644 --- a/arch/um/kernel/uml.lds.S +++ b/arch/um/kernel/uml.lds.S @@ -7,13 +7,16 @@ jiffies = jiffies_64; SECTIONS { - /*This must contain the right address - not quite the default ELF one.*/ + /* This must contain the right address - not quite the default ELF one.*/ PROVIDE (__executable_start = START); - . = START + SIZEOF_HEADERS; + /* Static binaries stick stuff here, like the sigreturn trampoline, + * invisibly to objdump. So, just make __binary_start equal to the very + * beginning of the executable, and if there are unmapped pages after this, + * they are forever unusable. + */ + __binary_start = START; - /* Used in arch/um/kernel/mem.c. Any memory between START and __binary_start - * is remapped.*/ - __binary_start = .; + . = START + SIZEOF_HEADERS; #ifdef MODE_TT .remap_data : { UNMAP_PATH (.data .bss) } -- cgit v1.2.3-55-g7522 From e64bd134085451fe3f751025c5d5a70729164b7c Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:07 -0700 Subject: [PATCH] uml: signal initialization cleanup It turns out that init_new_thread_signals is always called with altstack == 1, so we can eliminate the parameter. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 2 +- arch/um/kernel/skas/process_kern.c | 2 +- arch/um/kernel/tt/exec_kern.c | 2 +- arch/um/kernel/tt/process_kern.c | 2 +- arch/um/os-Linux/process.c | 19 +++++++++---------- arch/um/os-Linux/skas/process.c | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index f88856c28a66..700f7a76c822 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -199,7 +199,7 @@ extern int os_getpid(void); extern int os_getpgrp(void); extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)); -extern void init_new_thread_signals(int altstack); +extern void init_new_thread_signals(void); extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr); extern int os_map_memory(void *virt, int fd, unsigned long long off, diff --git a/arch/um/kernel/skas/process_kern.c b/arch/um/kernel/skas/process_kern.c index 2135eaf98a93..55caeec8b257 100644 --- a/arch/um/kernel/skas/process_kern.c +++ b/arch/um/kernel/skas/process_kern.c @@ -177,7 +177,7 @@ int start_uml_skas(void) if(proc_mm) userspace_pid[0] = start_userspace(0); - init_new_thread_signals(1); + init_new_thread_signals(); init_task.thread.request.u.thread.proc = start_kernel_proc; init_task.thread.request.u.thread.arg = NULL; diff --git a/arch/um/kernel/tt/exec_kern.c b/arch/um/kernel/tt/exec_kern.c index 5c1e4cc1c049..ad66df17d9d7 100644 --- a/arch/um/kernel/tt/exec_kern.c +++ b/arch/um/kernel/tt/exec_kern.c @@ -21,7 +21,7 @@ static int exec_tramp(void *sig_stack) { init_new_thread_stack(sig_stack, NULL); - init_new_thread_signals(1); + init_new_thread_signals(); os_stop_process(os_getpid()); return(0); } diff --git a/arch/um/kernel/tt/process_kern.c b/arch/um/kernel/tt/process_kern.c index 8368c2dbe635..1e86f0bfef72 100644 --- a/arch/um/kernel/tt/process_kern.c +++ b/arch/um/kernel/tt/process_kern.c @@ -142,7 +142,7 @@ static void new_thread_handler(int sig) schedule_tail(current->thread.prev_sched); current->thread.prev_sched = NULL; - init_new_thread_signals(1); + init_new_thread_signals(); enable_timer(); free_page(current->thread.temp_stack); set_cmdline("(kernel thread)"); diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 233be2f4f8cb..b1cda818f5b5 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -250,25 +250,24 @@ void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)) if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1); } -void init_new_thread_signals(int altstack) +void init_new_thread_signals(void) { - int flags = altstack ? SA_ONSTACK : 0; - - set_handler(SIGSEGV, (__sighandler_t) sig_handler, flags, + set_handler(SIGSEGV, (__sighandler_t) sig_handler, SA_ONSTACK, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); - set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags, + set_handler(SIGTRAP, (__sighandler_t) sig_handler, SA_ONSTACK, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); - set_handler(SIGFPE, (__sighandler_t) sig_handler, flags, + set_handler(SIGFPE, (__sighandler_t) sig_handler, SA_ONSTACK, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); - set_handler(SIGILL, (__sighandler_t) sig_handler, flags, + set_handler(SIGILL, (__sighandler_t) sig_handler, SA_ONSTACK, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); - set_handler(SIGBUS, (__sighandler_t) sig_handler, flags, + set_handler(SIGBUS, (__sighandler_t) sig_handler, SA_ONSTACK, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); set_handler(SIGUSR2, (__sighandler_t) sig_handler, - flags, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); + SA_ONSTACK, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, + -1); signal(SIGHUP, SIG_IGN); - init_irq_signals(altstack); + init_irq_signals(1); } int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr) diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index bd89c6b99d5d..bf35572d9cfa 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -159,7 +159,7 @@ static int userspace_tramp(void *stack) ptrace(PTRACE_TRACEME, 0, 0, 0); - init_new_thread_signals(1); + init_new_thread_signals(); enable_timer(); if(!proc_mm){ -- cgit v1.2.3-55-g7522 From 872aaa65a6ef30edef05a89977f7021f9840b215 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:08 -0700 Subject: [PATCH] uml: timer handler tidying Get rid of a user of timer_irq_inited (and first_tick) by observing that prev_ticks can be used to decide if this is the first call. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/kernel/time_kern.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/kernel/time_kern.c b/arch/um/kernel/time_kern.c index 8e56c58320ba..552ca1cb9847 100644 --- a/arch/um/kernel/time_kern.c +++ b/arch/um/kernel/time_kern.c @@ -38,7 +38,6 @@ unsigned long long sched_clock(void) /* Changed at early boot */ int timer_irq_inited = 0; -static int first_tick; static unsigned long long prev_nsecs; #ifdef CONFIG_UML_REAL_TIME_CLOCK static long long delta; /* Deviation per interval */ @@ -48,15 +47,8 @@ void timer_irq(union uml_pt_regs *regs) { unsigned long long ticks = 0; - if(!timer_irq_inited){ - /* This is to ensure that ticks don't pile up when - * the timer handler is suspended */ - first_tick = 0; - return; - } - - if(first_tick){ #ifdef CONFIG_UML_REAL_TIME_CLOCK + if(prev_nsecs){ /* We've had 1 tick */ unsigned long long nsecs = os_nsecs(); @@ -69,15 +61,11 @@ void timer_irq(union uml_pt_regs *regs) ticks += (delta * HZ) / BILLION; delta -= (ticks * BILLION) / HZ; + } + else prev_nsecs = os_nsecs(); #else - ticks = 1; + ticks = 1; #endif - } - else { - prev_nsecs = os_nsecs(); - first_tick = 1; - } - while(ticks > 0){ do_IRQ(TIMER_IRQ, regs); ticks--; -- cgit v1.2.3-55-g7522 From 8ae43ff8aa60f81f5d82a4911d704ce8902d11fb Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:09 -0700 Subject: [PATCH] uml: mark forward_interrupts as being mode-specific Mark forward_interrupts as being tt-mode only. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/irq_user.h | 7 ++++++- arch/um/kernel/irq.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/irq_user.h b/arch/um/include/irq_user.h index 69a93c804f0e..09e9e38920d5 100644 --- a/arch/um/include/irq_user.h +++ b/arch/um/include/irq_user.h @@ -6,6 +6,8 @@ #ifndef __IRQ_USER_H__ #define __IRQ_USER_H__ +#include "uml-config.h" + struct irq_fd { struct irq_fd *next; void *id; @@ -26,9 +28,12 @@ extern void free_irq_by_fd(int fd); extern void reactivate_fd(int fd, int irqnum); extern void deactivate_fd(int fd, int irqnum); extern int deactivate_all_fds(void); -extern void forward_interrupts(int pid); extern int activate_ipi(int fd, int pid); extern unsigned long irq_lock(void); extern void irq_unlock(unsigned long flags); +#ifdef CONFIG_MODE_TT +extern void forward_interrupts(int pid); +#endif + #endif diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index bfd0bdc8cd40..519cdb0a7708 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -350,6 +350,7 @@ int deactivate_all_fds(void) return 0; } +#ifdef CONFIG_MODE_TT void forward_interrupts(int pid) { struct irq_fd *irq; @@ -371,6 +372,7 @@ void forward_interrupts(int pid) } irq_unlock(flags); } +#endif /* * do_IRQ handles all normal device IRQ's (the special -- cgit v1.2.3-55-g7522 From bfaafd7184f044c63cd937cb0ffb4334b4ec7635 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:10 -0700 Subject: [PATCH] uml: remove spinlock wrapper functions The irq_spinlock is not needed from user code any more, so the irq_lock and irq_unlock wrappers can go away. This also changes the name of the lock to irq_lock. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/irq_user.h | 2 -- arch/um/kernel/irq.c | 45 ++++++++++++++++----------------------------- 2 files changed, 16 insertions(+), 31 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/irq_user.h b/arch/um/include/irq_user.h index 09e9e38920d5..15d311b9be9e 100644 --- a/arch/um/include/irq_user.h +++ b/arch/um/include/irq_user.h @@ -29,8 +29,6 @@ extern void reactivate_fd(int fd, int irqnum); extern void deactivate_fd(int fd, int irqnum); extern int deactivate_all_fds(void); extern int activate_ipi(int fd, int pid); -extern unsigned long irq_lock(void); -extern void irq_unlock(unsigned long flags); #ifdef CONFIG_MODE_TT extern void forward_interrupts(int pid); diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index 519cdb0a7708..27bc58ad38fd 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -123,6 +123,8 @@ static void maybe_sigio_broken(int fd, int type) } } +static DEFINE_SPINLOCK(irq_lock); + int activate_fd(int irq, int fd, int type, void *dev_id) { struct pollfd *tmp_pfd; @@ -166,7 +168,7 @@ int activate_fd(int irq, int fd, int type, void *dev_id) * this is called only from process context, and can be locked with * a semaphore. */ - flags = irq_lock(); + spin_lock_irqsave(&irq_lock, flags); for (irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next) { if ((irq_fd->fd == fd) && (irq_fd->type == type)) { printk("Registering fd %d twice\n", fd); @@ -199,7 +201,7 @@ int activate_fd(int irq, int fd, int type, void *dev_id) * so we will not be able to put new pollfd struct to pollfds * then we free the buffer tmp_fds and try again. */ - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); kfree(tmp_pfd); tmp_pfd = NULL; @@ -207,14 +209,14 @@ int activate_fd(int irq, int fd, int type, void *dev_id) if (tmp_pfd == NULL) goto out_kfree; - flags = irq_lock(); + spin_lock_irqsave(&irq_lock, flags); } /*-------------*/ *last_irq_ptr = new_fd; last_irq_ptr = &new_fd->next; - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); /* This calls activate_fd, so it has to be outside the critical * section. @@ -224,7 +226,7 @@ int activate_fd(int irq, int fd, int type, void *dev_id) return(0); out_unlock: - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); out_kfree: kfree(new_fd); out: @@ -235,9 +237,9 @@ static void free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg) { unsigned long flags; - flags = irq_lock(); + spin_lock_irqsave(&irq_lock, flags); os_free_irq_by_cb(test, arg, active_fds, &last_irq_ptr); - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); } struct irq_and_dev { @@ -304,14 +306,14 @@ void reactivate_fd(int fd, int irqnum) unsigned long flags; int i; - flags = irq_lock(); + spin_lock_irqsave(&irq_lock, flags); irq = find_irq_by_fd(fd, irqnum, &i); if (irq == NULL) { - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); return; } os_set_pollfd(i, irq->fd); - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); /* This calls activate_fd, so it has to be outside the critical * section. @@ -325,13 +327,13 @@ void deactivate_fd(int fd, int irqnum) unsigned long flags; int i; - flags = irq_lock(); + spin_lock_irqsave(&irq_lock, flags); irq = find_irq_by_fd(fd, irqnum, &i); if (irq == NULL) goto out; os_set_pollfd(i, -1); out: - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); } int deactivate_all_fds(void) @@ -357,7 +359,7 @@ void forward_interrupts(int pid) unsigned long flags; int err; - flags = irq_lock(); + spin_lock_irqsave(&irq_lock, flags); for (irq = active_fds; irq != NULL; irq = irq->next) { err = os_set_owner(irq->fd, pid); if (err < 0) { @@ -370,7 +372,7 @@ void forward_interrupts(int pid) irq->pid = pid; } - irq_unlock(flags); + spin_unlock_irqrestore(&irq_lock, flags); } #endif @@ -405,21 +407,6 @@ int um_request_irq(unsigned int irq, int fd, int type, EXPORT_SYMBOL(um_request_irq); EXPORT_SYMBOL(reactivate_fd); -static DEFINE_SPINLOCK(irq_spinlock); - -unsigned long irq_lock(void) -{ - unsigned long flags; - - spin_lock_irqsave(&irq_spinlock, flags); - return flags; -} - -void irq_unlock(unsigned long flags) -{ - spin_unlock_irqrestore(&irq_spinlock, flags); -} - /* hw_interrupt_type must define (startup || enable) && * (shutdown || disable) && end */ static void dummy(unsigned int irq) -- cgit v1.2.3-55-g7522 From 8e64d96aeb495709c13307e2d79f3ee37e96aa4e Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:11 -0700 Subject: [PATCH] uml: remove os_isatty os_isatty can be made to disappear by moving maybe_sigio_broken from kernel to user code. This also lets write_sigio_workaround become static. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 3 +-- arch/um/kernel/irq.c | 17 ++--------------- arch/um/os-Linux/irq.c | 5 ----- arch/um/os-Linux/sigio.c | 14 +++++++++++++- 4 files changed, 16 insertions(+), 23 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 700f7a76c822..548f6ddd8597 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -318,7 +318,6 @@ extern void reboot_skas(void); /* irq.c */ extern int os_waiting_for_events(struct irq_fd *active_fds); -extern int os_isatty(int fd); extern int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds); extern void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg, struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2); @@ -330,9 +329,9 @@ extern void os_set_ioignore(void); extern void init_irq_signals(int on_sigstack); /* sigio.c */ -extern void write_sigio_workaround(void); extern int add_sigio_fd(int fd, int read); extern int ignore_sigio_fd(int fd); +extern void maybe_sigio_broken(int fd, int read); /* skas/trap */ extern void sig_handler_common_skas(int sig, void *sc_ptr); diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c index 27bc58ad38fd..589c69a75043 100644 --- a/arch/um/kernel/irq.c +++ b/arch/um/kernel/irq.c @@ -110,19 +110,6 @@ void sigio_handler(int sig, union uml_pt_regs *regs) free_irqs(); } -static void maybe_sigio_broken(int fd, int type) -{ - if (os_isatty(fd)) { - if ((type == IRQ_WRITE) && !pty_output_sigio) { - write_sigio_workaround(); - add_sigio_fd(fd, 0); - } else if ((type == IRQ_READ) && !pty_close_sigio) { - write_sigio_workaround(); - add_sigio_fd(fd, 1); - } - } -} - static DEFINE_SPINLOCK(irq_lock); int activate_fd(int irq, int fd, int type, void *dev_id) @@ -221,7 +208,7 @@ int activate_fd(int irq, int fd, int type, void *dev_id) /* This calls activate_fd, so it has to be outside the critical * section. */ - maybe_sigio_broken(fd, type); + maybe_sigio_broken(fd, (type == IRQ_READ)); return(0); @@ -318,7 +305,7 @@ void reactivate_fd(int fd, int irqnum) /* This calls activate_fd, so it has to be outside the critical * section. */ - maybe_sigio_broken(fd, irq->type); + maybe_sigio_broken(fd, (irq->type == IRQ_READ)); } void deactivate_fd(int fd, int irqnum) diff --git a/arch/um/os-Linux/irq.c b/arch/um/os-Linux/irq.c index 64c114b02701..7555bf9c33d9 100644 --- a/arch/um/os-Linux/irq.c +++ b/arch/um/os-Linux/irq.c @@ -52,11 +52,6 @@ int os_waiting_for_events(struct irq_fd *active_fds) return n; } -int os_isatty(int fd) -{ - return isatty(fd); -} - int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds) { if (pollfds_num == pollfds_size) { diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c index 00e9388e947a..0d2422a7d72c 100644 --- a/arch/um/os-Linux/sigio.c +++ b/arch/um/os-Linux/sigio.c @@ -233,7 +233,7 @@ static struct pollfd *setup_initial_poll(int fd) return p; } -void write_sigio_workaround(void) +static void write_sigio_workaround(void) { unsigned long stack; struct pollfd *p; @@ -314,6 +314,18 @@ out_close1: close(l_write_sigio_fds[1]); } +void maybe_sigio_broken(int fd, int read) +{ + if(!isatty(fd)) + return; + + if((read || pty_output_sigio) && (!read || pty_close_sigio)) + return; + + write_sigio_workaround(); + add_sigio_fd(fd, read); +} + void sigio_cleanup(void) { if(write_sigio_pid != -1){ -- cgit v1.2.3-55-g7522 From 29ac1c2142346e1e0e072f41df31688fc42ff540 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:12 -0700 Subject: [PATCH] uml: make some symbols static A few sigio-related things can be made static. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 1 - arch/um/kernel/sigio_kern.c | 14 -------------- arch/um/os-Linux/sigio.c | 10 ++++++---- 3 files changed, 6 insertions(+), 19 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 548f6ddd8597..b6c52496e15a 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -329,7 +329,6 @@ extern void os_set_ioignore(void); extern void init_irq_signals(int on_sigstack); /* sigio.c */ -extern int add_sigio_fd(int fd, int read); extern int ignore_sigio_fd(int fd); extern void maybe_sigio_broken(int fd, int read); diff --git a/arch/um/kernel/sigio_kern.c b/arch/um/kernel/sigio_kern.c index 51b677083948..5102ba5d5bd0 100644 --- a/arch/um/kernel/sigio_kern.c +++ b/arch/um/kernel/sigio_kern.c @@ -53,17 +53,3 @@ void sigio_unlock(void) { spin_unlock(&sigio_spinlock); } - -extern void sigio_cleanup(void); -__uml_exitcall(sigio_cleanup); - -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * Emacs will notice this stuff at the end of the file and automatically - * adjust the settings for this buffer only. This must remain at the end - * of the file. - * --------------------------------------------------------------------------- - * Local variables: - * c-file-style: "linux" - * End: - */ diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c index d22623e8fced..0ecac563c7b3 100644 --- a/arch/um/os-Linux/sigio.c +++ b/arch/um/os-Linux/sigio.c @@ -43,13 +43,13 @@ struct pollfds { /* Protected by sigio_lock(). Used by the sigio thread, but the UML thread * synchronizes with it. */ -struct pollfds current_poll = { +static struct pollfds current_poll = { .poll = NULL, .size = 0, .used = 0 }; -struct pollfds next_poll = { +static struct pollfds next_poll = { .poll = NULL, .size = 0, .used = 0 @@ -156,7 +156,7 @@ static void update_thread(void) set_signals(flags); } -int add_sigio_fd(int fd, int read) +static int add_sigio_fd(int fd, int read) { int err = 0, i, n, events; @@ -333,10 +333,12 @@ void maybe_sigio_broken(int fd, int read) add_sigio_fd(fd, read); } -void sigio_cleanup(void) +static void sigio_cleanup(void) { if(write_sigio_pid != -1){ os_kill_process(write_sigio_pid, 1); write_sigio_pid = -1; } } + +__uml_exitcall(sigio_cleanup); -- cgit v1.2.3-55-g7522 From 469226a431f553a7b3ec17d87ce3c2d1c6c25fb2 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:13 -0700 Subject: [PATCH] uml: remove syscall debugging Eliminate an unused debug option. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/Kconfig.debug | 9 --------- arch/um/defconfig | 1 - arch/um/kernel/Makefile | 1 - arch/um/kernel/skas/syscall.c | 7 ------- arch/um/kernel/syscall.c | 36 ------------------------------------ arch/um/kernel/tt/syscall_kern.c | 12 +----------- arch/um/kernel/tt/tracer.c | 22 +--------------------- 7 files changed, 2 insertions(+), 86 deletions(-) delete mode 100644 arch/um/kernel/syscall.c (limited to 'arch/um/kernel') diff --git a/arch/um/Kconfig.debug b/arch/um/Kconfig.debug index bab51d619173..09c1aca6339f 100644 --- a/arch/um/Kconfig.debug +++ b/arch/um/Kconfig.debug @@ -47,13 +47,4 @@ config GCOV If you're involved in UML kernel development and want to use gcov, say Y. If you're unsure, say N. -config SYSCALL_DEBUG - bool "Enable system call debugging" - depends on DEBUG_INFO - help - This adds some system debugging to UML, including keeping a ring buffer - with recent system calls and some global and per-task statistics. - - If unsure, say N - endmenu diff --git a/arch/um/defconfig b/arch/um/defconfig index 402a74dc5026..780cc0a4a128 100644 --- a/arch/um/defconfig +++ b/arch/um/defconfig @@ -526,4 +526,3 @@ CONFIG_FORCED_INLINING=y # CONFIG_RCU_TORTURE_TEST is not set # CONFIG_GPROF is not set # CONFIG_GCOV is not set -# CONFIG_SYSCALL_DEBUG is not set diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index fe08971b64cf..82b435897256 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -15,7 +15,6 @@ obj-y = config.o exec_kern.o exitcode.o \ obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += gprof_syms.o obj-$(CONFIG_GCOV) += gmon_syms.o -obj-$(CONFIG_SYSCALL_DEBUG) += syscall.o obj-$(CONFIG_MODE_TT) += tt/ obj-$(CONFIG_MODE_SKAS) += skas/ diff --git a/arch/um/kernel/skas/syscall.c b/arch/um/kernel/skas/syscall.c index 51fb94076fcf..0ae4eea21be4 100644 --- a/arch/um/kernel/skas/syscall.c +++ b/arch/um/kernel/skas/syscall.c @@ -18,11 +18,7 @@ void handle_syscall(union uml_pt_regs *r) struct pt_regs *regs = container_of(r, struct pt_regs, regs); long result; int syscall; -#ifdef UML_CONFIG_SYSCALL_DEBUG - int index; - index = record_syscall_start(UPT_SYSCALL_NR(r)); -#endif syscall_trace(r, 0); current->thread.nsyscalls++; @@ -44,7 +40,4 @@ void handle_syscall(union uml_pt_regs *r) REGS_SET_SYSCALL_RETURN(r->skas.regs, result); syscall_trace(r, 1); -#ifdef UML_CONFIG_SYSCALL_DEBUG - record_syscall_end(index, result); -#endif } diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c deleted file mode 100644 index 1731d90e6850..000000000000 --- a/arch/um/kernel/syscall.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include "kern_util.h" -#include "syscall.h" -#include "os.h" - -struct { - int syscall; - int pid; - long result; - unsigned long long start; - unsigned long long end; -} syscall_record[1024]; - -int record_syscall_start(int syscall) -{ - int max, index; - - max = sizeof(syscall_record)/sizeof(syscall_record[0]); - index = next_syscall_index(max); - - syscall_record[index].syscall = syscall; - syscall_record[index].pid = current_pid(); - syscall_record[index].result = 0xdeadbeef; - syscall_record[index].start = os_nsecs(); - return(index); -} - -void record_syscall_end(int index, long result) -{ - syscall_record[index].result = result; - syscall_record[index].end = os_nsecs(); -} diff --git a/arch/um/kernel/tt/syscall_kern.c b/arch/um/kernel/tt/syscall_kern.c index 3fda9a03c59a..293caa6d0c2d 100644 --- a/arch/um/kernel/tt/syscall_kern.c +++ b/arch/um/kernel/tt/syscall_kern.c @@ -21,18 +21,11 @@ void syscall_handler_tt(int sig, struct pt_regs *regs) void *sc; long result; int syscall; -#ifdef CONFIG_SYSCALL_DEBUG - int index; -#endif + sc = UPT_SC(®s->regs); SC_START_SYSCALL(sc); syscall = UPT_SYSCALL_NR(®s->regs); - -#ifdef CONFIG_SYSCALL_DEBUG - index = record_syscall_start(syscall); -#endif - syscall_trace(®s->regs, 0); current->thread.nsyscalls++; @@ -50,7 +43,4 @@ void syscall_handler_tt(int sig, struct pt_regs *regs) SC_SET_SYSCALL_RETURN(sc, result); syscall_trace(®s->regs, 1); -#ifdef CONFIG_SYSCALL_DEBUG - record_syscall_end(index, result); -#endif } diff --git a/arch/um/kernel/tt/tracer.c b/arch/um/kernel/tt/tracer.c index 71daae24e48a..9882342206ec 100644 --- a/arch/um/kernel/tt/tracer.c +++ b/arch/um/kernel/tt/tracer.c @@ -188,10 +188,7 @@ int tracer(int (*init_proc)(void *), void *sp) int status, pid = 0, sig = 0, cont_type, tracing = 0, op = 0; int proc_id = 0, n, err, old_tracing = 0, strace = 0; int local_using_sysemu = 0; -#ifdef UML_CONFIG_SYSCALL_DEBUG - unsigned long eip = 0; - int last_index; -#endif + signal(SIGPIPE, SIG_IGN); setup_tracer_winch(); tracing_pid = os_getpid(); @@ -282,23 +279,6 @@ int tracer(int (*init_proc)(void *), void *sp) else if(WIFSTOPPED(status)){ proc_id = pid_to_processor_id(pid); sig = WSTOPSIG(status); -#ifdef UML_CONFIG_SYSCALL_DEBUG - if(signal_index[proc_id] == 1024){ - signal_index[proc_id] = 0; - last_index = 1023; - } - else last_index = signal_index[proc_id] - 1; - if(((sig == SIGPROF) || (sig == SIGVTALRM) || - (sig == SIGALRM)) && - (signal_record[proc_id][last_index].signal == sig)&& - (signal_record[proc_id][last_index].pid == pid)) - signal_index[proc_id] = last_index; - signal_record[proc_id][signal_index[proc_id]].pid = pid; - gettimeofday(&signal_record[proc_id][signal_index[proc_id]].time, NULL); - eip = ptrace(PTRACE_PEEKUSR, pid, PT_IP_OFFSET, 0); - signal_record[proc_id][signal_index[proc_id]].addr = eip; - signal_record[proc_id][signal_index[proc_id]++].signal = sig; -#endif if(proc_id == -1){ sleeping_process_signal(pid, sig); continue; -- cgit v1.2.3-55-g7522 From 1d3468a6643a6a5905e2ac9ae1fa1aefc06d882a Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Mon, 10 Jul 2006 04:45:13 -0700 Subject: [PATCH] uml: move _kern.c files Move most *_kern.c files in arch/um/kernel to *.c. This makes UML somewhat more closely resemble the other arches. [akpm@osdl.org: use the new INTF_* flags] Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/kernel/Makefile | 9 +- arch/um/kernel/exec.c | 86 +++++++++++++++ arch/um/kernel/exec_kern.c | 77 ------------- arch/um/kernel/sigio.c | 55 +++++++++ arch/um/kernel/sigio_kern.c | 55 --------- arch/um/kernel/signal.c | 191 ++++++++++++++++++++++++++++++++ arch/um/kernel/signal_kern.c | 191 -------------------------------- arch/um/kernel/syscall.c | 166 ++++++++++++++++++++++++++++ arch/um/kernel/syscall_kern.c | 166 ---------------------------- arch/um/kernel/time.c | 182 ++++++++++++++++++++++++++++++ arch/um/kernel/time_kern.c | 182 ------------------------------ arch/um/kernel/trap.c | 251 ++++++++++++++++++++++++++++++++++++++++++ arch/um/kernel/trap_kern.c | 251 ------------------------------------------ 13 files changed, 935 insertions(+), 927 deletions(-) create mode 100644 arch/um/kernel/exec.c delete mode 100644 arch/um/kernel/exec_kern.c create mode 100644 arch/um/kernel/sigio.c delete mode 100644 arch/um/kernel/sigio_kern.c create mode 100644 arch/um/kernel/signal.c delete mode 100644 arch/um/kernel/signal_kern.c create mode 100644 arch/um/kernel/syscall.c delete mode 100644 arch/um/kernel/syscall_kern.c create mode 100644 arch/um/kernel/time.c delete mode 100644 arch/um/kernel/time_kern.c create mode 100644 arch/um/kernel/trap.c delete mode 100644 arch/um/kernel/trap_kern.c (limited to 'arch/um/kernel') diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index 82b435897256..a2d93065b2d0 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -6,11 +6,10 @@ extra-y := vmlinux.lds clean-files := -obj-y = config.o exec_kern.o exitcode.o \ - init_task.o irq.o ksyms.o mem.o physmem.o \ - process_kern.o ptrace.o reboot.o resource.o sigio_kern.o \ - signal_kern.o smp.o syscall_kern.o sysrq.o \ - time_kern.o tlb.o trap_kern.o uaccess.o um_arch.o umid.o +obj-y = config.o exec.o exitcode.o init_task.o irq.o ksyms.o mem.o \ + physmem.o process_kern.o ptrace.o reboot.o resource.o sigio.o \ + signal.o smp.o syscall.o sysrq.o time.o tlb.o trap.o uaccess.o \ + um_arch.o umid.o obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += gprof_syms.o diff --git a/arch/um/kernel/exec.c b/arch/um/kernel/exec.c new file mode 100644 index 000000000000..fc38a6d5906d --- /dev/null +++ b/arch/um/kernel/exec.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/slab.h" +#include "linux/smp_lock.h" +#include "linux/ptrace.h" +#include "asm/ptrace.h" +#include "asm/pgtable.h" +#include "asm/tlbflush.h" +#include "asm/uaccess.h" +#include "user_util.h" +#include "kern_util.h" +#include "mem_user.h" +#include "kern.h" +#include "irq_user.h" +#include "tlb.h" +#include "os.h" +#include "choose-mode.h" +#include "mode_kern.h" + +void flush_thread(void) +{ + arch_flush_thread(¤t->thread.arch); + CHOOSE_MODE(flush_thread_tt(), flush_thread_skas()); +} + +void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp) +{ + CHOOSE_MODE_PROC(start_thread_tt, start_thread_skas, regs, eip, esp); +} + +#ifdef CONFIG_TTY_LOG +extern void log_exec(char **argv, void *tty); +#endif + +static long execve1(char *file, char __user * __user *argv, + char __user *__user *env) +{ + long error; + +#ifdef CONFIG_TTY_LOG + task_lock(current); + log_exec(argv, current->signal->tty); + task_unlock(current); +#endif + error = do_execve(file, argv, env, ¤t->thread.regs); + if (error == 0){ + task_lock(current); + current->ptrace &= ~PT_DTRACE; +#ifdef SUBARCH_EXECVE1 + SUBARCH_EXECVE1(¤t->thread.regs.regs); +#endif + task_unlock(current); + set_cmdline(current_cmd()); + } + return(error); +} + +long um_execve(char *file, char __user *__user *argv, char __user *__user *env) +{ + long err; + + err = execve1(file, argv, env); + if(!err) + do_longjmp(current->thread.exec_buf, 1); + return(err); +} + +long sys_execve(char __user *file, char __user *__user *argv, + char __user *__user *env) +{ + long error; + char *filename; + + lock_kernel(); + filename = getname(file); + error = PTR_ERR(filename); + if (IS_ERR(filename)) goto out; + error = execve1(filename, argv, env); + putname(filename); + out: + unlock_kernel(); + return(error); +} diff --git a/arch/um/kernel/exec_kern.c b/arch/um/kernel/exec_kern.c deleted file mode 100644 index c0cb627bf594..000000000000 --- a/arch/um/kernel/exec_kern.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include "linux/slab.h" -#include "linux/smp_lock.h" -#include "linux/ptrace.h" -#include "asm/ptrace.h" -#include "asm/pgtable.h" -#include "asm/tlbflush.h" -#include "asm/uaccess.h" -#include "user_util.h" -#include "kern_util.h" -#include "mem_user.h" -#include "kern.h" -#include "irq_user.h" -#include "tlb.h" -#include "os.h" -#include "choose-mode.h" -#include "mode_kern.h" - -void flush_thread(void) -{ - arch_flush_thread(¤t->thread.arch); - CHOOSE_MODE(flush_thread_tt(), flush_thread_skas()); -} - -void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp) -{ - CHOOSE_MODE_PROC(start_thread_tt, start_thread_skas, regs, eip, esp); -} - -static long execve1(char *file, char __user * __user *argv, - char __user *__user *env) -{ - long error; - -#ifdef CONFIG_TTY_LOG - log_exec(argv, current->tty); -#endif - error = do_execve(file, argv, env, ¤t->thread.regs); - if (error == 0){ - task_lock(current); - current->ptrace &= ~PT_DTRACE; - task_unlock(current); - set_cmdline(current_cmd()); - } - return(error); -} - -long um_execve(char *file, char __user *__user *argv, char __user *__user *env) -{ - long err; - - err = execve1(file, argv, env); - if(!err) - do_longjmp(current->thread.exec_buf, 1); - return(err); -} - -long sys_execve(char __user *file, char __user *__user *argv, - char __user *__user *env) -{ - long error; - char *filename; - - lock_kernel(); - filename = getname(file); - error = PTR_ERR(filename); - if (IS_ERR(filename)) goto out; - error = execve1(filename, argv, env); - putname(filename); - out: - unlock_kernel(); - return(error); -} diff --git a/arch/um/kernel/sigio.c b/arch/um/kernel/sigio.c new file mode 100644 index 000000000000..0ad755ceb212 --- /dev/null +++ b/arch/um/kernel/sigio.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "linux/list.h" +#include "linux/slab.h" +#include "linux/signal.h" +#include "linux/interrupt.h" +#include "init.h" +#include "sigio.h" +#include "irq_user.h" +#include "irq_kern.h" +#include "os.h" + +/* Protected by sigio_lock() called from write_sigio_workaround */ +static int sigio_irq_fd = -1; + +static irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused) +{ + char c; + + os_read_file(sigio_irq_fd, &c, sizeof(c)); + reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ); + return(IRQ_HANDLED); +} + +int write_sigio_irq(int fd) +{ + int err; + + err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt, + IRQF_DISABLED|IRQF_SAMPLE_RANDOM, "write sigio", + NULL); + if(err){ + printk("write_sigio_irq : um_request_irq failed, err = %d\n", + err); + return(-1); + } + sigio_irq_fd = fd; + return(0); +} + +static DEFINE_SPINLOCK(sigio_spinlock); + +void sigio_lock(void) +{ + spin_lock(&sigio_spinlock); +} + +void sigio_unlock(void) +{ + spin_unlock(&sigio_spinlock); +} diff --git a/arch/um/kernel/sigio_kern.c b/arch/um/kernel/sigio_kern.c deleted file mode 100644 index 5102ba5d5bd0..000000000000 --- a/arch/um/kernel/sigio_kern.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com) - * Licensed under the GPL - */ - -#include "linux/kernel.h" -#include "linux/list.h" -#include "linux/slab.h" -#include "linux/signal.h" -#include "linux/interrupt.h" -#include "init.h" -#include "sigio.h" -#include "irq_user.h" -#include "irq_kern.h" -#include "os.h" - -/* Protected by sigio_lock() called from write_sigio_workaround */ -static int sigio_irq_fd = -1; - -static irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused) -{ - char c; - - os_read_file(sigio_irq_fd, &c, sizeof(c)); - reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ); - return(IRQ_HANDLED); -} - -int write_sigio_irq(int fd) -{ - int err; - - err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt, - IRQF_DISABLED | IRQF_SAMPLE_RANDOM, "write sigio", - NULL); - if(err){ - printk("write_sigio_irq : um_request_irq failed, err = %d\n", - err); - return(-1); - } - sigio_irq_fd = fd; - return(0); -} - -static DEFINE_SPINLOCK(sigio_spinlock); - -void sigio_lock(void) -{ - spin_lock(&sigio_spinlock); -} - -void sigio_unlock(void) -{ - spin_unlock(&sigio_spinlock); -} diff --git a/arch/um/kernel/signal.c b/arch/um/kernel/signal.c new file mode 100644 index 000000000000..4aa9808ba264 --- /dev/null +++ b/arch/um/kernel/signal.c @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/config.h" +#include "linux/stddef.h" +#include "linux/sys.h" +#include "linux/sched.h" +#include "linux/wait.h" +#include "linux/kernel.h" +#include "linux/smp_lock.h" +#include "linux/module.h" +#include "linux/slab.h" +#include "linux/tty.h" +#include "linux/binfmts.h" +#include "linux/ptrace.h" +#include "asm/signal.h" +#include "asm/uaccess.h" +#include "asm/unistd.h" +#include "user_util.h" +#include "asm/ucontext.h" +#include "kern_util.h" +#include "signal_kern.h" +#include "kern.h" +#include "frame_kern.h" +#include "sigcontext.h" +#include "mode.h" + +EXPORT_SYMBOL(block_signals); +EXPORT_SYMBOL(unblock_signals); + +#define _S(nr) (1<<((nr)-1)) + +#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP))) + +/* + * OK, we're invoking a handler + */ +static int handle_signal(struct pt_regs *regs, unsigned long signr, + struct k_sigaction *ka, siginfo_t *info, + sigset_t *oldset) +{ + unsigned long sp; + int err; + + /* Always make any pending restarted system calls return -EINTR */ + current_thread_info()->restart_block.fn = do_no_restart_syscall; + + /* Did we come from a system call? */ + if(PT_REGS_SYSCALL_NR(regs) >= 0){ + /* If so, check system call restarting.. */ + switch(PT_REGS_SYSCALL_RET(regs)){ + case -ERESTART_RESTARTBLOCK: + case -ERESTARTNOHAND: + PT_REGS_SYSCALL_RET(regs) = -EINTR; + break; + + case -ERESTARTSYS: + if (!(ka->sa.sa_flags & SA_RESTART)) { + PT_REGS_SYSCALL_RET(regs) = -EINTR; + break; + } + /* fallthrough */ + case -ERESTARTNOINTR: + PT_REGS_RESTART_SYSCALL(regs); + PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs); + break; + } + } + + sp = PT_REGS_SP(regs); + if((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0)) + sp = current->sas_ss_sp + current->sas_ss_size; + +#ifdef CONFIG_ARCH_HAS_SC_SIGNALS + if(!(ka->sa.sa_flags & SA_SIGINFO)) + err = setup_signal_stack_sc(sp, signr, ka, regs, oldset); + else +#endif + err = setup_signal_stack_si(sp, signr, ka, regs, info, oldset); + + if(err){ + spin_lock_irq(¤t->sighand->siglock); + current->blocked = *oldset; + recalc_sigpending(); + spin_unlock_irq(¤t->sighand->siglock); + force_sigsegv(signr, current); + } else { + spin_lock_irq(¤t->sighand->siglock); + sigorsets(¤t->blocked, ¤t->blocked, + &ka->sa.sa_mask); + if(!(ka->sa.sa_flags & SA_NODEFER)) + sigaddset(¤t->blocked, signr); + recalc_sigpending(); + spin_unlock_irq(¤t->sighand->siglock); + } + + return err; +} + +static int kern_do_signal(struct pt_regs *regs) +{ + struct k_sigaction ka_copy; + siginfo_t info; + sigset_t *oldset; + int sig, handled_sig = 0; + + if (test_thread_flag(TIF_RESTORE_SIGMASK)) + oldset = ¤t->saved_sigmask; + else + oldset = ¤t->blocked; + + while((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0){ + handled_sig = 1; + /* Whee! Actually deliver the signal. */ + if(!handle_signal(regs, sig, &ka_copy, &info, oldset)){ + /* a signal was successfully delivered; the saved + * sigmask will have been stored in the signal frame, + * and will be restored by sigreturn, so we can simply + * clear the TIF_RESTORE_SIGMASK flag */ + if (test_thread_flag(TIF_RESTORE_SIGMASK)) + clear_thread_flag(TIF_RESTORE_SIGMASK); + break; + } + } + + /* Did we come from a system call? */ + if(!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)){ + /* Restart the system call - no handlers present */ + switch(PT_REGS_SYSCALL_RET(regs)){ + case -ERESTARTNOHAND: + case -ERESTARTSYS: + case -ERESTARTNOINTR: + PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs); + PT_REGS_RESTART_SYSCALL(regs); + break; + case -ERESTART_RESTARTBLOCK: + PT_REGS_ORIG_SYSCALL(regs) = __NR_restart_syscall; + PT_REGS_RESTART_SYSCALL(regs); + break; + } + } + + /* This closes a way to execute a system call on the host. If + * you set a breakpoint on a system call instruction and singlestep + * from it, the tracing thread used to PTRACE_SINGLESTEP the process + * rather than PTRACE_SYSCALL it, allowing the system call to execute + * on the host. The tracing thread will check this flag and + * PTRACE_SYSCALL if necessary. + */ + if(current->ptrace & PT_DTRACE) + current->thread.singlestep_syscall = + is_syscall(PT_REGS_IP(¤t->thread.regs)); + + /* if there's no signal to deliver, we just put the saved sigmask + * back */ + if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) { + clear_thread_flag(TIF_RESTORE_SIGMASK); + sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); + } + return(handled_sig); +} + +int do_signal(void) +{ + return(kern_do_signal(¤t->thread.regs)); +} + +/* + * Atomically swap in the new signal mask, and wait for a signal. + */ +long sys_sigsuspend(int history0, int history1, old_sigset_t mask) +{ + mask &= _BLOCKABLE; + spin_lock_irq(¤t->sighand->siglock); + current->saved_sigmask = current->blocked; + siginitset(¤t->blocked, mask); + recalc_sigpending(); + spin_unlock_irq(¤t->sighand->siglock); + + current->state = TASK_INTERRUPTIBLE; + schedule(); + set_thread_flag(TIF_RESTORE_SIGMASK); + return -ERESTARTNOHAND; +} + +long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss) +{ + return(do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs))); +} diff --git a/arch/um/kernel/signal_kern.c b/arch/um/kernel/signal_kern.c deleted file mode 100644 index da17b7541e08..000000000000 --- a/arch/um/kernel/signal_kern.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include "linux/config.h" -#include "linux/stddef.h" -#include "linux/sys.h" -#include "linux/sched.h" -#include "linux/wait.h" -#include "linux/kernel.h" -#include "linux/smp_lock.h" -#include "linux/module.h" -#include "linux/slab.h" -#include "linux/tty.h" -#include "linux/binfmts.h" -#include "linux/ptrace.h" -#include "asm/signal.h" -#include "asm/uaccess.h" -#include "asm/unistd.h" -#include "user_util.h" -#include "asm/ucontext.h" -#include "kern_util.h" -#include "signal_kern.h" -#include "kern.h" -#include "frame_kern.h" -#include "sigcontext.h" -#include "mode.h" - -EXPORT_SYMBOL(block_signals); -EXPORT_SYMBOL(unblock_signals); - -#define _S(nr) (1<<((nr)-1)) - -#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP))) - -/* - * OK, we're invoking a handler - */ -static int handle_signal(struct pt_regs *regs, unsigned long signr, - struct k_sigaction *ka, siginfo_t *info, - sigset_t *oldset) -{ - unsigned long sp; - int err; - - /* Always make any pending restarted system calls return -EINTR */ - current_thread_info()->restart_block.fn = do_no_restart_syscall; - - /* Did we come from a system call? */ - if(PT_REGS_SYSCALL_NR(regs) >= 0){ - /* If so, check system call restarting.. */ - switch(PT_REGS_SYSCALL_RET(regs)){ - case -ERESTART_RESTARTBLOCK: - case -ERESTARTNOHAND: - PT_REGS_SYSCALL_RET(regs) = -EINTR; - break; - - case -ERESTARTSYS: - if (!(ka->sa.sa_flags & SA_RESTART)) { - PT_REGS_SYSCALL_RET(regs) = -EINTR; - break; - } - /* fallthrough */ - case -ERESTARTNOINTR: - PT_REGS_RESTART_SYSCALL(regs); - PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs); - break; - } - } - - sp = PT_REGS_SP(regs); - if((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0)) - sp = current->sas_ss_sp + current->sas_ss_size; - -#ifdef CONFIG_ARCH_HAS_SC_SIGNALS - if(!(ka->sa.sa_flags & SA_SIGINFO)) - err = setup_signal_stack_sc(sp, signr, ka, regs, oldset); - else -#endif - err = setup_signal_stack_si(sp, signr, ka, regs, info, oldset); - - if(err){ - spin_lock_irq(¤t->sighand->siglock); - current->blocked = *oldset; - recalc_sigpending(); - spin_unlock_irq(¤t->sighand->siglock); - force_sigsegv(signr, current); - } else { - spin_lock_irq(¤t->sighand->siglock); - sigorsets(¤t->blocked, ¤t->blocked, - &ka->sa.sa_mask); - if(!(ka->sa.sa_flags & SA_NODEFER)) - sigaddset(¤t->blocked, signr); - recalc_sigpending(); - spin_unlock_irq(¤t->sighand->siglock); - } - - return err; -} - -static int kern_do_signal(struct pt_regs *regs) -{ - struct k_sigaction ka_copy; - siginfo_t info; - sigset_t *oldset; - int sig, handled_sig = 0; - - if (test_thread_flag(TIF_RESTORE_SIGMASK)) - oldset = ¤t->saved_sigmask; - else - oldset = ¤t->blocked; - - while((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0){ - handled_sig = 1; - /* Whee! Actually deliver the signal. */ - if(!handle_signal(regs, sig, &ka_copy, &info, oldset)){ - /* a signal was successfully delivered; the saved - * sigmask will have been stored in the signal frame, - * and will be restored by sigreturn, so we can simply - * clear the TIF_RESTORE_SIGMASK flag */ - if (test_thread_flag(TIF_RESTORE_SIGMASK)) - clear_thread_flag(TIF_RESTORE_SIGMASK); - break; - } - } - - /* Did we come from a system call? */ - if(!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)){ - /* Restart the system call - no handlers present */ - switch(PT_REGS_SYSCALL_RET(regs)){ - case -ERESTARTNOHAND: - case -ERESTARTSYS: - case -ERESTARTNOINTR: - PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs); - PT_REGS_RESTART_SYSCALL(regs); - break; - case -ERESTART_RESTARTBLOCK: - PT_REGS_SYSCALL_RET(regs) = __NR_restart_syscall; - PT_REGS_RESTART_SYSCALL(regs); - break; - } - } - - /* This closes a way to execute a system call on the host. If - * you set a breakpoint on a system call instruction and singlestep - * from it, the tracing thread used to PTRACE_SINGLESTEP the process - * rather than PTRACE_SYSCALL it, allowing the system call to execute - * on the host. The tracing thread will check this flag and - * PTRACE_SYSCALL if necessary. - */ - if(current->ptrace & PT_DTRACE) - current->thread.singlestep_syscall = - is_syscall(PT_REGS_IP(¤t->thread.regs)); - - /* if there's no signal to deliver, we just put the saved sigmask - * back */ - if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) { - clear_thread_flag(TIF_RESTORE_SIGMASK); - sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); - } - return(handled_sig); -} - -int do_signal(void) -{ - return(kern_do_signal(¤t->thread.regs)); -} - -/* - * Atomically swap in the new signal mask, and wait for a signal. - */ -long sys_sigsuspend(int history0, int history1, old_sigset_t mask) -{ - mask &= _BLOCKABLE; - spin_lock_irq(¤t->sighand->siglock); - current->saved_sigmask = current->blocked; - siginitset(¤t->blocked, mask); - recalc_sigpending(); - spin_unlock_irq(¤t->sighand->siglock); - - current->state = TASK_INTERRUPTIBLE; - schedule(); - set_thread_flag(TIF_RESTORE_SIGMASK); - return -ERESTARTNOHAND; -} - -long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss) -{ - return(do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs))); -} diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c new file mode 100644 index 000000000000..abf14aaf905f --- /dev/null +++ b/arch/um/kernel/syscall.c @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com) + * Licensed under the GPL + */ + +#include "linux/sched.h" +#include "linux/file.h" +#include "linux/smp_lock.h" +#include "linux/mm.h" +#include "linux/utsname.h" +#include "linux/msg.h" +#include "linux/shm.h" +#include "linux/sys.h" +#include "linux/syscalls.h" +#include "linux/unistd.h" +#include "linux/slab.h" +#include "linux/utime.h" +#include "asm/mman.h" +#include "asm/uaccess.h" +#include "kern_util.h" +#include "user_util.h" +#include "sysdep/syscalls.h" +#include "mode_kern.h" +#include "choose-mode.h" + +/* Unlocked, I don't care if this is a bit off */ +int nsyscalls = 0; + +long sys_fork(void) +{ + long ret; + + current->thread.forking = 1; + ret = do_fork(SIGCHLD, UPT_SP(¤t->thread.regs.regs), + ¤t->thread.regs, 0, NULL, NULL); + current->thread.forking = 0; + return(ret); +} + +long sys_vfork(void) +{ + long ret; + + current->thread.forking = 1; + ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, + UPT_SP(¤t->thread.regs.regs), + ¤t->thread.regs, 0, NULL, NULL); + current->thread.forking = 0; + return(ret); +} + +/* common code for old and new mmaps */ +long sys_mmap2(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long pgoff) +{ + long error = -EBADF; + struct file * file = NULL; + + flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); + if (!(flags & MAP_ANONYMOUS)) { + file = fget(fd); + if (!file) + goto out; + } + + down_write(¤t->mm->mmap_sem); + error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); + up_write(¤t->mm->mmap_sem); + + if (file) + fput(file); + out: + return error; +} + +long old_mmap(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long offset) +{ + long err = -EINVAL; + if (offset & ~PAGE_MASK) + goto out; + + err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); + out: + return err; +} +/* + * sys_pipe() is the normal C calling standard for creating + * a pipe. It's not the way unix traditionally does this, though. + */ +long sys_pipe(unsigned long __user * fildes) +{ + int fd[2]; + long error; + + error = do_pipe(fd); + if (!error) { + if (copy_to_user(fildes, fd, sizeof(fd))) + error = -EFAULT; + } + return error; +} + + +long sys_uname(struct old_utsname __user * name) +{ + long err; + if (!name) + return -EFAULT; + down_read(&uts_sem); + err = copy_to_user(name, utsname(), sizeof (*name)); + up_read(&uts_sem); + return err?-EFAULT:0; +} + +long sys_olduname(struct oldold_utsname __user * name) +{ + long error; + + if (!name) + return -EFAULT; + if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) + return -EFAULT; + + down_read(&uts_sem); + + error = __copy_to_user(&name->sysname, &utsname()->sysname, + __OLD_UTS_LEN); + error |= __put_user(0, name->sysname + __OLD_UTS_LEN); + error |= __copy_to_user(&name->nodename, &utsname()->nodename, + __OLD_UTS_LEN); + error |= __put_user(0, name->nodename + __OLD_UTS_LEN); + error |= __copy_to_user(&name->release, &utsname()->release, + __OLD_UTS_LEN); + error |= __put_user(0, name->release + __OLD_UTS_LEN); + error |= __copy_to_user(&name->version, &utsname()->version, + __OLD_UTS_LEN); + error |= __put_user(0, name->version + __OLD_UTS_LEN); + error |= __copy_to_user(&name->machine, &utsname()->machine, + __OLD_UTS_LEN); + error |= __put_user(0, name->machine + __OLD_UTS_LEN); + + up_read(&uts_sem); + + error = error ? -EFAULT : 0; + + return error; +} + +DEFINE_SPINLOCK(syscall_lock); + +static int syscall_index = 0; + +int next_syscall_index(int limit) +{ + int ret; + + spin_lock(&syscall_lock); + ret = syscall_index; + if(++syscall_index == limit) + syscall_index = 0; + spin_unlock(&syscall_lock); + return(ret); +} diff --git a/arch/um/kernel/syscall_kern.c b/arch/um/kernel/syscall_kern.c deleted file mode 100644 index 37d3978337d8..000000000000 --- a/arch/um/kernel/syscall_kern.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com) - * Licensed under the GPL - */ - -#include "linux/sched.h" -#include "linux/file.h" -#include "linux/smp_lock.h" -#include "linux/mm.h" -#include "linux/utsname.h" -#include "linux/msg.h" -#include "linux/shm.h" -#include "linux/sys.h" -#include "linux/syscalls.h" -#include "linux/unistd.h" -#include "linux/slab.h" -#include "linux/utime.h" -#include "asm/mman.h" -#include "asm/uaccess.h" -#include "kern_util.h" -#include "user_util.h" -#include "sysdep/syscalls.h" -#include "mode_kern.h" -#include "choose-mode.h" - -/* Unlocked, I don't care if this is a bit off */ -int nsyscalls = 0; - -long sys_fork(void) -{ - long ret; - - current->thread.forking = 1; - ret = do_fork(SIGCHLD, UPT_SP(¤t->thread.regs.regs), - ¤t->thread.regs, 0, NULL, NULL); - current->thread.forking = 0; - return(ret); -} - -long sys_vfork(void) -{ - long ret; - - current->thread.forking = 1; - ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, - UPT_SP(¤t->thread.regs.regs), - ¤t->thread.regs, 0, NULL, NULL); - current->thread.forking = 0; - return(ret); -} - -/* common code for old and new mmaps */ -long sys_mmap2(unsigned long addr, unsigned long len, - unsigned long prot, unsigned long flags, - unsigned long fd, unsigned long pgoff) -{ - long error = -EBADF; - struct file * file = NULL; - - flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); - if (!(flags & MAP_ANONYMOUS)) { - file = fget(fd); - if (!file) - goto out; - } - - down_write(¤t->mm->mmap_sem); - error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); - up_write(¤t->mm->mmap_sem); - - if (file) - fput(file); - out: - return error; -} - -long old_mmap(unsigned long addr, unsigned long len, - unsigned long prot, unsigned long flags, - unsigned long fd, unsigned long offset) -{ - long err = -EINVAL; - if (offset & ~PAGE_MASK) - goto out; - - err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); - out: - return err; -} -/* - * sys_pipe() is the normal C calling standard for creating - * a pipe. It's not the way unix traditionally does this, though. - */ -long sys_pipe(unsigned long __user * fildes) -{ - int fd[2]; - long error; - - error = do_pipe(fd); - if (!error) { - if (copy_to_user(fildes, fd, sizeof(fd))) - error = -EFAULT; - } - return error; -} - - -long sys_uname(struct old_utsname __user * name) -{ - long err; - if (!name) - return -EFAULT; - down_read(&uts_sem); - err=copy_to_user(name, &system_utsname, sizeof (*name)); - up_read(&uts_sem); - return err?-EFAULT:0; -} - -long sys_olduname(struct oldold_utsname __user * name) -{ - long error; - - if (!name) - return -EFAULT; - if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) - return -EFAULT; - - down_read(&uts_sem); - - error = __copy_to_user(&name->sysname,&system_utsname.sysname, - __OLD_UTS_LEN); - error |= __put_user(0,name->sysname+__OLD_UTS_LEN); - error |= __copy_to_user(&name->nodename,&system_utsname.nodename, - __OLD_UTS_LEN); - error |= __put_user(0,name->nodename+__OLD_UTS_LEN); - error |= __copy_to_user(&name->release,&system_utsname.release, - __OLD_UTS_LEN); - error |= __put_user(0,name->release+__OLD_UTS_LEN); - error |= __copy_to_user(&name->version,&system_utsname.version, - __OLD_UTS_LEN); - error |= __put_user(0,name->version+__OLD_UTS_LEN); - error |= __copy_to_user(&name->machine,&system_utsname.machine, - __OLD_UTS_LEN); - error |= __put_user(0,name->machine+__OLD_UTS_LEN); - - up_read(&uts_sem); - - error = error ? -EFAULT : 0; - - return error; -} - -DEFINE_SPINLOCK(syscall_lock); - -static int syscall_index = 0; - -int next_syscall_index(int limit) -{ - int ret; - - spin_lock(&syscall_lock); - ret = syscall_index; - if(++syscall_index == limit) - syscall_index = 0; - spin_unlock(&syscall_lock); - return(ret); -} diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c new file mode 100644 index 000000000000..552ca1cb9847 --- /dev/null +++ b/arch/um/kernel/time.c @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "linux/module.h" +#include "linux/unistd.h" +#include "linux/stddef.h" +#include "linux/spinlock.h" +#include "linux/time.h" +#include "linux/sched.h" +#include "linux/interrupt.h" +#include "linux/init.h" +#include "linux/delay.h" +#include "linux/hrtimer.h" +#include "asm/irq.h" +#include "asm/param.h" +#include "asm/current.h" +#include "kern_util.h" +#include "user_util.h" +#include "mode.h" +#include "os.h" + +int hz(void) +{ + return(HZ); +} + +/* + * Scheduler clock - returns current time in nanosec units. + */ +unsigned long long sched_clock(void) +{ + return (unsigned long long)jiffies_64 * (1000000000 / HZ); +} + +/* Changed at early boot */ +int timer_irq_inited = 0; + +static unsigned long long prev_nsecs; +#ifdef CONFIG_UML_REAL_TIME_CLOCK +static long long delta; /* Deviation per interval */ +#endif + +void timer_irq(union uml_pt_regs *regs) +{ + unsigned long long ticks = 0; + +#ifdef CONFIG_UML_REAL_TIME_CLOCK + if(prev_nsecs){ + /* We've had 1 tick */ + unsigned long long nsecs = os_nsecs(); + + delta += nsecs - prev_nsecs; + prev_nsecs = nsecs; + + /* Protect against the host clock being set backwards */ + if(delta < 0) + delta = 0; + + ticks += (delta * HZ) / BILLION; + delta -= (ticks * BILLION) / HZ; + } + else prev_nsecs = os_nsecs(); +#else + ticks = 1; +#endif + while(ticks > 0){ + do_IRQ(TIMER_IRQ, regs); + ticks--; + } +} + +static DEFINE_SPINLOCK(timer_spinlock); + +static unsigned long long local_offset = 0; + +static inline unsigned long long get_time(void) +{ + unsigned long long nsecs; + unsigned long flags; + + spin_lock_irqsave(&timer_spinlock, flags); + nsecs = os_nsecs(); + nsecs += local_offset; + spin_unlock_irqrestore(&timer_spinlock, flags); + + return nsecs; +} + +irqreturn_t um_timer(int irq, void *dev, struct pt_regs *regs) +{ + unsigned long long nsecs; + unsigned long flags; + + write_seqlock_irqsave(&xtime_lock, flags); + + do_timer(regs); + + nsecs = get_time() + local_offset; + xtime.tv_sec = nsecs / NSEC_PER_SEC; + xtime.tv_nsec = nsecs - xtime.tv_sec * NSEC_PER_SEC; + + write_sequnlock_irqrestore(&xtime_lock, flags); + + return IRQ_HANDLED; +} + +static void register_timer(void) +{ + int err; + + err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL); + if(err != 0) + printk(KERN_ERR "timer_init : request_irq failed - " + "errno = %d\n", -err); + + timer_irq_inited = 1; + + user_time_init(); +} + +extern void (*late_time_init)(void); + +void time_init(void) +{ + long long nsecs; + + nsecs = os_nsecs(); + set_normalized_timespec(&wall_to_monotonic, -nsecs / BILLION, + -nsecs % BILLION); + late_time_init = register_timer; +} + +void do_gettimeofday(struct timeval *tv) +{ + unsigned long long nsecs = get_time(); + + tv->tv_sec = nsecs / NSEC_PER_SEC; + /* Careful about calculations here - this was originally done as + * (nsecs - tv->tv_sec * NSEC_PER_SEC) / NSEC_PER_USEC + * which gave bogus (> 1000000) values. Dunno why, suspect gcc + * (4.0.0) miscompiled it, or there's a subtle 64/32-bit conversion + * problem that I missed. + */ + nsecs -= tv->tv_sec * NSEC_PER_SEC; + tv->tv_usec = (unsigned long) nsecs / NSEC_PER_USEC; +} + +static inline void set_time(unsigned long long nsecs) +{ + unsigned long long now; + unsigned long flags; + + spin_lock_irqsave(&timer_spinlock, flags); + now = os_nsecs(); + local_offset = nsecs - now; + spin_unlock_irqrestore(&timer_spinlock, flags); + + clock_was_set(); +} + +int do_settimeofday(struct timespec *tv) +{ + set_time((unsigned long long) tv->tv_sec * NSEC_PER_SEC + tv->tv_nsec); + + return 0; +} + +void timer_handler(int sig, union uml_pt_regs *regs) +{ + local_irq_disable(); + irq_enter(); + update_process_times(CHOOSE_MODE( + (UPT_SC(regs) && user_context(UPT_SP(regs))), + (regs)->skas.is_user)); + irq_exit(); + local_irq_enable(); + if(current_thread->cpu == 0) + timer_irq(regs); +} diff --git a/arch/um/kernel/time_kern.c b/arch/um/kernel/time_kern.c deleted file mode 100644 index 552ca1cb9847..000000000000 --- a/arch/um/kernel/time_kern.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include "linux/kernel.h" -#include "linux/module.h" -#include "linux/unistd.h" -#include "linux/stddef.h" -#include "linux/spinlock.h" -#include "linux/time.h" -#include "linux/sched.h" -#include "linux/interrupt.h" -#include "linux/init.h" -#include "linux/delay.h" -#include "linux/hrtimer.h" -#include "asm/irq.h" -#include "asm/param.h" -#include "asm/current.h" -#include "kern_util.h" -#include "user_util.h" -#include "mode.h" -#include "os.h" - -int hz(void) -{ - return(HZ); -} - -/* - * Scheduler clock - returns current time in nanosec units. - */ -unsigned long long sched_clock(void) -{ - return (unsigned long long)jiffies_64 * (1000000000 / HZ); -} - -/* Changed at early boot */ -int timer_irq_inited = 0; - -static unsigned long long prev_nsecs; -#ifdef CONFIG_UML_REAL_TIME_CLOCK -static long long delta; /* Deviation per interval */ -#endif - -void timer_irq(union uml_pt_regs *regs) -{ - unsigned long long ticks = 0; - -#ifdef CONFIG_UML_REAL_TIME_CLOCK - if(prev_nsecs){ - /* We've had 1 tick */ - unsigned long long nsecs = os_nsecs(); - - delta += nsecs - prev_nsecs; - prev_nsecs = nsecs; - - /* Protect against the host clock being set backwards */ - if(delta < 0) - delta = 0; - - ticks += (delta * HZ) / BILLION; - delta -= (ticks * BILLION) / HZ; - } - else prev_nsecs = os_nsecs(); -#else - ticks = 1; -#endif - while(ticks > 0){ - do_IRQ(TIMER_IRQ, regs); - ticks--; - } -} - -static DEFINE_SPINLOCK(timer_spinlock); - -static unsigned long long local_offset = 0; - -static inline unsigned long long get_time(void) -{ - unsigned long long nsecs; - unsigned long flags; - - spin_lock_irqsave(&timer_spinlock, flags); - nsecs = os_nsecs(); - nsecs += local_offset; - spin_unlock_irqrestore(&timer_spinlock, flags); - - return nsecs; -} - -irqreturn_t um_timer(int irq, void *dev, struct pt_regs *regs) -{ - unsigned long long nsecs; - unsigned long flags; - - write_seqlock_irqsave(&xtime_lock, flags); - - do_timer(regs); - - nsecs = get_time() + local_offset; - xtime.tv_sec = nsecs / NSEC_PER_SEC; - xtime.tv_nsec = nsecs - xtime.tv_sec * NSEC_PER_SEC; - - write_sequnlock_irqrestore(&xtime_lock, flags); - - return IRQ_HANDLED; -} - -static void register_timer(void) -{ - int err; - - err = request_irq(TIMER_IRQ, um_timer, IRQF_DISABLED, "timer", NULL); - if(err != 0) - printk(KERN_ERR "timer_init : request_irq failed - " - "errno = %d\n", -err); - - timer_irq_inited = 1; - - user_time_init(); -} - -extern void (*late_time_init)(void); - -void time_init(void) -{ - long long nsecs; - - nsecs = os_nsecs(); - set_normalized_timespec(&wall_to_monotonic, -nsecs / BILLION, - -nsecs % BILLION); - late_time_init = register_timer; -} - -void do_gettimeofday(struct timeval *tv) -{ - unsigned long long nsecs = get_time(); - - tv->tv_sec = nsecs / NSEC_PER_SEC; - /* Careful about calculations here - this was originally done as - * (nsecs - tv->tv_sec * NSEC_PER_SEC) / NSEC_PER_USEC - * which gave bogus (> 1000000) values. Dunno why, suspect gcc - * (4.0.0) miscompiled it, or there's a subtle 64/32-bit conversion - * problem that I missed. - */ - nsecs -= tv->tv_sec * NSEC_PER_SEC; - tv->tv_usec = (unsigned long) nsecs / NSEC_PER_USEC; -} - -static inline void set_time(unsigned long long nsecs) -{ - unsigned long long now; - unsigned long flags; - - spin_lock_irqsave(&timer_spinlock, flags); - now = os_nsecs(); - local_offset = nsecs - now; - spin_unlock_irqrestore(&timer_spinlock, flags); - - clock_was_set(); -} - -int do_settimeofday(struct timespec *tv) -{ - set_time((unsigned long long) tv->tv_sec * NSEC_PER_SEC + tv->tv_nsec); - - return 0; -} - -void timer_handler(int sig, union uml_pt_regs *regs) -{ - local_irq_disable(); - irq_enter(); - update_process_times(CHOOSE_MODE( - (UPT_SC(regs) && user_context(UPT_SP(regs))), - (regs)->skas.is_user)); - irq_exit(); - local_irq_enable(); - if(current_thread->cpu == 0) - timer_irq(regs); -} diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c new file mode 100644 index 000000000000..ac70fa5a2e2a --- /dev/null +++ b/arch/um/kernel/trap.c @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) + * Licensed under the GPL + */ + +#include "linux/kernel.h" +#include "asm/errno.h" +#include "linux/sched.h" +#include "linux/mm.h" +#include "linux/spinlock.h" +#include "linux/config.h" +#include "linux/init.h" +#include "linux/ptrace.h" +#include "asm/semaphore.h" +#include "asm/pgtable.h" +#include "asm/pgalloc.h" +#include "asm/tlbflush.h" +#include "asm/a.out.h" +#include "asm/current.h" +#include "asm/irq.h" +#include "sysdep/sigcontext.h" +#include "user_util.h" +#include "kern_util.h" +#include "kern.h" +#include "chan_kern.h" +#include "mconsole_kern.h" +#include "mem.h" +#include "mem_kern.h" +#include "sysdep/sigcontext.h" +#include "sysdep/ptrace.h" +#include "os.h" +#ifdef CONFIG_MODE_SKAS +#include "skas.h" +#endif +#include "os.h" + +/* Note this is constrained to return 0, -EFAULT, -EACCESS, -ENOMEM by segv(). */ +int handle_page_fault(unsigned long address, unsigned long ip, + int is_write, int is_user, int *code_out) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + int err = -EFAULT; + + *code_out = SEGV_MAPERR; + + /* If the fault was during atomic operation, don't take the fault, just + * fail. */ + if (in_atomic()) + goto out_nosemaphore; + + down_read(&mm->mmap_sem); + vma = find_vma(mm, address); + if(!vma) + goto out; + else if(vma->vm_start <= address) + goto good_area; + else if(!(vma->vm_flags & VM_GROWSDOWN)) + goto out; + else if(is_user && !ARCH_IS_STACKGROW(address)) + goto out; + else if(expand_stack(vma, address)) + goto out; + +good_area: + *code_out = SEGV_ACCERR; + if(is_write && !(vma->vm_flags & VM_WRITE)) + goto out; + + /* Don't require VM_READ|VM_EXEC for write faults! */ + if(!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC))) + goto out; + + do { +survive: + switch (handle_mm_fault(mm, vma, address, is_write)){ + case VM_FAULT_MINOR: + current->min_flt++; + break; + case VM_FAULT_MAJOR: + current->maj_flt++; + break; + case VM_FAULT_SIGBUS: + err = -EACCES; + goto out; + case VM_FAULT_OOM: + err = -ENOMEM; + goto out_of_memory; + default: + BUG(); + } + pgd = pgd_offset(mm, address); + pud = pud_offset(pgd, address); + pmd = pmd_offset(pud, address); + pte = pte_offset_kernel(pmd, address); + } while(!pte_present(*pte)); + err = 0; + /* The below warning was added in place of + * pte_mkyoung(); if (is_write) pte_mkdirty(); + * If it's triggered, we'd see normally a hang here (a clean pte is + * marked read-only to emulate the dirty bit). + * However, the generic code can mark a PTE writable but clean on a + * concurrent read fault, triggering this harmlessly. So comment it out. + */ +#if 0 + WARN_ON(!pte_young(*pte) || (is_write && !pte_dirty(*pte))); +#endif + flush_tlb_page(vma, address); +out: + up_read(&mm->mmap_sem); +out_nosemaphore: + return(err); + +/* + * We ran out of memory, or some other thing happened to us that made + * us unable to handle the page fault gracefully. + */ +out_of_memory: + if (current->pid == 1) { + up_read(&mm->mmap_sem); + yield(); + down_read(&mm->mmap_sem); + goto survive; + } + goto out; +} + +void segv_handler(int sig, union uml_pt_regs *regs) +{ + struct faultinfo * fi = UPT_FAULTINFO(regs); + + if(UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)){ + bad_segv(*fi, UPT_IP(regs)); + return; + } + segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs); +} + +struct kern_handlers handlinfo_kern = { + .relay_signal = relay_signal, + .winch = winch, + .bus_handler = relay_signal, + .page_fault = segv_handler, + .sigio_handler = sigio_handler, + .timer_handler = timer_handler +}; +/* + * We give a *copy* of the faultinfo in the regs to segv. + * This must be done, since nesting SEGVs could overwrite + * the info in the regs. A pointer to the info then would + * give us bad data! + */ +unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc) +{ + struct siginfo si; + void *catcher; + int err; + int is_write = FAULT_WRITE(fi); + unsigned long address = FAULT_ADDRESS(fi); + + if(!is_user && (address >= start_vm) && (address < end_vm)){ + flush_tlb_kernel_vm(); + return(0); + } + else if(current->mm == NULL) + panic("Segfault with no mm"); + + if (SEGV_IS_FIXABLE(&fi) || SEGV_MAYBE_FIXABLE(&fi)) + err = handle_page_fault(address, ip, is_write, is_user, &si.si_code); + else { + err = -EFAULT; + /* A thread accessed NULL, we get a fault, but CR2 is invalid. + * This code is used in __do_copy_from_user() of TT mode. */ + address = 0; + } + + catcher = current->thread.fault_catcher; + if(!err) + return(0); + else if(catcher != NULL){ + current->thread.fault_addr = (void *) address; + do_longjmp(catcher, 1); + } + else if(current->thread.fault_addr != NULL) + panic("fault_addr set but no fault catcher"); + else if(!is_user && arch_fixup(ip, sc)) + return(0); + + if(!is_user) + panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", + address, ip); + + if (err == -EACCES) { + si.si_signo = SIGBUS; + si.si_errno = 0; + si.si_code = BUS_ADRERR; + si.si_addr = (void __user *)address; + current->thread.arch.faultinfo = fi; + force_sig_info(SIGBUS, &si, current); + } else if (err == -ENOMEM) { + printk("VM: killing process %s\n", current->comm); + do_exit(SIGKILL); + } else { + BUG_ON(err != -EFAULT); + si.si_signo = SIGSEGV; + si.si_addr = (void __user *) address; + current->thread.arch.faultinfo = fi; + force_sig_info(SIGSEGV, &si, current); + } + return(0); +} + +void bad_segv(struct faultinfo fi, unsigned long ip) +{ + struct siginfo si; + + si.si_signo = SIGSEGV; + si.si_code = SEGV_ACCERR; + si.si_addr = (void __user *) FAULT_ADDRESS(fi); + current->thread.arch.faultinfo = fi; + force_sig_info(SIGSEGV, &si, current); +} + +void relay_signal(int sig, union uml_pt_regs *regs) +{ + if(arch_handle_signal(sig, regs)) return; + if(!UPT_IS_USER(regs)) + panic("Kernel mode signal %d", sig); + current->thread.arch.faultinfo = *UPT_FAULTINFO(regs); + force_sig(sig, current); +} + +void bus_handler(int sig, union uml_pt_regs *regs) +{ + if(current->thread.fault_catcher != NULL) + do_longjmp(current->thread.fault_catcher, 1); + else relay_signal(sig, regs); +} + +void winch(int sig, union uml_pt_regs *regs) +{ + do_IRQ(WINCH_IRQ, regs); +} + +void trap_init(void) +{ +} diff --git a/arch/um/kernel/trap_kern.c b/arch/um/kernel/trap_kern.c deleted file mode 100644 index 02f6d4d8dc3a..000000000000 --- a/arch/um/kernel/trap_kern.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include "linux/kernel.h" -#include "asm/errno.h" -#include "linux/sched.h" -#include "linux/mm.h" -#include "linux/spinlock.h" -#include "linux/config.h" -#include "linux/init.h" -#include "linux/ptrace.h" -#include "asm/semaphore.h" -#include "asm/pgtable.h" -#include "asm/pgalloc.h" -#include "asm/tlbflush.h" -#include "asm/a.out.h" -#include "asm/current.h" -#include "asm/irq.h" -#include "sysdep/sigcontext.h" -#include "user_util.h" -#include "kern_util.h" -#include "kern.h" -#include "chan_kern.h" -#include "mconsole_kern.h" -#include "mem.h" -#include "mem_kern.h" -#include "sysdep/sigcontext.h" -#include "sysdep/ptrace.h" -#include "os.h" -#ifdef CONFIG_MODE_SKAS -#include "skas.h" -#endif -#include "os.h" - -/* Note this is constrained to return 0, -EFAULT, -EACCESS, -ENOMEM by segv(). */ -int handle_page_fault(unsigned long address, unsigned long ip, - int is_write, int is_user, int *code_out) -{ - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma; - pgd_t *pgd; - pud_t *pud; - pmd_t *pmd; - pte_t *pte; - int err = -EFAULT; - - *code_out = SEGV_MAPERR; - - /* If the fault was during atomic operation, don't take the fault, just - * fail. */ - if (in_atomic()) - goto out_nosemaphore; - - down_read(&mm->mmap_sem); - vma = find_vma(mm, address); - if(!vma) - goto out; - else if(vma->vm_start <= address) - goto good_area; - else if(!(vma->vm_flags & VM_GROWSDOWN)) - goto out; - else if(is_user && !ARCH_IS_STACKGROW(address)) - goto out; - else if(expand_stack(vma, address)) - goto out; - -good_area: - *code_out = SEGV_ACCERR; - if(is_write && !(vma->vm_flags & VM_WRITE)) - goto out; - - /* Don't require VM_READ|VM_EXEC for write faults! */ - if(!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC))) - goto out; - - do { -survive: - switch (handle_mm_fault(mm, vma, address, is_write)){ - case VM_FAULT_MINOR: - current->min_flt++; - break; - case VM_FAULT_MAJOR: - current->maj_flt++; - break; - case VM_FAULT_SIGBUS: - err = -EACCES; - goto out; - case VM_FAULT_OOM: - err = -ENOMEM; - goto out_of_memory; - default: - BUG(); - } - pgd = pgd_offset(mm, address); - pud = pud_offset(pgd, address); - pmd = pmd_offset(pud, address); - pte = pte_offset_kernel(pmd, address); - } while(!pte_present(*pte)); - err = 0; - /* The below warning was added in place of - * pte_mkyoung(); if (is_write) pte_mkdirty(); - * If it's triggered, we'd see normally a hang here (a clean pte is - * marked read-only to emulate the dirty bit). - * However, the generic code can mark a PTE writable but clean on a - * concurrent read fault, triggering this harmlessly. So comment it out. - */ -#if 0 - WARN_ON(!pte_young(*pte) || (is_write && !pte_dirty(*pte))); -#endif - flush_tlb_page(vma, address); -out: - up_read(&mm->mmap_sem); -out_nosemaphore: - return(err); - -/* - * We ran out of memory, or some other thing happened to us that made - * us unable to handle the page fault gracefully. - */ -out_of_memory: - if (current->pid == 1) { - up_read(&mm->mmap_sem); - yield(); - down_read(&mm->mmap_sem); - goto survive; - } - goto out; -} - -void segv_handler(int sig, union uml_pt_regs *regs) -{ - struct faultinfo * fi = UPT_FAULTINFO(regs); - - if(UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)){ - bad_segv(*fi, UPT_IP(regs)); - return; - } - segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs); -} - -struct kern_handlers handlinfo_kern = { - .relay_signal = relay_signal, - .winch = winch, - .bus_handler = relay_signal, - .page_fault = segv_handler, - .sigio_handler = sigio_handler, - .timer_handler = timer_handler -}; -/* - * We give a *copy* of the faultinfo in the regs to segv. - * This must be done, since nesting SEGVs could overwrite - * the info in the regs. A pointer to the info then would - * give us bad data! - */ -unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc) -{ - struct siginfo si; - void *catcher; - int err; - int is_write = FAULT_WRITE(fi); - unsigned long address = FAULT_ADDRESS(fi); - - if(!is_user && (address >= start_vm) && (address < end_vm)){ - flush_tlb_kernel_vm(); - return(0); - } - else if(current->mm == NULL) - panic("Segfault with no mm"); - - if (SEGV_IS_FIXABLE(&fi) || SEGV_MAYBE_FIXABLE(&fi)) - err = handle_page_fault(address, ip, is_write, is_user, &si.si_code); - else { - err = -EFAULT; - /* A thread accessed NULL, we get a fault, but CR2 is invalid. - * This code is used in __do_copy_from_user() of TT mode. */ - address = 0; - } - - catcher = current->thread.fault_catcher; - if(!err) - return(0); - else if(catcher != NULL){ - current->thread.fault_addr = (void *) address; - do_longjmp(catcher, 1); - } - else if(current->thread.fault_addr != NULL) - panic("fault_addr set but no fault catcher"); - else if(!is_user && arch_fixup(ip, sc)) - return(0); - - if(!is_user) - panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", - address, ip); - - if (err == -EACCES) { - si.si_signo = SIGBUS; - si.si_errno = 0; - si.si_code = BUS_ADRERR; - si.si_addr = (void __user *)address; - current->thread.arch.faultinfo = fi; - force_sig_info(SIGBUS, &si, current); - } else if (err == -ENOMEM) { - printk("VM: killing process %s\n", current->comm); - do_exit(SIGKILL); - } else { - BUG_ON(err != -EFAULT); - si.si_signo = SIGSEGV; - si.si_addr = (void __user *) address; - current->thread.arch.faultinfo = fi; - force_sig_info(SIGSEGV, &si, current); - } - return(0); -} - -void bad_segv(struct faultinfo fi, unsigned long ip) -{ - struct siginfo si; - - si.si_signo = SIGSEGV; - si.si_code = SEGV_ACCERR; - si.si_addr = (void __user *) FAULT_ADDRESS(fi); - current->thread.arch.faultinfo = fi; - force_sig_info(SIGSEGV, &si, current); -} - -void relay_signal(int sig, union uml_pt_regs *regs) -{ - if(arch_handle_signal(sig, regs)) return; - if(!UPT_IS_USER(regs)) - panic("Kernel mode signal %d", sig); - current->thread.arch.faultinfo = *UPT_FAULTINFO(regs); - force_sig(sig, current); -} - -void bus_handler(int sig, union uml_pt_regs *regs) -{ - if(current->thread.fault_catcher != NULL) - do_longjmp(current->thread.fault_catcher, 1); - else relay_signal(sig, regs); -} - -void winch(int sig, union uml_pt_regs *regs) -{ - do_IRQ(WINCH_IRQ, regs); -} - -void trap_init(void) -{ -} -- cgit v1.2.3-55-g7522 From b076bb02ee2c489da36c89e35c640bfe45c7d27e Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Fri, 14 Jul 2006 00:24:03 -0700 Subject: [PATCH] uml: tidy biarch gcc support On top of the previous biarch changes for UML, this makes the preprocessor changes a bit cleaner. Specify the 64-bit build in CPPFLAGS on the x86_64 SUBARCH, rather than #undef'ing i386. Compile-tested with i386 and x86_64 SUBARCHs. Signed-off-by: Nishanth Aravamudan Signed-off-by: Jeff Dike Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/Makefile-x86_64 | 1 + arch/um/kernel/vmlinux.lds.S | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/Makefile-x86_64 b/arch/um/Makefile-x86_64 index dffd1184c956..9558a7cf34d5 100644 --- a/arch/um/Makefile-x86_64 +++ b/arch/um/Makefile-x86_64 @@ -11,6 +11,7 @@ USER_CFLAGS += -fno-builtin -m64 CHECKFLAGS += -m64 AFLAGS += -m64 LDFLAGS += -m elf_x86_64 +CPPFLAGS += -m64 ELF_ARCH := i386:x86-64 ELF_FORMAT := elf64-x86-64 diff --git a/arch/um/kernel/vmlinux.lds.S b/arch/um/kernel/vmlinux.lds.S index 72acdce205e0..f8aeb448aab6 100644 --- a/arch/um/kernel/vmlinux.lds.S +++ b/arch/um/kernel/vmlinux.lds.S @@ -1,5 +1,3 @@ -/* in case the preprocessor is a 32bit one */ -#undef i386 #ifdef CONFIG_LD_SCRIPT_STATIC #include "uml.lds.S" #else -- cgit v1.2.3-55-g7522 From b5032a50aea76b6230db74b1d171a7f56b204bb7 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Fri, 14 Jul 2006 15:52:23 -0400 Subject: [PATCH] UML - fix utsname build breakage Some -mm-only material leaked into a patch destined for mainline, and I didn't notice. This was the replacement of system_utsname with utsname() that's required by the uts namespace patch. This patch reverts those changes (which are correct in -mm) so that mainline UML builds again. Signed-off-by: Jeff Dike Signed-off-by: Linus Torvalds --- arch/um/kernel/syscall.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'arch/um/kernel') diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c index abf14aaf905f..48cf88dd02d4 100644 --- a/arch/um/kernel/syscall.c +++ b/arch/um/kernel/syscall.c @@ -110,7 +110,7 @@ long sys_uname(struct old_utsname __user * name) if (!name) return -EFAULT; down_read(&uts_sem); - err = copy_to_user(name, utsname(), sizeof (*name)); + err = copy_to_user(name, &system_utsname, sizeof (*name)); up_read(&uts_sem); return err?-EFAULT:0; } @@ -126,21 +126,21 @@ long sys_olduname(struct oldold_utsname __user * name) down_read(&uts_sem); - error = __copy_to_user(&name->sysname, &utsname()->sysname, + error = __copy_to_user(&name->sysname,&system_utsname.sysname, __OLD_UTS_LEN); - error |= __put_user(0, name->sysname + __OLD_UTS_LEN); - error |= __copy_to_user(&name->nodename, &utsname()->nodename, + error |= __put_user(0,name->sysname+__OLD_UTS_LEN); + error |= __copy_to_user(&name->nodename,&system_utsname.nodename, __OLD_UTS_LEN); - error |= __put_user(0, name->nodename + __OLD_UTS_LEN); - error |= __copy_to_user(&name->release, &utsname()->release, + error |= __put_user(0,name->nodename+__OLD_UTS_LEN); + error |= __copy_to_user(&name->release,&system_utsname.release, __OLD_UTS_LEN); - error |= __put_user(0, name->release + __OLD_UTS_LEN); - error |= __copy_to_user(&name->version, &utsname()->version, + error |= __put_user(0,name->release+__OLD_UTS_LEN); + error |= __copy_to_user(&name->version,&system_utsname.version, __OLD_UTS_LEN); - error |= __put_user(0, name->version + __OLD_UTS_LEN); - error |= __copy_to_user(&name->machine, &utsname()->machine, + error |= __put_user(0,name->version+__OLD_UTS_LEN); + error |= __copy_to_user(&name->machine,&system_utsname.machine, __OLD_UTS_LEN); - error |= __put_user(0, name->machine + __OLD_UTS_LEN); + error |= __put_user(0,name->machine+__OLD_UTS_LEN); up_read(&uts_sem); -- cgit v1.2.3-55-g7522 From 0b0bf7a3ccb6f0b38ead71980e79f875046047b7 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 30 Jul 2006 03:04:06 -0700 Subject: [PATCH] vDSO hash-style fix The latest toolchains can produce a new ELF section in DSOs and dynamically-linked executables. The new section ".gnu.hash" replaces ".hash", and allows for more efficient runtime symbol lookups by the dynamic linker. The new ld option --hash-style={sysv|gnu|both} controls whether to produce the old ".hash", the new ".gnu.hash", or both. In some new systems such as Fedora Core 6, gcc by default passes --hash-style=gnu to the linker, so that a standard invocation of "gcc -shared" results in producing a DSO with only ".gnu.hash". The new ".gnu.hash" sections need to be dealt with the same way as ".hash" sections in all respects; only the dynamic linker cares about their contents. To work with older dynamic linkers (i.e. preexisting releases of glibc), a binary must have the old ".hash" section. The --hash-style=both option produces binaries that a new dynamic linker can use more efficiently, but an old dynamic linker can still handle. The new section runs afoul of the custom linker scripts used to build vDSO images for the kernel. On ia64, the failure mode for this is a boot-time panic because the vDSO's PT_IA_64_UNWIND segment winds up ill-formed. This patch addresses the problem in two ways. First, it mentions ".gnu.hash" in all the linker scripts alongside ".hash". This produces correct vDSO images with --hash-style=sysv (or old tools), with --hash-style=gnu, or with --hash-style=both. Second, it passes the --hash-style=sysv option when building the vDSO images, so that ".gnu.hash" is not actually produced. This is the most conservative choice for compatibility with any old userland. There is some concern that some ancient glibc builds (though not any known old production system) might choke on --hash-style=both binaries. The optimizations provided by the new style of hash section do not really matter for a DSO with a tiny number of symbols, as the vDSO has. If someone wants to use =gnu or =both for their vDSO builds and worry less about that compatibility, just change the option and the linker script changes will make any choice work fine. Signed-off-by: Roland McGrath Cc: "Luck, Tony" Cc: Kyle McMartin Cc: Paul Mackerras Cc: Benjamin Herrenschmidt Cc: Jeff Dike Cc: Andi Kleen Cc: Sam Ravnborg Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- Documentation/kbuild/makefiles.txt | 14 ++++++++++++++ arch/i386/kernel/Makefile | 3 ++- arch/i386/kernel/vsyscall.lds.S | 1 + arch/ia64/kernel/Makefile | 3 ++- arch/ia64/kernel/gate.lds.S | 1 + arch/parisc/kernel/vmlinux.lds.S | 1 + arch/powerpc/kernel/vdso32/Makefile | 3 ++- arch/powerpc/kernel/vdso32/vdso32.lds.S | 1 + arch/powerpc/kernel/vdso64/Makefile | 3 ++- arch/powerpc/kernel/vdso64/vdso64.lds.S | 1 + arch/ppc/kernel/vmlinux.lds.S | 1 + arch/um/kernel/dyn.lds.S | 1 + arch/x86_64/ia32/Makefile | 1 + arch/x86_64/ia32/vsyscall.lds | 1 + scripts/Kbuild.include | 7 +++++++ 15 files changed, 38 insertions(+), 4 deletions(-) (limited to 'arch/um/kernel') diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index 14ef3868a328..0706699c9da9 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt @@ -407,6 +407,20 @@ more details, with real examples. The second argument is optional, and if supplied will be used if first argument is not supported. + ld-option + ld-option is used to check if $(CC) when used to link object files + supports the given option. An optional second option may be + specified if first option are not supported. + + Example: + #arch/i386/kernel/Makefile + vsyscall-flags += $(call ld-option, -Wl$(comma)--hash-style=sysv) + + In the above example vsyscall-flags will be assigned the option + -Wl$(comma)--hash-style=sysv if it is supported by $(CC). + The second argument is optional, and if supplied will be used + if first argument is not supported. + cc-option cc-option is used to check if $(CC) support a given option, and not supported to use an optional second option. diff --git a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile index 1b452a1665c4..ab98fc21a541 100644 --- a/arch/i386/kernel/Makefile +++ b/arch/i386/kernel/Makefile @@ -59,7 +59,8 @@ quiet_cmd_syscall = SYSCALL $@ export CPPFLAGS_vsyscall.lds += -P -C -U$(ARCH) -vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1 +vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1 \ + $(call ld-option, -Wl$(comma)--hash-style=sysv) SYSCFLAGS_vsyscall-sysenter.so = $(vsyscall-flags) SYSCFLAGS_vsyscall-int80.so = $(vsyscall-flags) diff --git a/arch/i386/kernel/vsyscall.lds.S b/arch/i386/kernel/vsyscall.lds.S index e26975fc68b6..f66cd11adb72 100644 --- a/arch/i386/kernel/vsyscall.lds.S +++ b/arch/i386/kernel/vsyscall.lds.S @@ -10,6 +10,7 @@ SECTIONS . = VDSO_PRELINK + SIZEOF_HEADERS; .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } diff --git a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile index 0e4553f320bf..ad8215a3c586 100644 --- a/arch/ia64/kernel/Makefile +++ b/arch/ia64/kernel/Makefile @@ -45,7 +45,8 @@ CPPFLAGS_gate.lds := -P -C -U$(ARCH) quiet_cmd_gate = GATE $@ cmd_gate = $(CC) -nostdlib $(GATECFLAGS_$(@F)) -Wl,-T,$(filter-out FORCE,$^) -o $@ -GATECFLAGS_gate.so = -shared -s -Wl,-soname=linux-gate.so.1 +GATECFLAGS_gate.so = -shared -s -Wl,-soname=linux-gate.so.1 \ + $(call ld-option, -Wl$(comma)--hash-style=sysv) $(obj)/gate.so: $(obj)/gate.lds $(obj)/gate.o FORCE $(call if_changed,gate) diff --git a/arch/ia64/kernel/gate.lds.S b/arch/ia64/kernel/gate.lds.S index cc35cddfd4cf..6d198339bf85 100644 --- a/arch/ia64/kernel/gate.lds.S +++ b/arch/ia64/kernel/gate.lds.S @@ -12,6 +12,7 @@ SECTIONS . = GATE_ADDR + SIZEOF_HEADERS; .hash : { *(.hash) } :readable + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S index 9989495a51dd..b3677fc8eef5 100644 --- a/arch/parisc/kernel/vmlinux.lds.S +++ b/arch/parisc/kernel/vmlinux.lds.S @@ -204,6 +204,7 @@ SECTIONS *(.dynstr) *(.dynamic) *(.hash) + *(.gnu.hash) #endif } diff --git a/arch/powerpc/kernel/vdso32/Makefile b/arch/powerpc/kernel/vdso32/Makefile index 8a3bed5f143a..3726358faae8 100644 --- a/arch/powerpc/kernel/vdso32/Makefile +++ b/arch/powerpc/kernel/vdso32/Makefile @@ -14,7 +14,8 @@ obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) EXTRA_CFLAGS := -shared -s -fno-common -fno-builtin -EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso32.so.1 +EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso32.so.1 \ + $(call ld-option, -Wl$(comma)--hash-style=sysv) EXTRA_AFLAGS := -D__VDSO32__ -s obj-y += vdso32_wrapper.o diff --git a/arch/powerpc/kernel/vdso32/vdso32.lds.S b/arch/powerpc/kernel/vdso32/vdso32.lds.S index f4bad720cb0a..6187af2d54c3 100644 --- a/arch/powerpc/kernel/vdso32/vdso32.lds.S +++ b/arch/powerpc/kernel/vdso32/vdso32.lds.S @@ -14,6 +14,7 @@ SECTIONS { . = VDSO32_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } diff --git a/arch/powerpc/kernel/vdso64/Makefile b/arch/powerpc/kernel/vdso64/Makefile index ab39988452cc..43af9b2a6f3b 100644 --- a/arch/powerpc/kernel/vdso64/Makefile +++ b/arch/powerpc/kernel/vdso64/Makefile @@ -8,7 +8,8 @@ targets := $(obj-vdso64) vdso64.so obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) EXTRA_CFLAGS := -shared -s -fno-common -fno-builtin -EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso64.so.1 +EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso64.so.1 \ + $(call ld-option, -Wl$(comma)--hash-style=sysv) EXTRA_AFLAGS := -D__VDSO64__ -s obj-y += vdso64_wrapper.o diff --git a/arch/powerpc/kernel/vdso64/vdso64.lds.S b/arch/powerpc/kernel/vdso64/vdso64.lds.S index 4bdf224464ab..4a2b6dc0960c 100644 --- a/arch/powerpc/kernel/vdso64/vdso64.lds.S +++ b/arch/powerpc/kernel/vdso64/vdso64.lds.S @@ -12,6 +12,7 @@ SECTIONS { . = VDSO64_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } diff --git a/arch/ppc/kernel/vmlinux.lds.S b/arch/ppc/kernel/vmlinux.lds.S index 09c6525cfa61..095fd3323323 100644 --- a/arch/ppc/kernel/vmlinux.lds.S +++ b/arch/ppc/kernel/vmlinux.lds.S @@ -8,6 +8,7 @@ SECTIONS . = + SIZEOF_HEADERS; .interp : { *(.interp) } .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .rel.text : { *(.rel.text) } diff --git a/arch/um/kernel/dyn.lds.S b/arch/um/kernel/dyn.lds.S index 2517ecb8bf27..68ed24df5c8f 100644 --- a/arch/um/kernel/dyn.lds.S +++ b/arch/um/kernel/dyn.lds.S @@ -26,6 +26,7 @@ SECTIONS /* Read-only sections, merged into text segment: */ .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } diff --git a/arch/x86_64/ia32/Makefile b/arch/x86_64/ia32/Makefile index 62bc5f56da9e..cdae36435e21 100644 --- a/arch/x86_64/ia32/Makefile +++ b/arch/x86_64/ia32/Makefile @@ -23,6 +23,7 @@ targets := $(foreach F,sysenter syscall,vsyscall-$F.o vsyscall-$F.so) # The DSO images are built using a special linker script quiet_cmd_syscall = SYSCALL $@ cmd_syscall = $(CC) -m32 -nostdlib -shared -s \ + $(call ld-option, -Wl$(comma)--hash-style=sysv) \ -Wl,-soname=linux-gate.so.1 -o $@ \ -Wl,-T,$(filter-out FORCE,$^) diff --git a/arch/x86_64/ia32/vsyscall.lds b/arch/x86_64/ia32/vsyscall.lds index f2e75ed4c6c7..1dc86ff5bcb9 100644 --- a/arch/x86_64/ia32/vsyscall.lds +++ b/arch/x86_64/ia32/vsyscall.lds @@ -11,6 +11,7 @@ SECTIONS . = VSYSCALL_BASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } .gnu.version : { *(.gnu.version) } diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 2180c88cfe89..f01132263535 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -85,6 +85,13 @@ cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \ cc-ifversion = $(shell if [ $(call cc-version, $(CC)) $(1) $(2) ]; then \ echo $(3); fi;) +# ld-option +# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both) +ld-option = $(shell if $(CC) $(1) \ + -nostdlib -o ldtest$$$$.out -xc /dev/null \ + > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi; \ + rm -f ldtest$$$$.out) + ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= # Usage: -- cgit v1.2.3-55-g7522