aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/include/shared
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2008-08-17 13:48:37 -0400
committerH. Peter Anvin <hpa@zytor.com>2008-10-23 01:55:19 -0400
commit8569c9140bd41089f9b6be8837ca421102714a90 (patch)
treecd289b322b215fe2ca2530aa320febfd99388d7f /arch/um/include/shared
parent2515ddc6db8eb49a79f0fe5e67ff09ac7c81eab4 (diff)
x86, um: take arch/um/include/* out of the way
We can't just plop asm/* into it - userland helpers are built with it in search path and seeing asm/* show up there suddenly would be a bad idea. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'arch/um/include/shared')
-rw-r--r--arch/um/include/shared/aio.h28
-rw-r--r--arch/um/include/shared/arch.h15
-rw-r--r--arch/um/include/shared/as-layout.h68
-rw-r--r--arch/um/include/shared/chan_kern.h50
-rw-r--r--arch/um/include/shared/chan_user.h55
-rw-r--r--arch/um/include/shared/common-offsets.h41
-rw-r--r--arch/um/include/shared/elf_user.h19
-rw-r--r--arch/um/include/shared/frame_kern.h32
-rw-r--r--arch/um/include/shared/init.h151
-rw-r--r--arch/um/include/shared/initrd.h22
-rw-r--r--arch/um/include/shared/irq_kern.h28
-rw-r--r--arch/um/include/shared/irq_user.h30
-rw-r--r--arch/um/include/shared/kern.h40
-rw-r--r--arch/um/include/shared/kern_util.h69
-rw-r--r--arch/um/include/shared/line.h105
-rw-r--r--arch/um/include/shared/longjmp.h23
-rw-r--r--arch/um/include/shared/mconsole.h98
-rw-r--r--arch/um/include/shared/mconsole_kern.h52
-rw-r--r--arch/um/include/shared/mem.h22
-rw-r--r--arch/um/include/shared/mem_kern.h30
-rw-r--r--arch/um/include/shared/mem_user.h62
-rw-r--r--arch/um/include/shared/net_kern.h70
-rw-r--r--arch/um/include/shared/net_user.h53
-rw-r--r--arch/um/include/shared/os.h304
-rw-r--r--arch/um/include/shared/process.h17
-rw-r--r--arch/um/include/shared/ptrace_user.h55
-rw-r--r--arch/um/include/shared/registers.h24
-rw-r--r--arch/um/include/shared/sigcontext.h25
-rw-r--r--arch/um/include/shared/sigio.h14
-rw-r--r--arch/um/include/shared/skas/mm_id.h17
-rw-r--r--arch/um/include/shared/skas/proc_mm.h44
-rw-r--r--arch/um/include/shared/skas/skas.h22
-rw-r--r--arch/um/include/shared/skas/stub-data.h18
-rw-r--r--arch/um/include/shared/skas_ptrace.h14
-rw-r--r--arch/um/include/shared/skas_ptregs.h6
-rw-r--r--arch/um/include/shared/syscall.h12
-rw-r--r--arch/um/include/shared/sysdep-i386/archsetjmp.h22
-rw-r--r--arch/um/include/shared/sysdep-i386/barrier.h9
-rw-r--r--arch/um/include/shared/sysdep-i386/checksum.h211
-rw-r--r--arch/um/include/shared/sysdep-i386/faultinfo.h29
-rw-r--r--arch/um/include/shared/sysdep-i386/kernel-offsets.h21
-rw-r--r--arch/um/include/shared/sysdep-i386/ptrace.h171
-rw-r--r--arch/um/include/shared/sysdep-i386/ptrace_user.h50
-rw-r--r--arch/um/include/shared/sysdep-i386/sc.h44
-rw-r--r--arch/um/include/shared/sysdep-i386/sigcontext.h26
-rw-r--r--arch/um/include/shared/sysdep-i386/skas_ptrace.h22
-rw-r--r--arch/um/include/shared/sysdep-i386/stub.h102
-rw-r--r--arch/um/include/shared/sysdep-i386/syscalls.h26
-rw-r--r--arch/um/include/shared/sysdep-i386/tls.h32
-rw-r--r--arch/um/include/shared/sysdep-ia64/ptrace.h26
-rw-r--r--arch/um/include/shared/sysdep-ia64/sigcontext.h20
-rw-r--r--arch/um/include/shared/sysdep-ia64/skas_ptrace.h22
-rw-r--r--arch/um/include/shared/sysdep-ia64/syscalls.h20
-rw-r--r--arch/um/include/shared/sysdep-ppc/ptrace.h103
-rw-r--r--arch/um/include/shared/sysdep-ppc/sigcontext.h62
-rw-r--r--arch/um/include/shared/sysdep-ppc/skas_ptrace.h22
-rw-r--r--arch/um/include/shared/sysdep-ppc/syscalls.h53
-rw-r--r--arch/um/include/shared/sysdep-x86_64/archsetjmp.h24
-rw-r--r--arch/um/include/shared/sysdep-x86_64/barrier.h7
-rw-r--r--arch/um/include/shared/sysdep-x86_64/checksum.h144
-rw-r--r--arch/um/include/shared/sysdep-x86_64/faultinfo.h29
-rw-r--r--arch/um/include/shared/sysdep-x86_64/kernel-offsets.h23
-rw-r--r--arch/um/include/shared/sysdep-x86_64/ptrace.h240
-rw-r--r--arch/um/include/shared/sysdep-x86_64/ptrace_user.h77
-rw-r--r--arch/um/include/shared/sysdep-x86_64/sc.h45
-rw-r--r--arch/um/include/shared/sysdep-x86_64/sigcontext.h27
-rw-r--r--arch/um/include/shared/sysdep-x86_64/skas_ptrace.h22
-rw-r--r--arch/um/include/shared/sysdep-x86_64/stub.h108
-rw-r--r--arch/um/include/shared/sysdep-x86_64/syscalls.h33
-rw-r--r--arch/um/include/shared/sysdep-x86_64/tls.h29
-rw-r--r--arch/um/include/shared/sysrq.h7
-rw-r--r--arch/um/include/shared/task.h9
-rw-r--r--arch/um/include/shared/tlb.h15
-rw-r--r--arch/um/include/shared/ubd_user.h26
-rw-r--r--arch/um/include/shared/um_malloc.h19
-rw-r--r--arch/um/include/shared/um_mmu.h25
-rw-r--r--arch/um/include/shared/um_uaccess.h97
-rw-r--r--arch/um/include/shared/user.h45
78 files changed, 3879 insertions, 0 deletions
diff --git a/arch/um/include/shared/aio.h b/arch/um/include/shared/aio.h
new file mode 100644
index 00000000000..423bae9153f
--- /dev/null
+++ b/arch/um/include/shared/aio.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2004 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef AIO_H__
7#define AIO_H__
8
9enum aio_type { AIO_READ, AIO_WRITE, AIO_MMAP };
10
11struct aio_thread_reply {
12 void *data;
13 int err;
14};
15
16struct aio_context {
17 int reply_fd;
18 struct aio_context *next;
19};
20
21#define INIT_AIO_CONTEXT { .reply_fd = -1, \
22 .next = NULL }
23
24extern int submit_aio(enum aio_type type, int fd, char *buf, int len,
25 unsigned long long offset, int reply_fd,
26 struct aio_context *aio);
27
28#endif
diff --git a/arch/um/include/shared/arch.h b/arch/um/include/shared/arch.h
new file mode 100644
index 00000000000..2de92a08a76
--- /dev/null
+++ b/arch/um/include/shared/arch.h
@@ -0,0 +1,15 @@
1/*
2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __ARCH_H__
7#define __ARCH_H__
8
9#include "sysdep/ptrace.h"
10
11extern void arch_check_bugs(void);
12extern int arch_fixup(unsigned long address, struct uml_pt_regs *regs);
13extern void arch_examine_signal(int sig, struct uml_pt_regs *regs);
14
15#endif
diff --git a/arch/um/include/shared/as-layout.h b/arch/um/include/shared/as-layout.h
new file mode 100644
index 00000000000..58e852dfb0c
--- /dev/null
+++ b/arch/um/include/shared/as-layout.h
@@ -0,0 +1,68 @@
1/*
2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __START_H__
7#define __START_H__
8
9#include "uml-config.h"
10#include "kern_constants.h"
11
12/*
13 * Stolen from linux/const.h, which can't be directly included since
14 * this is used in userspace code, which has no access to the kernel
15 * headers. Changed to be suitable for adding casts to the start,
16 * rather than "UL" to the end.
17 */
18
19/* Some constant macros are used in both assembler and
20 * C code. Therefore we cannot annotate them always with
21 * 'UL' and other type specifiers unilaterally. We
22 * use the following macros to deal with this.
23 */
24
25#ifdef __ASSEMBLY__
26#define _UML_AC(X, Y) (Y)
27#else
28#define __UML_AC(X, Y) (X(Y))
29#define _UML_AC(X, Y) __UML_AC(X, Y)
30#endif
31
32#define STUB_START _UML_AC(, 0x100000)
33#define STUB_CODE _UML_AC((unsigned long), STUB_START)
34#define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
35#define STUB_END _UML_AC((unsigned long), STUB_DATA + UM_KERN_PAGE_SIZE)
36
37#ifndef __ASSEMBLY__
38
39#include "sysdep/ptrace.h"
40
41struct cpu_task {
42 int pid;
43 void *task;
44};
45
46extern struct cpu_task cpu_tasks[];
47
48extern unsigned long low_physmem;
49extern unsigned long high_physmem;
50extern unsigned long uml_physmem;
51extern unsigned long uml_reserved;
52extern unsigned long end_vm;
53extern unsigned long start_vm;
54extern unsigned long long highmem;
55
56extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
57extern unsigned long _unprotected_end;
58extern unsigned long brk_start;
59
60extern unsigned long host_task_size;
61
62extern int linux_main(int argc, char **argv);
63
64extern void (*sig_info[])(int, struct uml_pt_regs *);
65
66#endif
67
68#endif
diff --git a/arch/um/include/shared/chan_kern.h b/arch/um/include/shared/chan_kern.h
new file mode 100644
index 00000000000..1e651457e04
--- /dev/null
+++ b/arch/um/include/shared/chan_kern.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __CHAN_KERN_H__
7#define __CHAN_KERN_H__
8
9#include "linux/tty.h"
10#include "linux/list.h"
11#include "linux/console.h"
12#include "chan_user.h"
13#include "line.h"
14
15struct chan {
16 struct list_head list;
17 struct list_head free_list;
18 struct line *line;
19 char *dev;
20 unsigned int primary:1;
21 unsigned int input:1;
22 unsigned int output:1;
23 unsigned int opened:1;
24 unsigned int enabled:1;
25 int fd;
26 const struct chan_ops *ops;
27 void *data;
28};
29
30extern void chan_interrupt(struct list_head *chans, struct delayed_work *task,
31 struct tty_struct *tty, int irq);
32extern int parse_chan_pair(char *str, struct line *line, int device,
33 const struct chan_opts *opts, char **error_out);
34extern int write_chan(struct list_head *chans, const char *buf, int len,
35 int write_irq);
36extern int console_write_chan(struct list_head *chans, const char *buf,
37 int len);
38extern int console_open_chan(struct line *line, struct console *co);
39extern void deactivate_chan(struct list_head *chans, int irq);
40extern void reactivate_chan(struct list_head *chans, int irq);
41extern void chan_enable_winch(struct list_head *chans, struct tty_struct *tty);
42extern int enable_chan(struct line *line);
43extern void close_chan(struct list_head *chans, int delay_free_irq);
44extern int chan_window_size(struct list_head *chans,
45 unsigned short *rows_out,
46 unsigned short *cols_out);
47extern int chan_config_string(struct list_head *chans, char *str, int size,
48 char **error_out);
49
50#endif
diff --git a/arch/um/include/shared/chan_user.h b/arch/um/include/shared/chan_user.h
new file mode 100644
index 00000000000..9b9ced85b70
--- /dev/null
+++ b/arch/um/include/shared/chan_user.h
@@ -0,0 +1,55 @@
1/*
2 * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __CHAN_USER_H__
7#define __CHAN_USER_H__
8
9#include "init.h"
10
11struct chan_opts {
12 void (*const announce)(char *dev_name, int dev);
13 char *xterm_title;
14 const int raw;
15};
16
17enum chan_init_pri { INIT_STATIC, INIT_ALL, INIT_ONE };
18
19struct chan_ops {
20 char *type;
21 void *(*init)(char *, int, const struct chan_opts *);
22 int (*open)(int, int, int, void *, char **);
23 void (*close)(int, void *);
24 int (*read)(int, char *, void *);
25 int (*write)(int, const char *, int, void *);
26 int (*console_write)(int, const char *, int);
27 int (*window_size)(int, void *, unsigned short *, unsigned short *);
28 void (*free)(void *);
29 int winch;
30};
31
32extern const struct chan_ops fd_ops, null_ops, port_ops, pts_ops, pty_ops,
33 tty_ops, xterm_ops;
34
35extern void generic_close(int fd, void *unused);
36extern int generic_read(int fd, char *c_out, void *unused);
37extern int generic_write(int fd, const char *buf, int n, void *unused);
38extern int generic_console_write(int fd, const char *buf, int n);
39extern int generic_window_size(int fd, void *unused, unsigned short *rows_out,
40 unsigned short *cols_out);
41extern void generic_free(void *data);
42
43struct tty_struct;
44extern void register_winch(int fd, struct tty_struct *tty);
45extern void register_winch_irq(int fd, int tty_fd, int pid,
46 struct tty_struct *tty, unsigned long stack);
47
48#define __channel_help(fn, prefix) \
49__uml_help(fn, prefix "[0-9]*=<channel description>\n" \
50" Attach a console or serial line to a host channel. See\n" \
51" http://user-mode-linux.sourceforge.net/old/input.html for a complete\n" \
52" description of this switch.\n\n" \
53);
54
55#endif
diff --git a/arch/um/include/shared/common-offsets.h b/arch/um/include/shared/common-offsets.h
new file mode 100644
index 00000000000..b54bd35585c
--- /dev/null
+++ b/arch/um/include/shared/common-offsets.h
@@ -0,0 +1,41 @@
1/* for use by sys-$SUBARCH/kernel-offsets.c */
2
3DEFINE(KERNEL_MADV_REMOVE, MADV_REMOVE);
4
5OFFSET(HOST_TASK_REGS, task_struct, thread.regs);
6OFFSET(HOST_TASK_PID, task_struct, pid);
7
8DEFINE(UM_KERN_PAGE_SIZE, PAGE_SIZE);
9DEFINE(UM_KERN_PAGE_MASK, PAGE_MASK);
10DEFINE(UM_KERN_PAGE_SHIFT, PAGE_SHIFT);
11DEFINE(UM_NSEC_PER_SEC, NSEC_PER_SEC);
12
13DEFINE_STR(UM_KERN_EMERG, KERN_EMERG);
14DEFINE_STR(UM_KERN_ALERT, KERN_ALERT);
15DEFINE_STR(UM_KERN_CRIT, KERN_CRIT);
16DEFINE_STR(UM_KERN_ERR, KERN_ERR);
17DEFINE_STR(UM_KERN_WARNING, KERN_WARNING);
18DEFINE_STR(UM_KERN_NOTICE, KERN_NOTICE);
19DEFINE_STR(UM_KERN_INFO, KERN_INFO);
20DEFINE_STR(UM_KERN_DEBUG, KERN_DEBUG);
21DEFINE_STR(UM_KERN_CONT, KERN_CONT);
22
23DEFINE(UM_ELF_CLASS, ELF_CLASS);
24DEFINE(UM_ELFCLASS32, ELFCLASS32);
25DEFINE(UM_ELFCLASS64, ELFCLASS64);
26
27DEFINE(UM_NR_CPUS, NR_CPUS);
28
29DEFINE(UM_GFP_KERNEL, GFP_KERNEL);
30DEFINE(UM_GFP_ATOMIC, GFP_ATOMIC);
31
32/* For crypto assembler code. */
33DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
34
35DEFINE(UM_THREAD_SIZE, THREAD_SIZE);
36
37DEFINE(UM_HZ, HZ);
38
39DEFINE(UM_USEC_PER_SEC, USEC_PER_SEC);
40DEFINE(UM_NSEC_PER_SEC, NSEC_PER_SEC);
41DEFINE(UM_NSEC_PER_USEC, NSEC_PER_USEC);
diff --git a/arch/um/include/shared/elf_user.h b/arch/um/include/shared/elf_user.h
new file mode 100644
index 00000000000..53516b63727
--- /dev/null
+++ b/arch/um/include/shared/elf_user.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) 2004 Fujitsu Siemens Computers GmbH
3 * Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
4 * Licensed under the GPL
5 */
6
7#ifndef __ELF_USER_H__
8#define __ELF_USER_H__
9
10/* For compilation on a host that doesn't support AT_SYSINFO (Linux 2.4) */
11
12#ifndef AT_SYSINFO
13#define AT_SYSINFO 32
14#endif
15#ifndef AT_SYSINFO_EHDR
16#define AT_SYSINFO_EHDR 33
17#endif
18
19#endif
diff --git a/arch/um/include/shared/frame_kern.h b/arch/um/include/shared/frame_kern.h
new file mode 100644
index 00000000000..ce9514f5721
--- /dev/null
+++ b/arch/um/include/shared/frame_kern.h
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __FRAME_KERN_H_
7#define __FRAME_KERN_H_
8
9#define _S(nr) (1<<((nr)-1))
10#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
11
12extern int setup_signal_stack_sc(unsigned long stack_top, int sig,
13 struct k_sigaction *ka,
14 struct pt_regs *regs,
15 sigset_t *mask);
16extern int setup_signal_stack_si(unsigned long stack_top, int sig,
17 struct k_sigaction *ka,
18 struct pt_regs *regs, siginfo_t *info,
19 sigset_t *mask);
20
21#endif
22
23/*
24 * Overrides for Emacs so that we follow Linus's tabbing style.
25 * Emacs will notice this stuff at the end of the file and automatically
26 * adjust the settings for this buffer only. This must remain at the end
27 * of the file.
28 * ---------------------------------------------------------------------------
29 * Local variables:
30 * c-file-style: "linux"
31 * End:
32 */
diff --git a/arch/um/include/shared/init.h b/arch/um/include/shared/init.h
new file mode 100644
index 00000000000..37dd097c16c
--- /dev/null
+++ b/arch/um/include/shared/init.h
@@ -0,0 +1,151 @@
1#ifndef _LINUX_UML_INIT_H
2#define _LINUX_UML_INIT_H
3
4/* These macros are used to mark some functions or
5 * initialized data (doesn't apply to uninitialized data)
6 * as `initialization' functions. The kernel can take this
7 * as hint that the function is used only during the initialization
8 * phase and free up used memory resources after
9 *
10 * Usage:
11 * For functions:
12 *
13 * You should add __init immediately before the function name, like:
14 *
15 * static void __init initme(int x, int y)
16 * {
17 * extern int z; z = x * y;
18 * }
19 *
20 * If the function has a prototype somewhere, you can also add
21 * __init between closing brace of the prototype and semicolon:
22 *
23 * extern int initialize_foobar_device(int, int, int) __init;
24 *
25 * For initialized data:
26 * You should insert __initdata between the variable name and equal
27 * sign followed by value, e.g.:
28 *
29 * static int init_variable __initdata = 0;
30 * static char linux_logo[] __initdata = { 0x32, 0x36, ... };
31 *
32 * Don't forget to initialize data not at file scope, i.e. within a function,
33 * as gcc otherwise puts the data into the bss section and not into the init
34 * section.
35 *
36 * Also note, that this data cannot be "const".
37 */
38
39#ifndef _LINUX_INIT_H
40typedef int (*initcall_t)(void);
41typedef void (*exitcall_t)(void);
42
43#ifndef __KERNEL__
44#ifndef __section
45# define __section(S) __attribute__ ((__section__(#S)))
46#endif
47
48#if __GNUC__ == 3
49
50#if __GNUC_MINOR__ >= 3
51# define __used __attribute__((__used__))
52#else
53# define __used __attribute__((__unused__))
54#endif
55
56#else
57#if __GNUC__ == 4
58# define __used __attribute__((__used__))
59#endif
60#endif
61
62#else
63#include <linux/compiler.h>
64#endif
65/* These are for everybody (although not all archs will actually
66 discard it in modules) */
67#define __init __section(.init.text)
68#define __initdata __section(.init.data)
69#define __exitdata __section(.exit.data)
70#define __exit_call __used __section(.exitcall.exit)
71
72#ifdef MODULE
73#define __exit __section(.exit.text)
74#else
75#define __exit __used __section(.exit.text)
76#endif
77
78#endif
79
80#ifndef MODULE
81struct uml_param {
82 const char *str;
83 int (*setup_func)(char *, int *);
84};
85
86extern initcall_t __uml_initcall_start, __uml_initcall_end;
87extern initcall_t __uml_postsetup_start, __uml_postsetup_end;
88extern const char *__uml_help_start, *__uml_help_end;
89#endif
90
91#define __uml_initcall(fn) \
92 static initcall_t __uml_initcall_##fn __uml_init_call = fn
93
94#define __uml_exitcall(fn) \
95 static exitcall_t __uml_exitcall_##fn __uml_exit_call = fn
96
97extern struct uml_param __uml_setup_start, __uml_setup_end;
98
99#define __uml_postsetup(fn) \
100 static initcall_t __uml_postsetup_##fn __uml_postsetup_call = fn
101
102#define __non_empty_string(dummyname,string) \
103 struct __uml_non_empty_string_struct_##dummyname \
104 { \
105 char _string[sizeof(string)-2]; \
106 }
107
108#ifndef MODULE
109#define __uml_setup(str, fn, help...) \
110 __non_empty_string(fn ##_setup, str); \
111 __uml_help(fn, help); \
112 static char __uml_setup_str_##fn[] __initdata = str; \
113 static struct uml_param __uml_setup_##fn __uml_init_setup = { __uml_setup_str_##fn, fn }
114#else
115#define __uml_setup(str, fn, help...) \
116
117#endif
118
119#define __uml_help(fn, help...) \
120 __non_empty_string(fn ##__help, help); \
121 static char __uml_help_str_##fn[] __initdata = help; \
122 static const char *__uml_help_##fn __uml_setup_help = __uml_help_str_##fn
123
124/*
125 * Mark functions and data as being only used at initialization
126 * or exit time.
127 */
128#define __uml_init_setup __used __section(.uml.setup.init)
129#define __uml_setup_help __used __section(.uml.help.init)
130#define __uml_init_call __used __section(.uml.initcall.init)
131#define __uml_postsetup_call __used __section(.uml.postsetup.init)
132#define __uml_exit_call __used __section(.uml.exitcall.exit)
133
134#ifndef __KERNEL__
135
136#define __define_initcall(level,fn) \
137 static initcall_t __initcall_##fn __used \
138 __attribute__((__section__(".initcall" level ".init"))) = fn
139
140/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
141 * make them run first.
142 */
143#define __initcall(fn) __define_initcall("1", fn)
144
145#define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn
146
147#define __init_call __used __section(.initcall.init)
148
149#endif
150
151#endif /* _LINUX_UML_INIT_H */
diff --git a/arch/um/include/shared/initrd.h b/arch/um/include/shared/initrd.h
new file mode 100644
index 00000000000..439b9a81498
--- /dev/null
+++ b/arch/um/include/shared/initrd.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __INITRD_USER_H__
7#define __INITRD_USER_H__
8
9extern int load_initrd(char *filename, void *buf, int size);
10
11#endif
12
13/*
14 * Overrides for Emacs so that we follow Linus's tabbing style.
15 * Emacs will notice this stuff at the end of the file and automatically
16 * adjust the settings for this buffer only. This must remain at the end
17 * of the file.
18 * ---------------------------------------------------------------------------
19 * Local variables:
20 * c-file-style: "linux"
21 * End:
22 */
diff --git a/arch/um/include/shared/irq_kern.h b/arch/um/include/shared/irq_kern.h
new file mode 100644
index 00000000000..fba3895274f
--- /dev/null
+++ b/arch/um/include/shared/irq_kern.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __IRQ_KERN_H__
7#define __IRQ_KERN_H__
8
9#include "linux/interrupt.h"
10#include "asm/ptrace.h"
11
12extern int um_request_irq(unsigned int irq, int fd, int type,
13 irq_handler_t handler,
14 unsigned long irqflags, const char * devname,
15 void *dev_id);
16
17#endif
18
19/*
20 * Overrides for Emacs so that we follow Linus's tabbing style.
21 * Emacs will notice this stuff at the end of the file and automatically
22 * adjust the settings for this buffer only. This must remain at the end
23 * of the file.
24 * ---------------------------------------------------------------------------
25 * Local variables:
26 * c-file-style: "linux"
27 * End:
28 */
diff --git a/arch/um/include/shared/irq_user.h b/arch/um/include/shared/irq_user.h
new file mode 100644
index 00000000000..c6c784df267
--- /dev/null
+++ b/arch/um/include/shared/irq_user.h
@@ -0,0 +1,30 @@
1/*
2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __IRQ_USER_H__
7#define __IRQ_USER_H__
8
9#include "sysdep/ptrace.h"
10
11struct irq_fd {
12 struct irq_fd *next;
13 void *id;
14 int fd;
15 int type;
16 int irq;
17 int events;
18 int current_events;
19};
20
21enum { IRQ_READ, IRQ_WRITE };
22
23extern void sigio_handler(int sig, struct uml_pt_regs *regs);
24extern void free_irq_by_fd(int fd);
25extern void reactivate_fd(int fd, int irqnum);
26extern void deactivate_fd(int fd, int irqnum);
27extern int deactivate_all_fds(void);
28extern int activate_ipi(int fd, int pid);
29
30#endif
diff --git a/arch/um/include/shared/kern.h b/arch/um/include/shared/kern.h
new file mode 100644
index 00000000000..4ce3fc650e5
--- /dev/null
+++ b/arch/um/include/shared/kern.h
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __KERN_H__
7#define __KERN_H__
8
9/* These are all user-mode things which are convenient to call directly
10 * from kernel code and for which writing a wrapper is too much of a pain.
11 * The regular include files can't be included because this file is included
12 * only into kernel code, and user-space includes conflict with kernel
13 * includes.
14 */
15
16extern int errno;
17
18extern int clone(int (*proc)(void *), void *sp, int flags, void *data);
19extern int sleep(int);
20extern int printf(const char *fmt, ...);
21extern char *strerror(int errnum);
22extern char *ptsname(int __fd);
23extern int munmap(void *, int);
24extern void *sbrk(int increment);
25extern void *malloc(int size);
26extern void perror(char *err);
27extern int kill(int pid, int sig);
28extern int getuid(void);
29extern int getgid(void);
30extern int pause(void);
31extern int write(int, const void *, int);
32extern void exit(int);
33extern int close(int);
34extern int read(unsigned int, char *, int);
35extern int pipe(int *);
36extern int sched_yield(void);
37extern int ptrace(int op, int pid, long addr, long data);
38
39#endif
40
diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/kern_util.h
new file mode 100644
index 00000000000..3c341222d25
--- /dev/null
+++ b/arch/um/include/shared/kern_util.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __KERN_UTIL_H__
7#define __KERN_UTIL_H__
8
9#include "sysdep/ptrace.h"
10#include "sysdep/faultinfo.h"
11
12extern int uml_exitcode;
13
14extern int ncpus;
15extern int kmalloc_ok;
16
17#define UML_ROUND_UP(addr) \
18 ((((unsigned long) addr) + PAGE_SIZE - 1) & PAGE_MASK)
19
20extern unsigned long alloc_stack(int order, int atomic);
21extern void free_stack(unsigned long stack, int order);
22
23extern int do_signal(void);
24extern void copy_sc(struct uml_pt_regs *regs, void *from);
25extern void interrupt_end(void);
26extern void relay_signal(int sig, struct uml_pt_regs *regs);
27
28extern unsigned long segv(struct faultinfo fi, unsigned long ip,
29 int is_user, struct uml_pt_regs *regs);
30extern int handle_page_fault(unsigned long address, unsigned long ip,
31 int is_write, int is_user, int *code_out);
32
33extern unsigned int do_IRQ(int irq, struct uml_pt_regs *regs);
34extern int smp_sigio_handler(void);
35extern void initial_thread_cb(void (*proc)(void *), void *arg);
36extern int is_syscall(unsigned long addr);
37extern void timer_handler(int sig, struct uml_pt_regs *regs);
38
39extern void timer_handler(int sig, struct uml_pt_regs *regs);
40
41extern int start_uml(void);
42extern void paging_init(void);
43
44extern void uml_cleanup(void);
45extern void do_uml_exitcalls(void);
46
47/*
48 * Are we disallowed to sleep? Used to choose between GFP_KERNEL and
49 * GFP_ATOMIC.
50 */
51extern int __cant_sleep(void);
52extern void *get_current(void);
53extern int copy_from_user_proc(void *to, void *from, int size);
54extern int cpu(void);
55extern char *uml_strdup(const char *string);
56
57extern unsigned long to_irq_stack(unsigned long *mask_out);
58extern unsigned long from_irq_stack(int nested);
59
60extern void syscall_trace(struct uml_pt_regs *regs, int entryexit);
61extern int singlestepping(void *t);
62
63extern void segv_handler(int sig, struct uml_pt_regs *regs);
64extern void bus_handler(int sig, struct uml_pt_regs *regs);
65extern void winch(int sig, struct uml_pt_regs *regs);
66extern void fatal_sigsegv(void) __attribute__ ((noreturn));
67
68
69#endif
diff --git a/arch/um/include/shared/line.h b/arch/um/include/shared/line.h
new file mode 100644
index 00000000000..311a0d3d93a
--- /dev/null
+++ b/arch/um/include/shared/line.h
@@ -0,0 +1,105 @@
1/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __LINE_H__
7#define __LINE_H__
8
9#include "linux/list.h"
10#include "linux/workqueue.h"
11#include "linux/tty.h"
12#include "linux/interrupt.h"
13#include "linux/spinlock.h"
14#include "linux/mutex.h"
15#include "chan_user.h"
16#include "mconsole_kern.h"
17
18/* There's only one modifiable field in this - .mc.list */
19struct line_driver {
20 const char *name;
21 const char *device_name;
22 const short major;
23 const short minor_start;
24 const short type;
25 const short subtype;
26 const int read_irq;
27 const char *read_irq_name;
28 const int write_irq;
29 const char *write_irq_name;
30 struct mc_device mc;
31};
32
33struct line {
34 struct tty_struct *tty;
35 spinlock_t count_lock;
36 int valid;
37
38 char *init_str;
39 int init_pri;
40 struct list_head chan_list;
41
42 /*This lock is actually, mostly, local to*/
43 spinlock_t lock;
44 int throttled;
45 /* Yes, this is a real circular buffer.
46 * XXX: And this should become a struct kfifo!
47 *
48 * buffer points to a buffer allocated on demand, of length
49 * LINE_BUFSIZE, head to the start of the ring, tail to the end.*/
50 char *buffer;
51 char *head;
52 char *tail;
53
54 int sigio;
55 struct delayed_work task;
56 const struct line_driver *driver;
57 int have_irq;
58};
59
60#define LINE_INIT(str, d) \
61 { .count_lock = __SPIN_LOCK_UNLOCKED((str).count_lock), \
62 .init_str = str, \
63 .init_pri = INIT_STATIC, \
64 .valid = 1, \
65 .lock = __SPIN_LOCK_UNLOCKED((str).lock), \
66 .driver = d }
67
68extern void line_close(struct tty_struct *tty, struct file * filp);
69extern int line_open(struct line *lines, struct tty_struct *tty);
70extern int line_setup(struct line *lines, unsigned int sizeof_lines,
71 char *init, char **error_out);
72extern int line_write(struct tty_struct *tty, const unsigned char *buf,
73 int len);
74extern int line_put_char(struct tty_struct *tty, unsigned char ch);
75extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
76extern int line_chars_in_buffer(struct tty_struct *tty);
77extern void line_flush_buffer(struct tty_struct *tty);
78extern void line_flush_chars(struct tty_struct *tty);
79extern int line_write_room(struct tty_struct *tty);
80extern int line_ioctl(struct tty_struct *tty, struct file * file,
81 unsigned int cmd, unsigned long arg);
82extern void line_throttle(struct tty_struct *tty);
83extern void line_unthrottle(struct tty_struct *tty);
84
85extern char *add_xterm_umid(char *base);
86extern int line_setup_irq(int fd, int input, int output, struct line *line,
87 void *data);
88extern void line_close_chan(struct line *line);
89extern struct tty_driver *register_lines(struct line_driver *line_driver,
90 const struct tty_operations *driver,
91 struct line *lines, int nlines);
92extern void lines_init(struct line *lines, int nlines, struct chan_opts *opts);
93extern void close_lines(struct line *lines, int nlines);
94
95extern int line_config(struct line *lines, unsigned int sizeof_lines,
96 char *str, const struct chan_opts *opts,
97 char **error_out);
98extern int line_id(char **str, int *start_out, int *end_out);
99extern int line_remove(struct line *lines, unsigned int sizeof_lines, int n,
100 char **error_out);
101extern int line_get_config(char *dev, struct line *lines,
102 unsigned int sizeof_lines, char *str,
103 int size, char **error_out);
104
105#endif
diff --git a/arch/um/include/shared/longjmp.h b/arch/um/include/shared/longjmp.h
new file mode 100644
index 00000000000..e860bc5848e
--- /dev/null
+++ b/arch/um/include/shared/longjmp.h
@@ -0,0 +1,23 @@
1#ifndef __UML_LONGJMP_H
2#define __UML_LONGJMP_H
3
4#include "sysdep/archsetjmp.h"
5#include "os.h"
6
7extern int setjmp(jmp_buf);
8extern void longjmp(jmp_buf, int);
9
10#define UML_LONGJMP(buf, val) do { \
11 longjmp(*buf, val); \
12} while(0)
13
14#define UML_SETJMP(buf) ({ \
15 int n; \
16 volatile int enable; \
17 enable = get_signals(); \
18 n = setjmp(*buf); \
19 if(n != 0) \
20 set_signals(enable); \
21 n; })
22
23#endif
diff --git a/arch/um/include/shared/mconsole.h b/arch/um/include/shared/mconsole.h
new file mode 100644
index 00000000000..c139ae1d682
--- /dev/null
+++ b/arch/um/include/shared/mconsole.h
@@ -0,0 +1,98 @@
1/*
2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org)
3 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 * Licensed under the GPL
5 */
6
7#ifndef __MCONSOLE_H__
8#define __MCONSOLE_H__
9
10#ifndef __KERNEL__
11#include <stdint.h>
12#define u32 uint32_t
13#endif
14
15#include "sysdep/ptrace.h"
16
17#define MCONSOLE_MAGIC (0xcafebabe)
18#define MCONSOLE_MAX_DATA (512)
19#define MCONSOLE_VERSION 2
20
21struct mconsole_request {
22 u32 magic;
23 u32 version;
24 u32 len;
25 char data[MCONSOLE_MAX_DATA];
26};
27
28struct mconsole_reply {
29 u32 err;
30 u32 more;
31 u32 len;
32 char data[MCONSOLE_MAX_DATA];
33};
34
35struct mconsole_notify {
36 u32 magic;
37 u32 version;
38 enum { MCONSOLE_SOCKET, MCONSOLE_PANIC, MCONSOLE_HANG,
39 MCONSOLE_USER_NOTIFY } type;
40 u32 len;
41 char data[MCONSOLE_MAX_DATA];
42};
43
44struct mc_request;
45
46enum mc_context { MCONSOLE_INTR, MCONSOLE_PROC };
47
48struct mconsole_command
49{
50 char *command;
51 void (*handler)(struct mc_request *req);
52 enum mc_context context;
53};
54
55struct mc_request
56{
57 int len;
58 int as_interrupt;
59
60 int originating_fd;
61 unsigned int originlen;
62 unsigned char origin[128]; /* sockaddr_un */
63
64 struct mconsole_request request;
65 struct mconsole_command *cmd;
66 struct uml_pt_regs regs;
67};
68
69extern char mconsole_socket_name[];
70
71extern int mconsole_unlink_socket(void);
72extern int mconsole_reply_len(struct mc_request *req, const char *reply,
73 int len, int err, int more);
74extern int mconsole_reply(struct mc_request *req, const char *str, int err,
75 int more);
76
77extern void mconsole_version(struct mc_request *req);
78extern void mconsole_help(struct mc_request *req);
79extern void mconsole_halt(struct mc_request *req);
80extern void mconsole_reboot(struct mc_request *req);
81extern void mconsole_config(struct mc_request *req);
82extern void mconsole_remove(struct mc_request *req);
83extern void mconsole_sysrq(struct mc_request *req);
84extern void mconsole_cad(struct mc_request *req);
85extern void mconsole_stop(struct mc_request *req);
86extern void mconsole_go(struct mc_request *req);
87extern void mconsole_log(struct mc_request *req);
88extern void mconsole_proc(struct mc_request *req);
89extern void mconsole_stack(struct mc_request *req);
90
91extern int mconsole_get_request(int fd, struct mc_request *req);
92extern int mconsole_notify(char *sock_name, int type, const void *data,
93 int len);
94extern char *mconsole_notify_socket(void);
95extern void lock_notify(void);
96extern void unlock_notify(void);
97
98#endif
diff --git a/arch/um/include/shared/mconsole_kern.h b/arch/um/include/shared/mconsole_kern.h
new file mode 100644
index 00000000000..d2fe07e7895
--- /dev/null
+++ b/arch/um/include/shared/mconsole_kern.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __MCONSOLE_KERN_H__
7#define __MCONSOLE_KERN_H__
8
9#include "linux/list.h"
10#include "mconsole.h"
11
12struct mconsole_entry {
13 struct list_head list;
14 struct mc_request request;
15};
16
17/* All these methods are called in process context. */
18struct mc_device {
19 struct list_head list;
20 char *name;
21 int (*config)(char *, char **);
22 int (*get_config)(char *, char *, int, char **);
23 int (*id)(char **, int *, int *);
24 int (*remove)(int, char **);
25};
26
27#define CONFIG_CHUNK(str, size, current, chunk, end) \
28do { \
29 current += strlen(chunk); \
30 if(current >= size) \
31 str = NULL; \
32 if(str != NULL){ \
33 strcpy(str, chunk); \
34 str += strlen(chunk); \
35 } \
36 if(end) \
37 current++; \
38} while(0)
39
40#ifdef CONFIG_MCONSOLE
41
42extern void mconsole_register_dev(struct mc_device *new);
43
44#else
45
46static inline void mconsole_register_dev(struct mc_device *new)
47{
48}
49
50#endif
51
52#endif
diff --git a/arch/um/include/shared/mem.h b/arch/um/include/shared/mem.h
new file mode 100644
index 00000000000..5cd40e99e8d
--- /dev/null
+++ b/arch/um/include/shared/mem.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __MEM_H__
7#define __MEM_H__
8
9extern int phys_mapping(unsigned long phys, unsigned long long *offset_out);
10
11extern unsigned long uml_physmem;
12static inline unsigned long to_phys(void *virt)
13{
14 return(((unsigned long) virt) - uml_physmem);
15}
16
17static inline void *to_virt(unsigned long phys)
18{
19 return((void *) uml_physmem + phys);
20}
21
22#endif
diff --git a/arch/um/include/shared/mem_kern.h b/arch/um/include/shared/mem_kern.h
new file mode 100644
index 00000000000..cb7e196d366
--- /dev/null
+++ b/arch/um/include/shared/mem_kern.h
@@ -0,0 +1,30 @@
1/*
2 * Copyright (C) 2003 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __MEM_KERN_H__
7#define __MEM_KERN_H__
8
9#include "linux/list.h"
10#include "linux/types.h"
11
12struct remapper {
13 struct list_head list;
14 int (*proc)(int, unsigned long, int, __u64);
15};
16
17extern void register_remapper(struct remapper *info);
18
19#endif
20
21/*
22 * Overrides for Emacs so that we follow Linus's tabbing style.
23 * Emacs will notice this stuff at the end of the file and automatically
24 * adjust the settings for this buffer only. This must remain at the end
25 * of the file.
26 * ---------------------------------------------------------------------------
27 * Local variables:
28 * c-file-style: "linux"
29 * End:
30 */
diff --git a/arch/um/include/shared/mem_user.h b/arch/um/include/shared/mem_user.h
new file mode 100644
index 00000000000..46384acd547
--- /dev/null
+++ b/arch/um/include/shared/mem_user.h
@@ -0,0 +1,62 @@
1/*
2 * arch/um/include/mem_user.h
3 *
4 * BRIEF MODULE DESCRIPTION
5 * user side memory interface for support IO memory inside user mode linux
6 *
7 * Copyright (C) 2001 RidgeRun, Inc.
8 * Author: RidgeRun, Inc.
9 * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#ifndef _MEM_USER_H
33#define _MEM_USER_H
34
35struct iomem_region {
36 struct iomem_region *next;
37 char *driver;
38 int fd;
39 int size;
40 unsigned long phys;
41 unsigned long virt;
42};
43
44extern struct iomem_region *iomem_regions;
45extern int iomem_size;
46
47#define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 << 22) - 1))
48
49extern int init_mem_user(void);
50extern void setup_memory(void *entry);
51extern unsigned long find_iomem(char *driver, unsigned long *len_out);
52extern int init_maps(unsigned long physmem, unsigned long iomem,
53 unsigned long highmem);
54extern unsigned long get_vm(unsigned long len);
55extern void setup_physmem(unsigned long start, unsigned long usable,
56 unsigned long len, unsigned long long highmem);
57extern void add_iomem(char *name, int fd, unsigned long size);
58extern unsigned long phys_offset(unsigned long phys);
59extern void map_memory(unsigned long virt, unsigned long phys,
60 unsigned long len, int r, int w, int x);
61
62#endif
diff --git a/arch/um/include/shared/net_kern.h b/arch/um/include/shared/net_kern.h
new file mode 100644
index 00000000000..d843c7924a7
--- /dev/null
+++ b/arch/um/include/shared/net_kern.h
@@ -0,0 +1,70 @@
1/*
2 * Copyright (C) 2002 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __UM_NET_KERN_H
7#define __UM_NET_KERN_H
8
9#include <linux/netdevice.h>
10#include <linux/platform_device.h>
11#include <linux/skbuff.h>
12#include <linux/socket.h>
13#include <linux/list.h>
14#include <linux/workqueue.h>
15
16struct uml_net {
17 struct list_head list;
18 struct net_device *dev;
19 struct platform_device pdev;
20 int index;
21 unsigned char mac[ETH_ALEN];
22};
23
24struct uml_net_private {
25 struct list_head list;
26 spinlock_t lock;
27 struct net_device *dev;
28 struct timer_list tl;
29 struct net_device_stats stats;
30 struct work_struct work;
31 int fd;
32 unsigned char mac[ETH_ALEN];
33 int max_packet;
34 unsigned short (*protocol)(struct sk_buff *);
35 int (*open)(void *);
36 void (*close)(int, void *);
37 void (*remove)(void *);
38 int (*read)(int, struct sk_buff *skb, struct uml_net_private *);
39 int (*write)(int, struct sk_buff *skb, struct uml_net_private *);
40
41 void (*add_address)(unsigned char *, unsigned char *, void *);
42 void (*delete_address)(unsigned char *, unsigned char *, void *);
43 char user[0];
44};
45
46struct net_kern_info {
47 void (*init)(struct net_device *, void *);
48 unsigned short (*protocol)(struct sk_buff *);
49 int (*read)(int, struct sk_buff *skb, struct uml_net_private *);
50 int (*write)(int, struct sk_buff *skb, struct uml_net_private *);
51};
52
53struct transport {
54 struct list_head list;
55 const char *name;
56 int (* const setup)(char *, char **, void *);
57 const struct net_user_info *user;
58 const struct net_kern_info *kern;
59 const int private_size;
60 const int setup_size;
61};
62
63extern struct net_device *ether_init(int);
64extern unsigned short ether_protocol(struct sk_buff *);
65extern int tap_setup_common(char *str, char *type, char **dev_name,
66 char **mac_out, char **gate_addr);
67extern void register_transport(struct transport *new);
68extern unsigned short eth_protocol(struct sk_buff *skb);
69
70#endif
diff --git a/arch/um/include/shared/net_user.h b/arch/um/include/shared/net_user.h
new file mode 100644
index 00000000000..63bee158cd8
--- /dev/null
+++ b/arch/um/include/shared/net_user.h
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __UM_NET_USER_H__
7#define __UM_NET_USER_H__
8
9#define ETH_ADDR_LEN (6)
10#define ETH_HEADER_ETHERTAP (16)
11#define ETH_HEADER_OTHER (14)
12#define ETH_MAX_PACKET (1500)
13
14#define UML_NET_VERSION (4)
15
16struct net_user_info {
17 int (*init)(void *, void *);
18 int (*open)(void *);
19 void (*close)(int, void *);
20 void (*remove)(void *);
21 void (*add_address)(unsigned char *, unsigned char *, void *);
22 void (*delete_address)(unsigned char *, unsigned char *, void *);
23 int max_packet;
24 int mtu;
25};
26
27extern void ether_user_init(void *data, void *dev);
28extern void iter_addresses(void *d, void (*cb)(unsigned char *,
29 unsigned char *, void *),
30 void *arg);
31
32extern void *get_output_buffer(int *len_out);
33extern void free_output_buffer(void *buffer);
34
35extern int tap_open_common(void *dev, char *gate_addr);
36extern void tap_check_ips(char *gate_addr, unsigned char *eth_addr);
37
38extern void read_output(int fd, char *output_out, int len);
39
40extern int net_read(int fd, void *buf, int len);
41extern int net_recvfrom(int fd, void *buf, int len);
42extern int net_write(int fd, void *buf, int len);
43extern int net_send(int fd, void *buf, int len);
44extern int net_sendto(int fd, void *buf, int len, void *to, int sock_len);
45
46extern void open_addr(unsigned char *addr, unsigned char *netmask, void *arg);
47extern void close_addr(unsigned char *addr, unsigned char *netmask, void *arg);
48
49extern char *split_if_spec(char *str, ...);
50
51extern int dev_netmask(void *d, void *m);
52
53#endif
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
new file mode 100644
index 00000000000..2aaffa04fc8
--- /dev/null
+++ b/arch/um/include/shared/os.h
@@ -0,0 +1,304 @@
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __OS_H__
7#define __OS_H__
8
9#include <stdarg.h>
10#include "irq_user.h"
11#include "longjmp.h"
12#include "mm_id.h"
13#include "sysdep/tls.h"
14#include "../../os/include/file.h"
15
16#define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR))
17
18#define OS_TYPE_FILE 1
19#define OS_TYPE_DIR 2
20#define OS_TYPE_SYMLINK 3
21#define OS_TYPE_CHARDEV 4
22#define OS_TYPE_BLOCKDEV 5
23#define OS_TYPE_FIFO 6
24#define OS_TYPE_SOCK 7
25
26/* os_access() flags */
27#define OS_ACC_F_OK 0 /* Test for existence. */
28#define OS_ACC_X_OK 1 /* Test for execute permission. */
29#define OS_ACC_W_OK 2 /* Test for write permission. */
30#define OS_ACC_R_OK 4 /* Test for read permission. */
31#define OS_ACC_RW_OK (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW permission */
32
33/*
34 * types taken from stat_file() in hostfs_user.c
35 * (if they are wrong here, they are wrong there...).
36 */
37struct uml_stat {
38 int ust_dev; /* device */
39 unsigned long long ust_ino; /* inode */
40 int ust_mode; /* protection */
41 int ust_nlink; /* number of hard links */
42 int ust_uid; /* user ID of owner */
43 int ust_gid; /* group ID of owner */
44 unsigned long long ust_size; /* total size, in bytes */
45 int ust_blksize; /* blocksize for filesystem I/O */
46 unsigned long long ust_blocks; /* number of blocks allocated */
47 unsigned long ust_atime; /* time of last access */
48 unsigned long ust_mtime; /* time of last modification */
49 unsigned long ust_ctime; /* time of last change */
50};
51
52struct openflags {
53 unsigned int r : 1;
54 unsigned int w : 1;
55 unsigned int s : 1; /* O_SYNC */
56 unsigned int c : 1; /* O_CREAT */
57 unsigned int t : 1; /* O_TRUNC */
58 unsigned int a : 1; /* O_APPEND */
59 unsigned int e : 1; /* O_EXCL */
60 unsigned int cl : 1; /* FD_CLOEXEC */
61};
62
63#define OPENFLAGS() ((struct openflags) { .r = 0, .w = 0, .s = 0, .c = 0, \
64 .t = 0, .a = 0, .e = 0, .cl = 0 })
65
66static inline struct openflags of_read(struct openflags flags)
67{
68 flags.r = 1;
69 return flags;
70}
71
72static inline struct openflags of_write(struct openflags flags)
73{
74 flags.w = 1;
75 return flags;
76}
77
78static inline struct openflags of_rdwr(struct openflags flags)
79{
80 return of_read(of_write(flags));
81}
82
83static inline struct openflags of_set_rw(struct openflags flags, int r, int w)
84{
85 flags.r = r;
86 flags.w = w;
87 return flags;
88}
89
90static inline struct openflags of_sync(struct openflags flags)
91{
92 flags.s = 1;
93 return flags;
94}
95
96static inline struct openflags of_create(struct openflags flags)
97{
98 flags.c = 1;
99 return flags;
100}
101
102static inline struct openflags of_trunc(struct openflags flags)
103{
104 flags.t = 1;
105 return flags;
106}
107
108static inline struct openflags of_append(struct openflags flags)
109{
110 flags.a = 1;
111 return flags;
112}
113
114static inline struct openflags of_excl(struct openflags flags)
115{
116 flags.e = 1;
117 return flags;
118}
119
120static inline struct openflags of_cloexec(struct openflags flags)
121{
122 flags.cl = 1;
123 return flags;
124}
125
126/* file.c */
127extern int os_stat_file(const char *file_name, struct uml_stat *buf);
128extern int os_stat_fd(const int fd, struct uml_stat *buf);
129extern int os_access(const char *file, int mode);
130extern int os_set_exec_close(int fd);
131extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
132extern int os_get_ifname(int fd, char *namebuf);
133extern int os_set_slip(int fd);
134extern int os_mode_fd(int fd, int mode);
135
136extern int os_seek_file(int fd, unsigned long long offset);
137extern int os_open_file(const char *file, struct openflags flags, int mode);
138extern int os_read_file(int fd, void *buf, int len);
139extern int os_write_file(int fd, const void *buf, int count);
140extern int os_file_size(const char *file, unsigned long long *size_out);
141extern int os_file_modtime(const char *file, unsigned long *modtime);
142extern int os_pipe(int *fd, int stream, int close_on_exec);
143extern int os_set_fd_async(int fd);
144extern int os_clear_fd_async(int fd);
145extern int os_set_fd_block(int fd, int blocking);
146extern int os_accept_connection(int fd);
147extern int os_create_unix_socket(const char *file, int len, int close_on_exec);
148extern int os_shutdown_socket(int fd, int r, int w);
149extern void os_close_file(int fd);
150extern int os_rcv_fd(int fd, int *helper_pid_out);
151extern int create_unix_socket(char *file, int len, int close_on_exec);
152extern int os_connect_socket(const char *name);
153extern int os_file_type(char *file);
154extern int os_file_mode(const char *file, struct openflags *mode_out);
155extern int os_lock_file(int fd, int excl);
156extern void os_flush_stdout(void);
157extern int os_stat_filesystem(char *path, long *bsize_out,
158 long long *blocks_out, long long *bfree_out,
159 long long *bavail_out, long long *files_out,
160 long long *ffree_out, void *fsid_out,
161 int fsid_size, long *namelen_out,
162 long *spare_out);
163extern int os_change_dir(char *dir);
164extern int os_fchange_dir(int fd);
165
166/* start_up.c */
167extern void os_early_checks(void);
168extern void can_do_skas(void);
169extern void os_check_bugs(void);
170extern void check_host_supports_tls(int *supports_tls, int *tls_min);
171
172/* mem.c */
173extern int create_mem_file(unsigned long long len);
174
175/* process.c */
176extern unsigned long os_process_pc(int pid);
177extern int os_process_parent(int pid);
178extern void os_stop_process(int pid);
179extern void os_kill_process(int pid, int reap_child);
180extern void os_kill_ptraced_process(int pid, int reap_child);
181extern long os_ptrace_ldt(long pid, long addr, long data);
182
183extern int os_getpid(void);
184extern int os_getpgrp(void);
185
186extern void init_new_thread_signals(void);
187extern int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr);
188
189extern int os_map_memory(void *virt, int fd, unsigned long long off,
190 unsigned long len, int r, int w, int x);
191extern int os_protect_memory(void *addr, unsigned long len,
192 int r, int w, int x);
193extern int os_unmap_memory(void *addr, int len);
194extern int os_drop_memory(void *addr, int length);
195extern int can_drop_memory(void);
196extern void os_flush_stdout(void);
197
198/* uaccess.c */
199extern unsigned long __do_user_copy(void *to, const void *from, int n,
200 void **fault_addr, jmp_buf **fault_catcher,
201 void (*op)(void *to, const void *from,
202 int n), int *faulted_out);
203
204/* execvp.c */
205extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
206/* helper.c */
207extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv);
208extern int run_helper_thread(int (*proc)(void *), void *arg,
209 unsigned int flags, unsigned long *stack_out);
210extern int helper_wait(int pid);
211
212
213/* tls.c */
214extern int os_set_thread_area(user_desc_t *info, int pid);
215extern int os_get_thread_area(user_desc_t *info, int pid);
216
217/* umid.c */
218extern int umid_file_name(char *name, char *buf, int len);
219extern int set_umid(char *name);
220extern char *get_umid(void);
221
222/* signal.c */
223extern void timer_init(void);
224extern void set_sigstack(void *sig_stack, int size);
225extern void remove_sigstack(void);
226extern void set_handler(int sig, void (*handler)(int), int flags, ...);
227extern int change_sig(int signal, int on);
228extern void block_signals(void);
229extern void unblock_signals(void);
230extern int get_signals(void);
231extern int set_signals(int enable);
232
233/* util.c */
234extern void stack_protections(unsigned long address);
235extern int raw(int fd);
236extern void setup_machinename(char *machine_out);
237extern void setup_hostinfo(char *buf, int len);
238extern void os_dump_core(void) __attribute__ ((noreturn));
239
240/* time.c */
241extern void idle_sleep(unsigned long long nsecs);
242extern int set_interval(void);
243extern int timer_one_shot(int ticks);
244extern long long disable_timer(void);
245extern void uml_idle_timer(void);
246extern long long os_nsecs(void);
247
248/* skas/mem.c */
249extern long run_syscall_stub(struct mm_id * mm_idp,
250 int syscall, unsigned long *args, long expected,
251 void **addr, int done);
252extern long syscall_stub_data(struct mm_id * mm_idp,
253 unsigned long *data, int data_count,
254 void **addr, void **stub_addr);
255extern int map(struct mm_id * mm_idp, unsigned long virt,
256 unsigned long len, int prot, int phys_fd,
257 unsigned long long offset, int done, void **data);
258extern int unmap(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
259 int done, void **data);
260extern int protect(struct mm_id * mm_idp, unsigned long addr,
261 unsigned long len, unsigned int prot, int done, void **data);
262
263/* skas/process.c */
264extern int is_skas_winch(int pid, int fd, void *data);
265extern int start_userspace(unsigned long stub_stack);
266extern int copy_context_skas0(unsigned long stack, int pid);
267extern void userspace(struct uml_pt_regs *regs);
268extern int map_stub_pages(int fd, unsigned long code, unsigned long data,
269 unsigned long stack);
270extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
271extern void switch_threads(jmp_buf *me, jmp_buf *you);
272extern int start_idle_thread(void *stack, jmp_buf *switch_buf);
273extern void initial_thread_cb_skas(void (*proc)(void *),
274 void *arg);
275extern void halt_skas(void);
276extern void reboot_skas(void);
277
278/* irq.c */
279extern int os_waiting_for_events(struct irq_fd *active_fds);
280extern int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds);
281extern void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
282 struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2);
283extern void os_free_irq_later(struct irq_fd *active_fds,
284 int irq, void *dev_id);
285extern int os_get_pollfd(int i);
286extern void os_set_pollfd(int i, int fd);
287extern void os_set_ioignore(void);
288
289/* sigio.c */
290extern int add_sigio_fd(int fd);
291extern int ignore_sigio_fd(int fd);
292extern void maybe_sigio_broken(int fd, int read);
293extern void sigio_broken(int fd, int read);
294
295/* sys-x86_64/prctl.c */
296extern int os_arch_prctl(int pid, int code, unsigned long *addr);
297
298/* tty.c */
299extern int get_pty(void);
300
301/* sys-$ARCH/task_size.c */
302extern unsigned long os_get_top_address(void);
303
304#endif
diff --git a/arch/um/include/shared/process.h b/arch/um/include/shared/process.h
new file mode 100644
index 00000000000..bb873a51262
--- /dev/null
+++ b/arch/um/include/shared/process.h
@@ -0,0 +1,17 @@
1/*
2 * Copyright (C) 2000 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __PROCESS_H__
7#define __PROCESS_H__
8
9#include <signal.h>
10
11/* Copied from linux/compiler-gcc.h since we can't include it directly */
12#define barrier() __asm__ __volatile__("": : :"memory")
13
14extern void sig_handler(int sig, struct sigcontext *sc);
15extern void alarm_handler(int sig, struct sigcontext *sc);
16
17#endif
diff --git a/arch/um/include/shared/ptrace_user.h b/arch/um/include/shared/ptrace_user.h
new file mode 100644
index 00000000000..4bce6e01288
--- /dev/null
+++ b/arch/um/include/shared/ptrace_user.h
@@ -0,0 +1,55 @@
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __PTRACE_USER_H__
7#define __PTRACE_USER_H__
8
9#include "sysdep/ptrace_user.h"
10
11extern int ptrace_getregs(long pid, unsigned long *regs_out);
12extern int ptrace_setregs(long pid, unsigned long *regs_in);
13
14/* syscall emulation path in ptrace */
15
16#ifndef PTRACE_SYSEMU
17#define PTRACE_SYSEMU 31
18#endif
19#ifndef PTRACE_SYSEMU_SINGLESTEP
20#define PTRACE_SYSEMU_SINGLESTEP 32
21#endif
22
23/* On architectures, that started to support PTRACE_O_TRACESYSGOOD
24 * in linux 2.4, there are two different definitions of
25 * PTRACE_SETOPTIONS: linux 2.4 uses 21 while linux 2.6 uses 0x4200.
26 * For binary compatibility, 2.6 also supports the old "21", named
27 * PTRACE_OLDSETOPTION. On these architectures, UML always must use
28 * "21", to ensure the kernel runs on 2.4 and 2.6 host without
29 * recompilation. So, we use PTRACE_OLDSETOPTIONS in UML.
30 * We also want to be able to build the kernel on 2.4, which doesn't
31 * have PTRACE_OLDSETOPTIONS. So, if it is missing, we declare
32 * PTRACE_OLDSETOPTIONS to to be the same as PTRACE_SETOPTIONS.
33 *
34 * On architectures, that start to support PTRACE_O_TRACESYSGOOD on
35 * linux 2.6, PTRACE_OLDSETOPTIONS never is defined, and also isn't
36 * supported by the host kernel. In that case, our trick lets us use
37 * the new 0x4200 with the name PTRACE_OLDSETOPTIONS.
38 */
39#ifndef PTRACE_OLDSETOPTIONS
40#define PTRACE_OLDSETOPTIONS PTRACE_SETOPTIONS
41#endif
42
43void set_using_sysemu(int value);
44int get_using_sysemu(void);
45extern int sysemu_supported;
46
47#define SELECT_PTRACE_OPERATION(sysemu_mode, singlestep_mode) \
48 (((int[3][3] ) { \
49 { PTRACE_SYSCALL, PTRACE_SYSCALL, PTRACE_SINGLESTEP }, \
50 { PTRACE_SYSEMU, PTRACE_SYSEMU, PTRACE_SINGLESTEP }, \
51 { PTRACE_SYSEMU, PTRACE_SYSEMU_SINGLESTEP, \
52 PTRACE_SYSEMU_SINGLESTEP } }) \
53 [sysemu_mode][singlestep_mode])
54
55#endif
diff --git a/arch/um/include/shared/registers.h b/arch/um/include/shared/registers.h
new file mode 100644
index 00000000000..b0b4589e0eb
--- /dev/null
+++ b/arch/um/include/shared/registers.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) 2004 PathScale, Inc
3 * Licensed under the GPL
4 */
5
6#ifndef __REGISTERS_H
7#define __REGISTERS_H
8
9#include "sysdep/ptrace.h"
10#include "sysdep/archsetjmp.h"
11
12extern int save_fp_registers(int pid, unsigned long *fp_regs);
13extern int restore_fp_registers(int pid, unsigned long *fp_regs);
14extern int save_fpx_registers(int pid, unsigned long *fp_regs);
15extern int restore_fpx_registers(int pid, unsigned long *fp_regs);
16extern int save_registers(int pid, struct uml_pt_regs *regs);
17extern int restore_registers(int pid, struct uml_pt_regs *regs);
18extern int init_registers(int pid);
19extern void get_safe_registers(unsigned long *regs);
20extern unsigned long get_thread_reg(int reg, jmp_buf *buf);
21extern int get_fp_registers(int pid, unsigned long *regs);
22extern int put_fp_registers(int pid, unsigned long *regs);
23
24#endif
diff --git a/arch/um/include/shared/sigcontext.h b/arch/um/include/shared/sigcontext.h
new file mode 100644
index 00000000000..59816ca7a8d
--- /dev/null
+++ b/arch/um/include/shared/sigcontext.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __UML_SIGCONTEXT_H__
7#define __UML_SIGCONTEXT_H__
8
9#include "sysdep/sigcontext.h"
10
11extern int sc_size(void *data);
12extern void sc_to_sc(void *to_ptr, void *from_ptr);
13
14#endif
15
16/*
17 * Overrides for Emacs so that we follow Linus's tabbing style.
18 * Emacs will notice this stuff at the end of the file and automatically
19 * adjust the settings for this buffer only. This must remain at the end
20 * of the file.
21 * ---------------------------------------------------------------------------
22 * Local variables:
23 * c-file-style: "linux"
24 * End:
25 */
diff --git a/arch/um/include/shared/sigio.h b/arch/um/include/shared/sigio.h
new file mode 100644
index 00000000000..434f1a9ae4b
--- /dev/null
+++ b/arch/um/include/shared/sigio.h
@@ -0,0 +1,14 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SIGIO_H__
7#define __SIGIO_H__
8
9extern int write_sigio_irq(int fd);
10extern int register_sigio_fd(int fd);
11extern void sigio_lock(void);
12extern void sigio_unlock(void);
13
14#endif
diff --git a/arch/um/include/shared/skas/mm_id.h b/arch/um/include/shared/skas/mm_id.h
new file mode 100644
index 00000000000..48dd0989dda
--- /dev/null
+++ b/arch/um/include/shared/skas/mm_id.h
@@ -0,0 +1,17 @@
1/*
2 * Copyright (C) 2005 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __MM_ID_H
7#define __MM_ID_H
8
9struct mm_id {
10 union {
11 int mm_fd;
12 int pid;
13 } u;
14 unsigned long stack;
15};
16
17#endif
diff --git a/arch/um/include/shared/skas/proc_mm.h b/arch/um/include/shared/skas/proc_mm.h
new file mode 100644
index 00000000000..90280920960
--- /dev/null
+++ b/arch/um/include/shared/skas/proc_mm.h
@@ -0,0 +1,44 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SKAS_PROC_MM_H
7#define __SKAS_PROC_MM_H
8
9#define MM_MMAP 54
10#define MM_MUNMAP 55
11#define MM_MPROTECT 56
12#define MM_COPY_SEGMENTS 57
13
14struct mm_mmap {
15 unsigned long addr;
16 unsigned long len;
17 unsigned long prot;
18 unsigned long flags;
19 unsigned long fd;
20 unsigned long offset;
21};
22
23struct mm_munmap {
24 unsigned long addr;
25 unsigned long len;
26};
27
28struct mm_mprotect {
29 unsigned long addr;
30 unsigned long len;
31 unsigned int prot;
32};
33
34struct proc_mm_op {
35 int op;
36 union {
37 struct mm_mmap mmap;
38 struct mm_munmap munmap;
39 struct mm_mprotect mprotect;
40 int copy_segments;
41 } u;
42};
43
44#endif
diff --git a/arch/um/include/shared/skas/skas.h b/arch/um/include/shared/skas/skas.h
new file mode 100644
index 00000000000..64d2c744330
--- /dev/null
+++ b/arch/um/include/shared/skas/skas.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SKAS_H
7#define __SKAS_H
8
9#include "sysdep/ptrace.h"
10
11extern int userspace_pid[];
12extern int proc_mm, ptrace_faultinfo, ptrace_ldt;
13extern int skas_needs_stub;
14
15extern int user_thread(unsigned long stack, int flags);
16extern void new_thread_handler(void);
17extern void handle_syscall(struct uml_pt_regs *regs);
18extern int new_mm(unsigned long stack);
19extern long execute_syscall_skas(void *r);
20extern unsigned long current_stub_stack(void);
21
22#endif
diff --git a/arch/um/include/shared/skas/stub-data.h b/arch/um/include/shared/skas/stub-data.h
new file mode 100644
index 00000000000..f6ed92c3727
--- /dev/null
+++ b/arch/um/include/shared/skas/stub-data.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright (C) 2005 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __STUB_DATA_H
7#define __STUB_DATA_H
8
9#include <sys/time.h>
10
11struct stub_data {
12 long offset;
13 int fd;
14 struct itimerval timer;
15 long err;
16};
17
18#endif
diff --git a/arch/um/include/shared/skas_ptrace.h b/arch/um/include/shared/skas_ptrace.h
new file mode 100644
index 00000000000..3d31bbacd01
--- /dev/null
+++ b/arch/um/include/shared/skas_ptrace.h
@@ -0,0 +1,14 @@
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SKAS_PTRACE_H
7#define __SKAS_PTRACE_H
8
9#define PTRACE_FAULTINFO 52
10#define PTRACE_SWITCH_MM 55
11
12#include "sysdep/skas_ptrace.h"
13
14#endif
diff --git a/arch/um/include/shared/skas_ptregs.h b/arch/um/include/shared/skas_ptregs.h
new file mode 100644
index 00000000000..73db19e9c07
--- /dev/null
+++ b/arch/um/include/shared/skas_ptregs.h
@@ -0,0 +1,6 @@
1#ifndef __SKAS_PT_REGS_
2#define __SKAS_PT_REGS_
3
4#include <user_constants.h>
5
6#endif
diff --git a/arch/um/include/shared/syscall.h b/arch/um/include/shared/syscall.h
new file mode 100644
index 00000000000..dda1df901a0
--- /dev/null
+++ b/arch/um/include/shared/syscall.h
@@ -0,0 +1,12 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSCALL_USER_H
7#define __SYSCALL_USER_H
8
9extern int record_syscall_start(int syscall);
10extern void record_syscall_end(int index, long result);
11
12#endif
diff --git a/arch/um/include/shared/sysdep-i386/archsetjmp.h b/arch/um/include/shared/sysdep-i386/archsetjmp.h
new file mode 100644
index 00000000000..0f312085ce1
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/archsetjmp.h
@@ -0,0 +1,22 @@
1/*
2 * arch/um/include/sysdep-i386/archsetjmp.h
3 */
4
5#ifndef _KLIBC_ARCHSETJMP_H
6#define _KLIBC_ARCHSETJMP_H
7
8struct __jmp_buf {
9 unsigned int __ebx;
10 unsigned int __esp;
11 unsigned int __ebp;
12 unsigned int __esi;
13 unsigned int __edi;
14 unsigned int __eip;
15};
16
17typedef struct __jmp_buf jmp_buf[1];
18
19#define JB_IP __eip
20#define JB_SP __esp
21
22#endif /* _SETJMP_H */
diff --git a/arch/um/include/shared/sysdep-i386/barrier.h b/arch/um/include/shared/sysdep-i386/barrier.h
new file mode 100644
index 00000000000..b58d52c5b2f
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/barrier.h
@@ -0,0 +1,9 @@
1#ifndef __SYSDEP_I386_BARRIER_H
2#define __SYSDEP_I386_BARRIER_H
3
4/* Copied from include/asm-i386 for use by userspace. i386 has the option
5 * of using mfence, but I'm just using this, which works everywhere, for now.
6 */
7#define mb() asm volatile("lock; addl $0,0(%esp)")
8
9#endif
diff --git a/arch/um/include/shared/sysdep-i386/checksum.h b/arch/um/include/shared/sysdep-i386/checksum.h
new file mode 100644
index 00000000000..0cb4645cbeb
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/checksum.h
@@ -0,0 +1,211 @@
1/*
2 * Licensed under the GPL
3 */
4
5#ifndef __UM_SYSDEP_CHECKSUM_H
6#define __UM_SYSDEP_CHECKSUM_H
7
8#include "linux/in6.h"
9#include "linux/string.h"
10
11/*
12 * computes the checksum of a memory block at buff, length len,
13 * and adds in "sum" (32-bit)
14 *
15 * returns a 32-bit number suitable for feeding into itself
16 * or csum_tcpudp_magic
17 *
18 * this function must be called with even lengths, except
19 * for the last fragment, which may be odd
20 *
21 * it's best to have buff aligned on a 32-bit boundary
22 */
23__wsum csum_partial(const void *buff, int len, __wsum sum);
24
25/*
26 * Note: when you get a NULL pointer exception here this means someone
27 * passed in an incorrect kernel address to one of these functions.
28 *
29 * If you use these functions directly please don't forget the
30 * access_ok().
31 */
32
33static __inline__
34__wsum csum_partial_copy_nocheck(const void *src, void *dst,
35 int len, __wsum sum)
36{
37 memcpy(dst, src, len);
38 return csum_partial(dst, len, sum);
39}
40
41/*
42 * the same as csum_partial, but copies from src while it
43 * checksums, and handles user-space pointer exceptions correctly, when needed.
44 *
45 * here even more important to align src and dst on a 32-bit (or even
46 * better 64-bit) boundary
47 */
48
49static __inline__
50__wsum csum_partial_copy_from_user(const void __user *src, void *dst,
51 int len, __wsum sum, int *err_ptr)
52{
53 if (copy_from_user(dst, src, len)) {
54 *err_ptr = -EFAULT;
55 return (__force __wsum)-1;
56 }
57
58 return csum_partial(dst, len, sum);
59}
60
61/*
62 * This is a version of ip_compute_csum() optimized for IP headers,
63 * which always checksum on 4 octet boundaries.
64 *
65 * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
66 * Arnt Gulbrandsen.
67 */
68static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
69{
70 unsigned int sum;
71
72 __asm__ __volatile__(
73 "movl (%1), %0 ;\n"
74 "subl $4, %2 ;\n"
75 "jbe 2f ;\n"
76 "addl 4(%1), %0 ;\n"
77 "adcl 8(%1), %0 ;\n"
78 "adcl 12(%1), %0 ;\n"
79"1: adcl 16(%1), %0 ;\n"
80 "lea 4(%1), %1 ;\n"
81 "decl %2 ;\n"
82 "jne 1b ;\n"
83 "adcl $0, %0 ;\n"
84 "movl %0, %2 ;\n"
85 "shrl $16, %0 ;\n"
86 "addw %w2, %w0 ;\n"
87 "adcl $0, %0 ;\n"
88 "notl %0 ;\n"
89"2: ;\n"
90 /* Since the input registers which are loaded with iph and ipl
91 are modified, we must also specify them as outputs, or gcc
92 will assume they contain their original values. */
93 : "=r" (sum), "=r" (iph), "=r" (ihl)
94 : "1" (iph), "2" (ihl)
95 : "memory");
96 return (__force __sum16)sum;
97}
98
99/*
100 * Fold a partial checksum
101 */
102
103static inline __sum16 csum_fold(__wsum sum)
104{
105 __asm__(
106 "addl %1, %0 ;\n"
107 "adcl $0xffff, %0 ;\n"
108 : "=r" (sum)
109 : "r" ((__force u32)sum << 16),
110 "0" ((__force u32)sum & 0xffff0000)
111 );
112 return (__force __sum16)(~(__force u32)sum >> 16);
113}
114
115static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
116 unsigned short len,
117 unsigned short proto,
118 __wsum sum)
119{
120 __asm__(
121 "addl %1, %0 ;\n"
122 "adcl %2, %0 ;\n"
123 "adcl %3, %0 ;\n"
124 "adcl $0, %0 ;\n"
125 : "=r" (sum)
126 : "g" (daddr), "g"(saddr), "g"((len + proto) << 8), "0"(sum));
127 return sum;
128}
129
130/*
131 * computes the checksum of the TCP/UDP pseudo-header
132 * returns a 16-bit checksum, already complemented
133 */
134static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
135 unsigned short len,
136 unsigned short proto,
137 __wsum sum)
138{
139 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
140}
141
142/*
143 * this routine is used for miscellaneous IP-like checksums, mainly
144 * in icmp.c
145 */
146
147static inline __sum16 ip_compute_csum(const void *buff, int len)
148{
149 return csum_fold (csum_partial(buff, len, 0));
150}
151
152#define _HAVE_ARCH_IPV6_CSUM
153static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
154 const struct in6_addr *daddr,
155 __u32 len, unsigned short proto,
156 __wsum sum)
157{
158 __asm__(
159 "addl 0(%1), %0 ;\n"
160 "adcl 4(%1), %0 ;\n"
161 "adcl 8(%1), %0 ;\n"
162 "adcl 12(%1), %0 ;\n"
163 "adcl 0(%2), %0 ;\n"
164 "adcl 4(%2), %0 ;\n"
165 "adcl 8(%2), %0 ;\n"
166 "adcl 12(%2), %0 ;\n"
167 "adcl %3, %0 ;\n"
168 "adcl %4, %0 ;\n"
169 "adcl $0, %0 ;\n"
170 : "=&r" (sum)
171 : "r" (saddr), "r" (daddr),
172 "r"(htonl(len)), "r"(htonl(proto)), "0"(sum));
173
174 return csum_fold(sum);
175}
176
177/*
178 * Copy and checksum to user
179 */
180#define HAVE_CSUM_COPY_USER
181static __inline__ __wsum csum_and_copy_to_user(const void *src,
182 void __user *dst,
183 int len, __wsum sum, int *err_ptr)
184{
185 if (access_ok(VERIFY_WRITE, dst, len)) {
186 if (copy_to_user(dst, src, len)) {
187 *err_ptr = -EFAULT;
188 return (__force __wsum)-1;
189 }
190
191 return csum_partial(src, len, sum);
192 }
193
194 if (len)
195 *err_ptr = -EFAULT;
196
197 return (__force __wsum)-1; /* invalid checksum */
198}
199
200#endif
201
202/*
203 * Overrides for Emacs so that we follow Linus's tabbing style.
204 * Emacs will notice this stuff at the end of the file and automatically
205 * adjust the settings for this buffer only. This must remain at the end
206 * of the file.
207 * ---------------------------------------------------------------------------
208 * Local variables:
209 * c-file-style: "linux"
210 * End:
211 */
diff --git a/arch/um/include/shared/sysdep-i386/faultinfo.h b/arch/um/include/shared/sysdep-i386/faultinfo.h
new file mode 100644
index 00000000000..db437cc373b
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/faultinfo.h
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2004 Fujitsu Siemens Computers GmbH
3 * Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
4 * Licensed under the GPL
5 */
6
7#ifndef __FAULTINFO_I386_H
8#define __FAULTINFO_I386_H
9
10/* this structure contains the full arch-specific faultinfo
11 * from the traps.
12 * On i386, ptrace_faultinfo unfortunately doesn't provide
13 * all the info, since trap_no is missing.
14 * All common elements are defined at the same position in
15 * both structures, thus making it easy to copy the
16 * contents without knowledge about the structure elements.
17 */
18struct faultinfo {
19 int error_code; /* in ptrace_faultinfo misleadingly called is_write */
20 unsigned long cr2; /* in ptrace_faultinfo called addr */
21 int trap_no; /* missing in ptrace_faultinfo */
22};
23
24#define FAULT_WRITE(fi) ((fi).error_code & 2)
25#define FAULT_ADDRESS(fi) ((fi).cr2)
26
27#define PTRACE_FULL_FAULTINFO 0
28
29#endif
diff --git a/arch/um/include/shared/sysdep-i386/kernel-offsets.h b/arch/um/include/shared/sysdep-i386/kernel-offsets.h
new file mode 100644
index 00000000000..5868526b5ee
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/kernel-offsets.h
@@ -0,0 +1,21 @@
1#include <linux/stddef.h>
2#include <linux/sched.h>
3#include <linux/elf.h>
4#include <linux/crypto.h>
5#include <asm/mman.h>
6
7#define DEFINE(sym, val) \
8 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
9
10#define STR(x) #x
11#define DEFINE_STR(sym, val) asm volatile("\n->" #sym " " STR(val) " " #val: : )
12
13#define BLANK() asm volatile("\n->" : : )
14
15#define OFFSET(sym, str, mem) \
16 DEFINE(sym, offsetof(struct str, mem));
17
18void foo(void)
19{
20#include <common-offsets.h>
21}
diff --git a/arch/um/include/shared/sysdep-i386/ptrace.h b/arch/um/include/shared/sysdep-i386/ptrace.h
new file mode 100644
index 00000000000..11c08969d13
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/ptrace.h
@@ -0,0 +1,171 @@
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_I386_PTRACE_H
7#define __SYSDEP_I386_PTRACE_H
8
9#include "uml-config.h"
10#include "user_constants.h"
11#include "sysdep/faultinfo.h"
12
13#define MAX_REG_NR (UM_FRAME_SIZE / sizeof(unsigned long))
14#define MAX_REG_OFFSET (UM_FRAME_SIZE)
15
16static inline void update_debugregs(int seq) {}
17
18/* syscall emulation path in ptrace */
19
20#ifndef PTRACE_SYSEMU
21#define PTRACE_SYSEMU 31
22#endif
23
24void set_using_sysemu(int value);
25int get_using_sysemu(void);
26extern int sysemu_supported;
27
28#include "skas_ptregs.h"
29
30#define REGS_IP(r) ((r)[HOST_IP])
31#define REGS_SP(r) ((r)[HOST_SP])
32#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
33#define REGS_EAX(r) ((r)[HOST_EAX])
34#define REGS_EBX(r) ((r)[HOST_EBX])
35#define REGS_ECX(r) ((r)[HOST_ECX])
36#define REGS_EDX(r) ((r)[HOST_EDX])
37#define REGS_ESI(r) ((r)[HOST_ESI])
38#define REGS_EDI(r) ((r)[HOST_EDI])
39#define REGS_EBP(r) ((r)[HOST_EBP])
40#define REGS_CS(r) ((r)[HOST_CS])
41#define REGS_SS(r) ((r)[HOST_SS])
42#define REGS_DS(r) ((r)[HOST_DS])
43#define REGS_ES(r) ((r)[HOST_ES])
44#define REGS_FS(r) ((r)[HOST_FS])
45#define REGS_GS(r) ((r)[HOST_GS])
46
47#define REGS_SET_SYSCALL_RETURN(r, res) REGS_EAX(r) = (res)
48
49#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
50
51#ifndef PTRACE_SYSEMU_SINGLESTEP
52#define PTRACE_SYSEMU_SINGLESTEP 32
53#endif
54
55struct uml_pt_regs {
56 unsigned long gp[MAX_REG_NR];
57 struct faultinfo faultinfo;
58 long syscall;
59 int is_user;
60};
61
62#define EMPTY_UML_PT_REGS { }
63
64#define UPT_IP(r) REGS_IP((r)->gp)
65#define UPT_SP(r) REGS_SP((r)->gp)
66#define UPT_EFLAGS(r) REGS_EFLAGS((r)->gp)
67#define UPT_EAX(r) REGS_EAX((r)->gp)
68#define UPT_EBX(r) REGS_EBX((r)->gp)
69#define UPT_ECX(r) REGS_ECX((r)->gp)
70#define UPT_EDX(r) REGS_EDX((r)->gp)
71#define UPT_ESI(r) REGS_ESI((r)->gp)
72#define UPT_EDI(r) REGS_EDI((r)->gp)
73#define UPT_EBP(r) REGS_EBP((r)->gp)
74#define UPT_ORIG_EAX(r) ((r)->syscall)
75#define UPT_CS(r) REGS_CS((r)->gp)
76#define UPT_SS(r) REGS_SS((r)->gp)
77#define UPT_DS(r) REGS_DS((r)->gp)
78#define UPT_ES(r) REGS_ES((r)->gp)
79#define UPT_FS(r) REGS_FS((r)->gp)
80#define UPT_GS(r) REGS_GS((r)->gp)
81
82#define UPT_SYSCALL_ARG1(r) UPT_EBX(r)
83#define UPT_SYSCALL_ARG2(r) UPT_ECX(r)
84#define UPT_SYSCALL_ARG3(r) UPT_EDX(r)
85#define UPT_SYSCALL_ARG4(r) UPT_ESI(r)
86#define UPT_SYSCALL_ARG5(r) UPT_EDI(r)
87#define UPT_SYSCALL_ARG6(r) UPT_EBP(r)
88
89extern int user_context(unsigned long sp);
90
91#define UPT_IS_USER(r) ((r)->is_user)
92
93struct syscall_args {
94 unsigned long args[6];
95};
96
97#define SYSCALL_ARGS(r) ((struct syscall_args) \
98 { .args = { UPT_SYSCALL_ARG1(r), \
99 UPT_SYSCALL_ARG2(r), \
100 UPT_SYSCALL_ARG3(r), \
101 UPT_SYSCALL_ARG4(r), \
102 UPT_SYSCALL_ARG5(r), \
103 UPT_SYSCALL_ARG6(r) } } )
104
105#define UPT_REG(regs, reg) \
106 ({ unsigned long val; \
107 switch(reg){ \
108 case EIP: val = UPT_IP(regs); break; \
109 case UESP: val = UPT_SP(regs); break; \
110 case EAX: val = UPT_EAX(regs); break; \
111 case EBX: val = UPT_EBX(regs); break; \
112 case ECX: val = UPT_ECX(regs); break; \
113 case EDX: val = UPT_EDX(regs); break; \
114 case ESI: val = UPT_ESI(regs); break; \
115 case EDI: val = UPT_EDI(regs); break; \
116 case EBP: val = UPT_EBP(regs); break; \
117 case ORIG_EAX: val = UPT_ORIG_EAX(regs); break; \
118 case CS: val = UPT_CS(regs); break; \
119 case SS: val = UPT_SS(regs); break; \
120 case DS: val = UPT_DS(regs); break; \
121 case ES: val = UPT_ES(regs); break; \
122 case FS: val = UPT_FS(regs); break; \
123 case GS: val = UPT_GS(regs); break; \
124 case EFL: val = UPT_EFLAGS(regs); break; \
125 default : \
126 panic("Bad register in UPT_REG : %d\n", reg); \
127 val = -1; \
128 } \
129 val; \
130 })
131
132#define UPT_SET(regs, reg, val) \
133 do { \
134 switch(reg){ \
135 case EIP: UPT_IP(regs) = val; break; \
136 case UESP: UPT_SP(regs) = val; break; \
137 case EAX: UPT_EAX(regs) = val; break; \
138 case EBX: UPT_EBX(regs) = val; break; \
139 case ECX: UPT_ECX(regs) = val; break; \
140 case EDX: UPT_EDX(regs) = val; break; \
141 case ESI: UPT_ESI(regs) = val; break; \
142 case EDI: UPT_EDI(regs) = val; break; \
143 case EBP: UPT_EBP(regs) = val; break; \
144 case ORIG_EAX: UPT_ORIG_EAX(regs) = val; break; \
145 case CS: UPT_CS(regs) = val; break; \
146 case SS: UPT_SS(regs) = val; break; \
147 case DS: UPT_DS(regs) = val; break; \
148 case ES: UPT_ES(regs) = val; break; \
149 case FS: UPT_FS(regs) = val; break; \
150 case GS: UPT_GS(regs) = val; break; \
151 case EFL: UPT_EFLAGS(regs) = val; break; \
152 default : \
153 panic("Bad register in UPT_SET : %d\n", reg); \
154 break; \
155 } \
156 } while (0)
157
158#define UPT_SET_SYSCALL_RETURN(r, res) \
159 REGS_SET_SYSCALL_RETURN((r)->regs, (res))
160
161#define UPT_RESTART_SYSCALL(r) REGS_RESTART_SYSCALL((r)->gp)
162
163#define UPT_ORIG_SYSCALL(r) UPT_EAX(r)
164#define UPT_SYSCALL_NR(r) UPT_ORIG_EAX(r)
165#define UPT_SYSCALL_RET(r) UPT_EAX(r)
166
167#define UPT_FAULTINFO(r) (&(r)->faultinfo)
168
169extern void arch_init_registers(int pid);
170
171#endif
diff --git a/arch/um/include/shared/sysdep-i386/ptrace_user.h b/arch/um/include/shared/sysdep-i386/ptrace_user.h
new file mode 100644
index 00000000000..ef56247e414
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/ptrace_user.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_I386_PTRACE_USER_H__
7#define __SYSDEP_I386_PTRACE_USER_H__
8
9#include <sys/ptrace.h>
10#include <linux/ptrace.h>
11#include <asm/ptrace.h>
12#include "user_constants.h"
13
14#define PT_OFFSET(r) ((r) * sizeof(long))
15
16#define PT_SYSCALL_NR(regs) ((regs)[ORIG_EAX])
17#define PT_SYSCALL_NR_OFFSET PT_OFFSET(ORIG_EAX)
18
19#define PT_SYSCALL_ARG1_OFFSET PT_OFFSET(EBX)
20#define PT_SYSCALL_ARG2_OFFSET PT_OFFSET(ECX)
21#define PT_SYSCALL_ARG3_OFFSET PT_OFFSET(EDX)
22#define PT_SYSCALL_ARG4_OFFSET PT_OFFSET(ESI)
23#define PT_SYSCALL_ARG5_OFFSET PT_OFFSET(EDI)
24#define PT_SYSCALL_ARG6_OFFSET PT_OFFSET(EBP)
25
26#define PT_SYSCALL_RET_OFFSET PT_OFFSET(EAX)
27
28#define REGS_SYSCALL_NR EAX /* This is used before a system call */
29#define REGS_SYSCALL_ARG1 EBX
30#define REGS_SYSCALL_ARG2 ECX
31#define REGS_SYSCALL_ARG3 EDX
32#define REGS_SYSCALL_ARG4 ESI
33#define REGS_SYSCALL_ARG5 EDI
34#define REGS_SYSCALL_ARG6 EBP
35
36#define REGS_IP_INDEX EIP
37#define REGS_SP_INDEX UESP
38
39#define PT_IP_OFFSET PT_OFFSET(EIP)
40#define PT_IP(regs) ((regs)[EIP])
41#define PT_SP_OFFSET PT_OFFSET(UESP)
42#define PT_SP(regs) ((regs)[UESP])
43
44#define FP_SIZE ((HOST_FPX_SIZE > HOST_FP_SIZE) ? HOST_FPX_SIZE : HOST_FP_SIZE)
45
46#ifndef FRAME_SIZE
47#define FRAME_SIZE (17)
48#endif
49
50#endif
diff --git a/arch/um/include/shared/sysdep-i386/sc.h b/arch/um/include/shared/sysdep-i386/sc.h
new file mode 100644
index 00000000000..c57d1780ad3
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/sc.h
@@ -0,0 +1,44 @@
1#ifndef __SYSDEP_I386_SC_H
2#define __SYSDEP_I386_SC_H
3
4#include <user_constants.h>
5
6#define SC_OFFSET(sc, field) \
7 *((unsigned long *) &(((char *) (sc))[HOST_##field]))
8#define SC_FP_OFFSET(sc, field) \
9 *((unsigned long *) &(((char *) (SC_FPSTATE(sc)))[HOST_##field]))
10#define SC_FP_OFFSET_PTR(sc, field, type) \
11 ((type *) &(((char *) (SC_FPSTATE(sc)))[HOST_##field]))
12
13#define SC_IP(sc) SC_OFFSET(sc, SC_IP)
14#define SC_SP(sc) SC_OFFSET(sc, SC_SP)
15#define SC_FS(sc) SC_OFFSET(sc, SC_FS)
16#define SC_GS(sc) SC_OFFSET(sc, SC_GS)
17#define SC_DS(sc) SC_OFFSET(sc, SC_DS)
18#define SC_ES(sc) SC_OFFSET(sc, SC_ES)
19#define SC_SS(sc) SC_OFFSET(sc, SC_SS)
20#define SC_CS(sc) SC_OFFSET(sc, SC_CS)
21#define SC_EFLAGS(sc) SC_OFFSET(sc, SC_EFLAGS)
22#define SC_EAX(sc) SC_OFFSET(sc, SC_EAX)
23#define SC_EBX(sc) SC_OFFSET(sc, SC_EBX)
24#define SC_ECX(sc) SC_OFFSET(sc, SC_ECX)
25#define SC_EDX(sc) SC_OFFSET(sc, SC_EDX)
26#define SC_EDI(sc) SC_OFFSET(sc, SC_EDI)
27#define SC_ESI(sc) SC_OFFSET(sc, SC_ESI)
28#define SC_EBP(sc) SC_OFFSET(sc, SC_EBP)
29#define SC_TRAPNO(sc) SC_OFFSET(sc, SC_TRAPNO)
30#define SC_ERR(sc) SC_OFFSET(sc, SC_ERR)
31#define SC_CR2(sc) SC_OFFSET(sc, SC_CR2)
32#define SC_FPSTATE(sc) SC_OFFSET(sc, SC_FPSTATE)
33#define SC_SIGMASK(sc) SC_OFFSET(sc, SC_SIGMASK)
34#define SC_FP_CW(sc) SC_FP_OFFSET(sc, SC_FP_CW)
35#define SC_FP_SW(sc) SC_FP_OFFSET(sc, SC_FP_SW)
36#define SC_FP_TAG(sc) SC_FP_OFFSET(sc, SC_FP_TAG)
37#define SC_FP_IPOFF(sc) SC_FP_OFFSET(sc, SC_FP_IPOFF)
38#define SC_FP_CSSEL(sc) SC_FP_OFFSET(sc, SC_FP_CSSEL)
39#define SC_FP_DATAOFF(sc) SC_FP_OFFSET(sc, SC_FP_DATAOFF)
40#define SC_FP_DATASEL(sc) SC_FP_OFFSET(sc, SC_FP_DATASEL)
41#define SC_FP_ST(sc) SC_FP_OFFSET_PTR(sc, SC_FP_ST, struct _fpstate)
42#define SC_FXSR_ENV(sc) SC_FP_OFFSET_PTR(sc, SC_FXSR_ENV, void)
43
44#endif
diff --git a/arch/um/include/shared/sysdep-i386/sigcontext.h b/arch/um/include/shared/sysdep-i386/sigcontext.h
new file mode 100644
index 00000000000..f583c87111a
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/sigcontext.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYS_SIGCONTEXT_I386_H
7#define __SYS_SIGCONTEXT_I386_H
8
9#include "sysdep/sc.h"
10
11#define IP_RESTART_SYSCALL(ip) ((ip) -= 2)
12
13#define GET_FAULTINFO_FROM_SC(fi, sc) \
14 { \
15 (fi).cr2 = SC_CR2(sc); \
16 (fi).error_code = SC_ERR(sc); \
17 (fi).trap_no = SC_TRAPNO(sc); \
18 }
19
20/* This is Page Fault */
21#define SEGV_IS_FIXABLE(fi) ((fi)->trap_no == 14)
22
23/* SKAS3 has no trap_no on i386, but get_skas_faultinfo() sets it to 0. */
24#define SEGV_MAYBE_FIXABLE(fi) ((fi)->trap_no == 0 && ptrace_faultinfo)
25
26#endif
diff --git a/arch/um/include/shared/sysdep-i386/skas_ptrace.h b/arch/um/include/shared/sysdep-i386/skas_ptrace.h
new file mode 100644
index 00000000000..e27b8a79177
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/skas_ptrace.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_I386_SKAS_PTRACE_H
7#define __SYSDEP_I386_SKAS_PTRACE_H
8
9struct ptrace_faultinfo {
10 int is_write;
11 unsigned long addr;
12};
13
14struct ptrace_ldt {
15 int func;
16 void *ptr;
17 unsigned long bytecount;
18};
19
20#define PTRACE_LDT 54
21
22#endif
diff --git a/arch/um/include/shared/sysdep-i386/stub.h b/arch/um/include/shared/sysdep-i386/stub.h
new file mode 100644
index 00000000000..8c097b87fca
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/stub.h
@@ -0,0 +1,102 @@
1/*
2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_STUB_H
7#define __SYSDEP_STUB_H
8
9#include <sys/mman.h>
10#include <asm/ptrace.h>
11#include <asm/unistd.h>
12#include "as-layout.h"
13#include "stub-data.h"
14#include "kern_constants.h"
15#include "uml-config.h"
16
17extern void stub_segv_handler(int sig);
18extern void stub_clone_handler(void);
19
20#define STUB_SYSCALL_RET EAX
21#define STUB_MMAP_NR __NR_mmap2
22#define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT)
23
24static inline long stub_syscall0(long syscall)
25{
26 long ret;
27
28 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
29
30 return ret;
31}
32
33static inline long stub_syscall1(long syscall, long arg1)
34{
35 long ret;
36
37 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
38
39 return ret;
40}
41
42static inline long stub_syscall2(long syscall, long arg1, long arg2)
43{
44 long ret;
45
46 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
47 "c" (arg2));
48
49 return ret;
50}
51
52static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
53{
54 long ret;
55
56 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
57 "c" (arg2), "d" (arg3));
58
59 return ret;
60}
61
62static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
63 long arg4)
64{
65 long ret;
66
67 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
68 "c" (arg2), "d" (arg3), "S" (arg4));
69
70 return ret;
71}
72
73static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
74 long arg4, long arg5)
75{
76 long ret;
77
78 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
79 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
80
81 return ret;
82}
83
84static inline void trap_myself(void)
85{
86 __asm("int3");
87}
88
89static inline void remap_stack(int fd, unsigned long offset)
90{
91 __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;"
92 "movl %7, %%ebx ; movl %%eax, (%%ebx)"
93 : : "g" (STUB_MMAP_NR), "b" (STUB_DATA),
94 "c" (UM_KERN_PAGE_SIZE),
95 "d" (PROT_READ | PROT_WRITE),
96 "S" (MAP_FIXED | MAP_SHARED), "D" (fd),
97 "a" (offset),
98 "i" (&((struct stub_data *) STUB_DATA)->err)
99 : "memory");
100}
101
102#endif
diff --git a/arch/um/include/shared/sysdep-i386/syscalls.h b/arch/um/include/shared/sysdep-i386/syscalls.h
new file mode 100644
index 00000000000..905698197e3
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/syscalls.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2000 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#include "asm/unistd.h"
7#include "sysdep/ptrace.h"
8
9typedef long syscall_handler_t(struct pt_regs);
10
11/* Not declared on x86, incompatible declarations on x86_64, so these have
12 * to go here rather than in sys_call_table.c
13 */
14extern syscall_handler_t sys_rt_sigaction;
15
16extern syscall_handler_t old_mmap_i386;
17
18extern syscall_handler_t *sys_call_table[];
19
20#define EXECUTE_SYSCALL(syscall, regs) \
21 ((long (*)(struct syscall_args)) \
22 (*sys_call_table[syscall]))(SYSCALL_ARGS(&regs->regs))
23
24extern long sys_mmap2(unsigned long addr, unsigned long len,
25 unsigned long prot, unsigned long flags,
26 unsigned long fd, unsigned long pgoff);
diff --git a/arch/um/include/shared/sysdep-i386/tls.h b/arch/um/include/shared/sysdep-i386/tls.h
new file mode 100644
index 00000000000..918fd3c5ff9
--- /dev/null
+++ b/arch/um/include/shared/sysdep-i386/tls.h
@@ -0,0 +1,32 @@
1#ifndef _SYSDEP_TLS_H
2#define _SYSDEP_TLS_H
3
4# ifndef __KERNEL__
5
6/* Change name to avoid conflicts with the original one from <asm/ldt.h>, which
7 * may be named user_desc (but in 2.4 and in header matching its API was named
8 * modify_ldt_ldt_s). */
9
10typedef struct um_dup_user_desc {
11 unsigned int entry_number;
12 unsigned int base_addr;
13 unsigned int limit;
14 unsigned int seg_32bit:1;
15 unsigned int contents:2;
16 unsigned int read_exec_only:1;
17 unsigned int limit_in_pages:1;
18 unsigned int seg_not_present:1;
19 unsigned int useable:1;
20} user_desc_t;
21
22# else /* __KERNEL__ */
23
24# include <asm/ldt.h>
25typedef struct user_desc user_desc_t;
26
27# endif /* __KERNEL__ */
28
29#define GDT_ENTRY_TLS_MIN_I386 6
30#define GDT_ENTRY_TLS_MIN_X86_64 12
31
32#endif /* _SYSDEP_TLS_H */
diff --git a/arch/um/include/shared/sysdep-ia64/ptrace.h b/arch/um/include/shared/sysdep-ia64/ptrace.h
new file mode 100644
index 00000000000..42dd8fb6f2f
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ia64/ptrace.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_IA64_PTRACE_H
7#define __SYSDEP_IA64_PTRACE_H
8
9struct sys_pt_regs {
10 int foo;
11};
12
13#define EMPTY_REGS { 0 }
14
15#endif
16
17/*
18 * Overrides for Emacs so that we follow Linus's tabbing style.
19 * Emacs will notice this stuff at the end of the file and automatically
20 * adjust the settings for this buffer only. This must remain at the end
21 * of the file.
22 * ---------------------------------------------------------------------------
23 * Local variables:
24 * c-file-style: "linux"
25 * End:
26 */
diff --git a/arch/um/include/shared/sysdep-ia64/sigcontext.h b/arch/um/include/shared/sysdep-ia64/sigcontext.h
new file mode 100644
index 00000000000..f15fb25260b
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ia64/sigcontext.h
@@ -0,0 +1,20 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_IA64_SIGCONTEXT_H
7#define __SYSDEP_IA64_SIGCONTEXT_H
8
9#endif
10
11/*
12 * Overrides for Emacs so that we follow Linus's tabbing style.
13 * Emacs will notice this stuff at the end of the file and automatically
14 * adjust the settings for this buffer only. This must remain at the end
15 * of the file.
16 * ---------------------------------------------------------------------------
17 * Local variables:
18 * c-file-style: "linux"
19 * End:
20 */
diff --git a/arch/um/include/shared/sysdep-ia64/skas_ptrace.h b/arch/um/include/shared/sysdep-ia64/skas_ptrace.h
new file mode 100644
index 00000000000..25a38e71570
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ia64/skas_ptrace.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_IA64_SKAS_PTRACE_H
7#define __SYSDEP_IA64_SKAS_PTRACE_H
8
9struct ptrace_faultinfo {
10 int is_write;
11 unsigned long addr;
12};
13
14struct ptrace_ldt {
15 int func;
16 void *ptr;
17 unsigned long bytecount;
18};
19
20#define PTRACE_LDT 54
21
22#endif
diff --git a/arch/um/include/shared/sysdep-ia64/syscalls.h b/arch/um/include/shared/sysdep-ia64/syscalls.h
new file mode 100644
index 00000000000..4a1f46ef1eb
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ia64/syscalls.h
@@ -0,0 +1,20 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_IA64_SYSCALLS_H
7#define __SYSDEP_IA64_SYSCALLS_H
8
9#endif
10
11/*
12 * Overrides for Emacs so that we follow Linus's tabbing style.
13 * Emacs will notice this stuff at the end of the file and automatically
14 * adjust the settings for this buffer only. This must remain at the end
15 * of the file.
16 * ---------------------------------------------------------------------------
17 * Local variables:
18 * c-file-style: "linux"
19 * End:
20 */
diff --git a/arch/um/include/shared/sysdep-ppc/ptrace.h b/arch/um/include/shared/sysdep-ppc/ptrace.h
new file mode 100644
index 00000000000..df2397dba3e
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ppc/ptrace.h
@@ -0,0 +1,103 @@
1/*
2 * Licensed under the GPL
3 */
4
5#ifndef __SYS_PTRACE_PPC_H
6#define __SYS_PTRACE_PPC_H
7
8#include "linux/types.h"
9
10/* the following taken from <asm-ppc/ptrace.h> */
11
12#ifdef CONFIG_PPC64
13#define PPC_REG unsigned long /*long*/
14#else
15#define PPC_REG unsigned long
16#endif
17struct sys_pt_regs_s {
18 PPC_REG gpr[32];
19 PPC_REG nip;
20 PPC_REG msr;
21 PPC_REG orig_gpr3; /* Used for restarting system calls */
22 PPC_REG ctr;
23 PPC_REG link;
24 PPC_REG xer;
25 PPC_REG ccr;
26 PPC_REG mq; /* 601 only (not used at present) */
27 /* Used on APUS to hold IPL value. */
28 PPC_REG trap; /* Reason for being here */
29 PPC_REG dar; /* Fault registers */
30 PPC_REG dsisr;
31 PPC_REG result; /* Result of a system call */
32};
33
34#define NUM_REGS (sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG))
35
36struct sys_pt_regs {
37 PPC_REG regs[sizeof(struct sys_pt_regs_s) / sizeof(PPC_REG)];
38};
39
40#define UM_MAX_REG (PT_FPR0)
41#define UM_MAX_REG_OFFSET (UM_MAX_REG * sizeof(PPC_REG))
42
43#define EMPTY_REGS { { [ 0 ... NUM_REGS - 1] = 0 } }
44
45#define UM_REG(r, n) ((r)->regs[n])
46
47#define UM_SYSCALL_RET(r) UM_REG(r, PT_R3)
48#define UM_SP(r) UM_REG(r, PT_R1)
49#define UM_IP(r) UM_REG(r, PT_NIP)
50#define UM_ELF_ZERO(r) UM_REG(r, PT_FPSCR)
51#define UM_SYSCALL_NR(r) UM_REG(r, PT_R0)
52#define UM_SYSCALL_ARG1(r) UM_REG(r, PT_ORIG_R3)
53#define UM_SYSCALL_ARG2(r) UM_REG(r, PT_R4)
54#define UM_SYSCALL_ARG3(r) UM_REG(r, PT_R5)
55#define UM_SYSCALL_ARG4(r) UM_REG(r, PT_R6)
56#define UM_SYSCALL_ARG5(r) UM_REG(r, PT_R7)
57#define UM_SYSCALL_ARG6(r) UM_REG(r, PT_R8)
58
59#define UM_SYSCALL_NR_OFFSET (PT_R0 * sizeof(PPC_REG))
60#define UM_SYSCALL_RET_OFFSET (PT_R3 * sizeof(PPC_REG))
61#define UM_SYSCALL_ARG1_OFFSET (PT_R3 * sizeof(PPC_REG))
62#define UM_SYSCALL_ARG2_OFFSET (PT_R4 * sizeof(PPC_REG))
63#define UM_SYSCALL_ARG3_OFFSET (PT_R5 * sizeof(PPC_REG))
64#define UM_SYSCALL_ARG4_OFFSET (PT_R6 * sizeof(PPC_REG))
65#define UM_SYSCALL_ARG5_OFFSET (PT_R7 * sizeof(PPC_REG))
66#define UM_SYSCALL_ARG6_OFFSET (PT_R8 * sizeof(PPC_REG))
67#define UM_SP_OFFSET (PT_R1 * sizeof(PPC_REG))
68#define UM_IP_OFFSET (PT_NIP * sizeof(PPC_REG))
69#define UM_ELF_ZERO_OFFSET (PT_R3 * sizeof(PPC_REG))
70
71#define UM_SET_SYSCALL_RETURN(_regs, result) \
72do { \
73 if (result < 0) { \
74 (_regs)->regs[PT_CCR] |= 0x10000000; \
75 UM_SYSCALL_RET((_regs)) = -result; \
76 } else { \
77 UM_SYSCALL_RET((_regs)) = result; \
78 } \
79} while(0)
80
81extern void shove_aux_table(unsigned long sp);
82#define UM_FIX_EXEC_STACK(sp) shove_aux_table(sp);
83
84/* These aren't actually defined. The undefs are just to make sure
85 * everyone's clear on the concept.
86 */
87#undef UML_HAVE_GETREGS
88#undef UML_HAVE_GETFPREGS
89#undef UML_HAVE_SETREGS
90#undef UML_HAVE_SETFPREGS
91
92#endif
93
94/*
95 * Overrides for Emacs so that we follow Linus's tabbing style.
96 * Emacs will notice this stuff at the end of the file and automatically
97 * adjust the settings for this buffer only. This must remain at the end
98 * of the file.
99 * ---------------------------------------------------------------------------
100 * Local variables:
101 * c-file-style: "linux"
102 * End:
103 */
diff --git a/arch/um/include/shared/sysdep-ppc/sigcontext.h b/arch/um/include/shared/sysdep-ppc/sigcontext.h
new file mode 100644
index 00000000000..f20d965de9c
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ppc/sigcontext.h
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYS_SIGCONTEXT_PPC_H
7#define __SYS_SIGCONTEXT_PPC_H
8
9#define DSISR_WRITE 0x02000000
10
11#define SC_FAULT_ADDR(sc) ({ \
12 struct sigcontext *_sc = (sc); \
13 long retval = -1; \
14 switch (_sc->regs->trap) { \
15 case 0x300: \
16 /* data exception */ \
17 retval = _sc->regs->dar; \
18 break; \
19 case 0x400: \
20 /* instruction exception */ \
21 retval = _sc->regs->nip; \
22 break; \
23 default: \
24 panic("SC_FAULT_ADDR: unhandled trap type\n"); \
25 } \
26 retval; \
27 })
28
29#define SC_FAULT_WRITE(sc) ({ \
30 struct sigcontext *_sc = (sc); \
31 long retval = -1; \
32 switch (_sc->regs->trap) { \
33 case 0x300: \
34 /* data exception */ \
35 retval = !!(_sc->regs->dsisr & DSISR_WRITE); \
36 break; \
37 case 0x400: \
38 /* instruction exception: not a write */ \
39 retval = 0; \
40 break; \
41 default: \
42 panic("SC_FAULT_ADDR: unhandled trap type\n"); \
43 } \
44 retval; \
45 })
46
47#define SC_IP(sc) ((sc)->regs->nip)
48#define SC_SP(sc) ((sc)->regs->gpr[1])
49#define SEGV_IS_FIXABLE(sc) (1)
50
51#endif
52
53/*
54 * Overrides for Emacs so that we follow Linus's tabbing style.
55 * Emacs will notice this stuff at the end of the file and automatically
56 * adjust the settings for this buffer only. This must remain at the end
57 * of the file.
58 * ---------------------------------------------------------------------------
59 * Local variables:
60 * c-file-style: "linux"
61 * End:
62 */
diff --git a/arch/um/include/shared/sysdep-ppc/skas_ptrace.h b/arch/um/include/shared/sysdep-ppc/skas_ptrace.h
new file mode 100644
index 00000000000..d9fbbac10de
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ppc/skas_ptrace.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_PPC_SKAS_PTRACE_H
7#define __SYSDEP_PPC_SKAS_PTRACE_H
8
9struct ptrace_faultinfo {
10 int is_write;
11 unsigned long addr;
12};
13
14struct ptrace_ldt {
15 int func;
16 void *ptr;
17 unsigned long bytecount;
18};
19
20#define PTRACE_LDT 54
21
22#endif
diff --git a/arch/um/include/shared/sysdep-ppc/syscalls.h b/arch/um/include/shared/sysdep-ppc/syscalls.h
new file mode 100644
index 00000000000..679df351e19
--- /dev/null
+++ b/arch/um/include/shared/sysdep-ppc/syscalls.h
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6typedef long syscall_handler_t(unsigned long arg1, unsigned long arg2,
7 unsigned long arg3, unsigned long arg4,
8 unsigned long arg5, unsigned long arg6);
9
10#define EXECUTE_SYSCALL(syscall, regs) \
11 (*sys_call_table[syscall])(UM_SYSCALL_ARG1(&regs), \
12 UM_SYSCALL_ARG2(&regs), \
13 UM_SYSCALL_ARG3(&regs), \
14 UM_SYSCALL_ARG4(&regs), \
15 UM_SYSCALL_ARG5(&regs), \
16 UM_SYSCALL_ARG6(&regs))
17
18extern syscall_handler_t sys_mincore;
19extern syscall_handler_t sys_madvise;
20
21/* old_mmap needs the correct prototype since syscall_kern.c includes
22 * this file.
23 */
24int old_mmap(unsigned long addr, unsigned long len,
25 unsigned long prot, unsigned long flags,
26 unsigned long fd, unsigned long offset);
27
28#define ARCH_SYSCALLS \
29 [ __NR_modify_ldt ] = sys_ni_syscall, \
30 [ __NR_pciconfig_read ] = sys_ni_syscall, \
31 [ __NR_pciconfig_write ] = sys_ni_syscall, \
32 [ __NR_pciconfig_iobase ] = sys_ni_syscall, \
33 [ __NR_pivot_root ] = sys_ni_syscall, \
34 [ __NR_multiplexer ] = sys_ni_syscall, \
35 [ __NR_mmap ] = old_mmap, \
36 [ __NR_madvise ] = sys_madvise, \
37 [ __NR_mincore ] = sys_mincore, \
38 [ __NR_iopl ] = (syscall_handler_t *) sys_ni_syscall, \
39 [ __NR_utimes ] = (syscall_handler_t *) sys_utimes, \
40 [ __NR_fadvise64 ] = (syscall_handler_t *) sys_fadvise64,
41
42#define LAST_ARCH_SYSCALL __NR_fadvise64
43
44/*
45 * Overrides for Emacs so that we follow Linus's tabbing style.
46 * Emacs will notice this stuff at the end of the file and automatically
47 * adjust the settings for this buffer only. This must remain at the end
48 * of the file.
49 * ---------------------------------------------------------------------------
50 * Local variables:
51 * c-file-style: "linux"
52 * End:
53 */
diff --git a/arch/um/include/shared/sysdep-x86_64/archsetjmp.h b/arch/um/include/shared/sysdep-x86_64/archsetjmp.h
new file mode 100644
index 00000000000..2af8f12ca16
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/archsetjmp.h
@@ -0,0 +1,24 @@
1/*
2 * arch/um/include/sysdep-x86_64/archsetjmp.h
3 */
4
5#ifndef _KLIBC_ARCHSETJMP_H
6#define _KLIBC_ARCHSETJMP_H
7
8struct __jmp_buf {
9 unsigned long __rbx;
10 unsigned long __rsp;
11 unsigned long __rbp;
12 unsigned long __r12;
13 unsigned long __r13;
14 unsigned long __r14;
15 unsigned long __r15;
16 unsigned long __rip;
17};
18
19typedef struct __jmp_buf jmp_buf[1];
20
21#define JB_IP __rip
22#define JB_SP __rsp
23
24#endif /* _SETJMP_H */
diff --git a/arch/um/include/shared/sysdep-x86_64/barrier.h b/arch/um/include/shared/sysdep-x86_64/barrier.h
new file mode 100644
index 00000000000..7b610befdc8
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/barrier.h
@@ -0,0 +1,7 @@
1#ifndef __SYSDEP_X86_64_BARRIER_H
2#define __SYSDEP_X86_64_BARRIER_H
3
4/* Copied from include/asm-x86_64 for use by userspace. */
5#define mb() asm volatile("mfence":::"memory")
6
7#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/checksum.h b/arch/um/include/shared/sysdep-x86_64/checksum.h
new file mode 100644
index 00000000000..a5be9031ea8
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/checksum.h
@@ -0,0 +1,144 @@
1/*
2 * Licensed under the GPL
3 */
4
5#ifndef __UM_SYSDEP_CHECKSUM_H
6#define __UM_SYSDEP_CHECKSUM_H
7
8#include "linux/string.h"
9#include "linux/in6.h"
10#include "asm/uaccess.h"
11
12extern __wsum csum_partial(const void *buff, int len, __wsum sum);
13
14/*
15 * Note: when you get a NULL pointer exception here this means someone
16 * passed in an incorrect kernel address to one of these functions.
17 *
18 * If you use these functions directly please don't forget the
19 * access_ok().
20 */
21
22static __inline__
23__wsum csum_partial_copy_nocheck(const void *src, void *dst,
24 int len, __wsum sum)
25{
26 memcpy(dst, src, len);
27 return(csum_partial(dst, len, sum));
28}
29
30static __inline__
31__wsum csum_partial_copy_from_user(const void __user *src,
32 void *dst, int len, __wsum sum,
33 int *err_ptr)
34{
35 if (copy_from_user(dst, src, len)) {
36 *err_ptr = -EFAULT;
37 return (__force __wsum)-1;
38 }
39 return csum_partial(dst, len, sum);
40}
41
42/**
43 * csum_fold - Fold and invert a 32bit checksum.
44 * sum: 32bit unfolded sum
45 *
46 * Fold a 32bit running checksum to 16bit and invert it. This is usually
47 * the last step before putting a checksum into a packet.
48 * Make sure not to mix with 64bit checksums.
49 */
50static inline __sum16 csum_fold(__wsum sum)
51{
52 __asm__(
53 " addl %1,%0\n"
54 " adcl $0xffff,%0"
55 : "=r" (sum)
56 : "r" ((__force u32)sum << 16),
57 "0" ((__force u32)sum & 0xffff0000)
58 );
59 return (__force __sum16)(~(__force u32)sum >> 16);
60}
61
62/**
63 * csum_tcpup_nofold - Compute an IPv4 pseudo header checksum.
64 * @saddr: source address
65 * @daddr: destination address
66 * @len: length of packet
67 * @proto: ip protocol of packet
68 * @sum: initial sum to be added in (32bit unfolded)
69 *
70 * Returns the pseudo header checksum the input data. Result is
71 * 32bit unfolded.
72 */
73static inline __wsum
74csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
75 unsigned short proto, __wsum sum)
76{
77 asm(" addl %1, %0\n"
78 " adcl %2, %0\n"
79 " adcl %3, %0\n"
80 " adcl $0, %0\n"
81 : "=r" (sum)
82 : "g" (daddr), "g" (saddr), "g" ((len + proto) << 8), "0" (sum));
83 return sum;
84}
85
86/*
87 * computes the checksum of the TCP/UDP pseudo-header
88 * returns a 16-bit checksum, already complemented
89 */
90static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
91 unsigned short len,
92 unsigned short proto,
93 __wsum sum)
94{
95 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
96}
97
98/**
99 * ip_fast_csum - Compute the IPv4 header checksum efficiently.
100 * iph: ipv4 header
101 * ihl: length of header / 4
102 */
103static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
104{
105 unsigned int sum;
106
107 asm( " movl (%1), %0\n"
108 " subl $4, %2\n"
109 " jbe 2f\n"
110 " addl 4(%1), %0\n"
111 " adcl 8(%1), %0\n"
112 " adcl 12(%1), %0\n"
113 "1: adcl 16(%1), %0\n"
114 " lea 4(%1), %1\n"
115 " decl %2\n"
116 " jne 1b\n"
117 " adcl $0, %0\n"
118 " movl %0, %2\n"
119 " shrl $16, %0\n"
120 " addw %w2, %w0\n"
121 " adcl $0, %0\n"
122 " notl %0\n"
123 "2:"
124 /* Since the input registers which are loaded with iph and ipl
125 are modified, we must also specify them as outputs, or gcc
126 will assume they contain their original values. */
127 : "=r" (sum), "=r" (iph), "=r" (ihl)
128 : "1" (iph), "2" (ihl)
129 : "memory");
130 return (__force __sum16)sum;
131}
132
133static inline unsigned add32_with_carry(unsigned a, unsigned b)
134{
135 asm("addl %2,%0\n\t"
136 "adcl $0,%0"
137 : "=r" (a)
138 : "0" (a), "r" (b));
139 return a;
140}
141
142extern __sum16 ip_compute_csum(const void *buff, int len);
143
144#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/faultinfo.h b/arch/um/include/shared/sysdep-x86_64/faultinfo.h
new file mode 100644
index 00000000000..cb917b0d566
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/faultinfo.h
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2004 Fujitsu Siemens Computers GmbH
3 * Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
4 * Licensed under the GPL
5 */
6
7#ifndef __FAULTINFO_X86_64_H
8#define __FAULTINFO_X86_64_H
9
10/* this structure contains the full arch-specific faultinfo
11 * from the traps.
12 * On i386, ptrace_faultinfo unfortunately doesn't provide
13 * all the info, since trap_no is missing.
14 * All common elements are defined at the same position in
15 * both structures, thus making it easy to copy the
16 * contents without knowledge about the structure elements.
17 */
18struct faultinfo {
19 int error_code; /* in ptrace_faultinfo misleadingly called is_write */
20 unsigned long cr2; /* in ptrace_faultinfo called addr */
21 int trap_no; /* missing in ptrace_faultinfo */
22};
23
24#define FAULT_WRITE(fi) ((fi).error_code & 2)
25#define FAULT_ADDRESS(fi) ((fi).cr2)
26
27#define PTRACE_FULL_FAULTINFO 1
28
29#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/kernel-offsets.h b/arch/um/include/shared/sysdep-x86_64/kernel-offsets.h
new file mode 100644
index 00000000000..a307237b796
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/kernel-offsets.h
@@ -0,0 +1,23 @@
1#include <linux/stddef.h>
2#include <linux/sched.h>
3#include <linux/time.h>
4#include <linux/elf.h>
5#include <linux/crypto.h>
6#include <asm/page.h>
7#include <asm/mman.h>
8
9#define DEFINE(sym, val) \
10 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
11
12#define DEFINE_STR1(x) #x
13#define DEFINE_STR(sym, val) asm volatile("\n->" #sym " " DEFINE_STR1(val) " " #val: : )
14
15#define BLANK() asm volatile("\n->" : : )
16
17#define OFFSET(sym, str, mem) \
18 DEFINE(sym, offsetof(struct str, mem));
19
20void foo(void)
21{
22#include <common-offsets.h>
23}
diff --git a/arch/um/include/shared/sysdep-x86_64/ptrace.h b/arch/um/include/shared/sysdep-x86_64/ptrace.h
new file mode 100644
index 00000000000..9ea44d111f3
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/ptrace.h
@@ -0,0 +1,240 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 *
5 * Licensed under the GPL
6 */
7
8#ifndef __SYSDEP_X86_64_PTRACE_H
9#define __SYSDEP_X86_64_PTRACE_H
10
11#include "uml-config.h"
12#include "user_constants.h"
13#include "sysdep/faultinfo.h"
14
15#define MAX_REG_OFFSET (UM_FRAME_SIZE)
16#define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long))
17
18#include "skas_ptregs.h"
19
20#define REGS_IP(r) ((r)[HOST_IP])
21#define REGS_SP(r) ((r)[HOST_SP])
22
23#define REGS_RBX(r) ((r)[HOST_RBX])
24#define REGS_RCX(r) ((r)[HOST_RCX])
25#define REGS_RDX(r) ((r)[HOST_RDX])
26#define REGS_RSI(r) ((r)[HOST_RSI])
27#define REGS_RDI(r) ((r)[HOST_RDI])
28#define REGS_RBP(r) ((r)[HOST_RBP])
29#define REGS_RAX(r) ((r)[HOST_RAX])
30#define REGS_R8(r) ((r)[HOST_R8])
31#define REGS_R9(r) ((r)[HOST_R9])
32#define REGS_R10(r) ((r)[HOST_R10])
33#define REGS_R11(r) ((r)[HOST_R11])
34#define REGS_R12(r) ((r)[HOST_R12])
35#define REGS_R13(r) ((r)[HOST_R13])
36#define REGS_R14(r) ((r)[HOST_R14])
37#define REGS_R15(r) ((r)[HOST_R15])
38#define REGS_CS(r) ((r)[HOST_CS])
39#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
40#define REGS_SS(r) ((r)[HOST_SS])
41
42#define HOST_FS_BASE 21
43#define HOST_GS_BASE 22
44#define HOST_DS 23
45#define HOST_ES 24
46#define HOST_FS 25
47#define HOST_GS 26
48
49/* Also defined in asm/ptrace-x86_64.h, but not in libc headers. So, these
50 * are already defined for kernel code, but not for userspace code.
51 */
52#ifndef FS_BASE
53/* These aren't defined in ptrace.h, but exist in struct user_regs_struct,
54 * which is what x86_64 ptrace actually uses.
55 */
56#define FS_BASE (HOST_FS_BASE * sizeof(long))
57#define GS_BASE (HOST_GS_BASE * sizeof(long))
58#define DS (HOST_DS * sizeof(long))
59#define ES (HOST_ES * sizeof(long))
60#define FS (HOST_FS * sizeof(long))
61#define GS (HOST_GS * sizeof(long))
62#endif
63
64#define REGS_FS_BASE(r) ((r)[HOST_FS_BASE])
65#define REGS_GS_BASE(r) ((r)[HOST_GS_BASE])
66#define REGS_DS(r) ((r)[HOST_DS])
67#define REGS_ES(r) ((r)[HOST_ES])
68#define REGS_FS(r) ((r)[HOST_FS])
69#define REGS_GS(r) ((r)[HOST_GS])
70
71#define REGS_ORIG_RAX(r) ((r)[HOST_ORIG_RAX])
72
73#define REGS_SET_SYSCALL_RETURN(r, res) REGS_RAX(r) = (res)
74
75#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
76
77#define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)
78
79#define REGS_FAULT_ADDR(r) ((r)->fault_addr)
80
81#define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
82
83#define REGS_TRAP(r) ((r)->trap_type)
84
85#define REGS_ERR(r) ((r)->fault_type)
86
87struct uml_pt_regs {
88 unsigned long gp[MAX_REG_NR];
89 struct faultinfo faultinfo;
90 long syscall;
91 int is_user;
92};
93
94#define EMPTY_UML_PT_REGS { }
95
96#define UPT_RBX(r) REGS_RBX((r)->gp)
97#define UPT_RCX(r) REGS_RCX((r)->gp)
98#define UPT_RDX(r) REGS_RDX((r)->gp)
99#define UPT_RSI(r) REGS_RSI((r)->gp)
100#define UPT_RDI(r) REGS_RDI((r)->gp)
101#define UPT_RBP(r) REGS_RBP((r)->gp)
102#define UPT_RAX(r) REGS_RAX((r)->gp)
103#define UPT_R8(r) REGS_R8((r)->gp)
104#define UPT_R9(r) REGS_R9((r)->gp)
105#define UPT_R10(r) REGS_R10((r)->gp)
106#define UPT_R11(r) REGS_R11((r)->gp)
107#define UPT_R12(r) REGS_R12((r)->gp)
108#define UPT_R13(r) REGS_R13((r)->gp)
109#define UPT_R14(r) REGS_R14((r)->gp)
110#define UPT_R15(r) REGS_R15((r)->gp)
111#define UPT_CS(r) REGS_CS((r)->gp)
112#define UPT_FS_BASE(r) REGS_FS_BASE((r)->gp)
113#define UPT_FS(r) REGS_FS((r)->gp)
114#define UPT_GS_BASE(r) REGS_GS_BASE((r)->gp)
115#define UPT_GS(r) REGS_GS((r)->gp)
116#define UPT_DS(r) REGS_DS((r)->gp)
117#define UPT_ES(r) REGS_ES((r)->gp)
118#define UPT_CS(r) REGS_CS((r)->gp)
119#define UPT_SS(r) REGS_SS((r)->gp)
120#define UPT_ORIG_RAX(r) REGS_ORIG_RAX((r)->gp)
121
122#define UPT_IP(r) REGS_IP((r)->gp)
123#define UPT_SP(r) REGS_SP((r)->gp)
124
125#define UPT_EFLAGS(r) REGS_EFLAGS((r)->gp)
126#define UPT_SYSCALL_NR(r) ((r)->syscall)
127#define UPT_SYSCALL_RET(r) UPT_RAX(r)
128
129extern int user_context(unsigned long sp);
130
131#define UPT_IS_USER(r) ((r)->is_user)
132
133#define UPT_SYSCALL_ARG1(r) UPT_RDI(r)
134#define UPT_SYSCALL_ARG2(r) UPT_RSI(r)
135#define UPT_SYSCALL_ARG3(r) UPT_RDX(r)
136#define UPT_SYSCALL_ARG4(r) UPT_R10(r)
137#define UPT_SYSCALL_ARG5(r) UPT_R8(r)
138#define UPT_SYSCALL_ARG6(r) UPT_R9(r)
139
140struct syscall_args {
141 unsigned long args[6];
142};
143
144#define SYSCALL_ARGS(r) ((struct syscall_args) \
145 { .args = { UPT_SYSCALL_ARG1(r), \
146 UPT_SYSCALL_ARG2(r), \
147 UPT_SYSCALL_ARG3(r), \
148 UPT_SYSCALL_ARG4(r), \
149 UPT_SYSCALL_ARG5(r), \
150 UPT_SYSCALL_ARG6(r) } } )
151
152#define UPT_REG(regs, reg) \
153 ({ unsigned long val; \
154 switch(reg){ \
155 case R8: val = UPT_R8(regs); break; \
156 case R9: val = UPT_R9(regs); break; \
157 case R10: val = UPT_R10(regs); break; \
158 case R11: val = UPT_R11(regs); break; \
159 case R12: val = UPT_R12(regs); break; \
160 case R13: val = UPT_R13(regs); break; \
161 case R14: val = UPT_R14(regs); break; \
162 case R15: val = UPT_R15(regs); break; \
163 case RIP: val = UPT_IP(regs); break; \
164 case RSP: val = UPT_SP(regs); break; \
165 case RAX: val = UPT_RAX(regs); break; \
166 case RBX: val = UPT_RBX(regs); break; \
167 case RCX: val = UPT_RCX(regs); break; \
168 case RDX: val = UPT_RDX(regs); break; \
169 case RSI: val = UPT_RSI(regs); break; \
170 case RDI: val = UPT_RDI(regs); break; \
171 case RBP: val = UPT_RBP(regs); break; \
172 case ORIG_RAX: val = UPT_ORIG_RAX(regs); break; \
173 case CS: val = UPT_CS(regs); break; \
174 case SS: val = UPT_SS(regs); break; \
175 case FS_BASE: val = UPT_FS_BASE(regs); break; \
176 case GS_BASE: val = UPT_GS_BASE(regs); break; \
177 case DS: val = UPT_DS(regs); break; \
178 case ES: val = UPT_ES(regs); break; \
179 case FS : val = UPT_FS (regs); break; \
180 case GS: val = UPT_GS(regs); break; \
181 case EFLAGS: val = UPT_EFLAGS(regs); break; \
182 default : \
183 panic("Bad register in UPT_REG : %d\n", reg); \
184 val = -1; \
185 } \
186 val; \
187 })
188
189
190#define UPT_SET(regs, reg, val) \
191 ({ unsigned long __upt_val = val; \
192 switch(reg){ \
193 case R8: UPT_R8(regs) = __upt_val; break; \
194 case R9: UPT_R9(regs) = __upt_val; break; \
195 case R10: UPT_R10(regs) = __upt_val; break; \
196 case R11: UPT_R11(regs) = __upt_val; break; \
197 case R12: UPT_R12(regs) = __upt_val; break; \
198 case R13: UPT_R13(regs) = __upt_val; break; \
199 case R14: UPT_R14(regs) = __upt_val; break; \
200 case R15: UPT_R15(regs) = __upt_val; break; \
201 case RIP: UPT_IP(regs) = __upt_val; break; \
202 case RSP: UPT_SP(regs) = __upt_val; break; \
203 case RAX: UPT_RAX(regs) = __upt_val; break; \
204 case RBX: UPT_RBX(regs) = __upt_val; break; \
205 case RCX: UPT_RCX(regs) = __upt_val; break; \
206 case RDX: UPT_RDX(regs) = __upt_val; break; \
207 case RSI: UPT_RSI(regs) = __upt_val; break; \
208 case RDI: UPT_RDI(regs) = __upt_val; break; \
209 case RBP: UPT_RBP(regs) = __upt_val; break; \
210 case ORIG_RAX: UPT_ORIG_RAX(regs) = __upt_val; break; \
211 case CS: UPT_CS(regs) = __upt_val; break; \
212 case SS: UPT_SS(regs) = __upt_val; break; \
213 case FS_BASE: UPT_FS_BASE(regs) = __upt_val; break; \
214 case GS_BASE: UPT_GS_BASE(regs) = __upt_val; break; \
215 case DS: UPT_DS(regs) = __upt_val; break; \
216 case ES: UPT_ES(regs) = __upt_val; break; \
217 case FS: UPT_FS(regs) = __upt_val; break; \
218 case GS: UPT_GS(regs) = __upt_val; break; \
219 case EFLAGS: UPT_EFLAGS(regs) = __upt_val; break; \
220 default : \
221 panic("Bad register in UPT_SET : %d\n", reg); \
222 break; \
223 } \
224 __upt_val; \
225 })
226
227#define UPT_SET_SYSCALL_RETURN(r, res) \
228 REGS_SET_SYSCALL_RETURN((r)->regs, (res))
229
230#define UPT_RESTART_SYSCALL(r) REGS_RESTART_SYSCALL((r)->gp)
231
232#define UPT_SEGV_IS_FIXABLE(r) REGS_SEGV_IS_FIXABLE(&r->skas)
233
234#define UPT_FAULTINFO(r) (&(r)->faultinfo)
235
236static inline void arch_init_registers(int pid)
237{
238}
239
240#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/ptrace_user.h b/arch/um/include/shared/sysdep-x86_64/ptrace_user.h
new file mode 100644
index 00000000000..4dbccdb58f4
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/ptrace_user.h
@@ -0,0 +1,77 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#ifndef __SYSDEP_X86_64_PTRACE_USER_H__
8#define __SYSDEP_X86_64_PTRACE_USER_H__
9
10#define __FRAME_OFFSETS
11#include <sys/ptrace.h>
12#include <linux/ptrace.h>
13#include <asm/ptrace.h>
14#undef __FRAME_OFFSETS
15#include "user_constants.h"
16
17#define PT_INDEX(off) ((off) / sizeof(unsigned long))
18
19#define PT_SYSCALL_NR(regs) ((regs)[PT_INDEX(ORIG_RAX)])
20#define PT_SYSCALL_NR_OFFSET (ORIG_RAX)
21
22#define PT_SYSCALL_ARG1(regs) (((unsigned long *) (regs))[PT_INDEX(RDI)])
23#define PT_SYSCALL_ARG1_OFFSET (RDI)
24
25#define PT_SYSCALL_ARG2(regs) (((unsigned long *) (regs))[PT_INDEX(RSI)])
26#define PT_SYSCALL_ARG2_OFFSET (RSI)
27
28#define PT_SYSCALL_ARG3(regs) (((unsigned long *) (regs))[PT_INDEX(RDX)])
29#define PT_SYSCALL_ARG3_OFFSET (RDX)
30
31#define PT_SYSCALL_ARG4(regs) (((unsigned long *) (regs))[PT_INDEX(RCX)])
32#define PT_SYSCALL_ARG4_OFFSET (RCX)
33
34#define PT_SYSCALL_ARG5(regs) (((unsigned long *) (regs))[PT_INDEX(R8)])
35#define PT_SYSCALL_ARG5_OFFSET (R8)
36
37#define PT_SYSCALL_ARG6(regs) (((unsigned long *) (regs))[PT_INDEX(R9)])
38#define PT_SYSCALL_ARG6_OFFSET (R9)
39
40#define PT_SYSCALL_RET_OFFSET (RAX)
41
42#define PT_IP_OFFSET (RIP)
43#define PT_IP(regs) ((regs)[PT_INDEX(RIP)])
44
45#define PT_SP_OFFSET (RSP)
46#define PT_SP(regs) ((regs)[PT_INDEX(RSP)])
47
48#define PT_ORIG_RAX_OFFSET (ORIG_RAX)
49#define PT_ORIG_RAX(regs) ((regs)[PT_INDEX(ORIG_RAX)])
50
51/*
52 * x86_64 FC3 doesn't define this in /usr/include/linux/ptrace.h even though
53 * it's defined in the kernel's include/linux/ptrace.h. Additionally, use the
54 * 2.4 name and value for 2.4 host compatibility.
55 */
56#ifndef PTRACE_OLDSETOPTIONS
57#define PTRACE_OLDSETOPTIONS 21
58#endif
59
60/*
61 * These are before the system call, so the system call number is RAX
62 * rather than ORIG_RAX, and arg4 is R10 rather than RCX
63 */
64#define REGS_SYSCALL_NR PT_INDEX(RAX)
65#define REGS_SYSCALL_ARG1 PT_INDEX(RDI)
66#define REGS_SYSCALL_ARG2 PT_INDEX(RSI)
67#define REGS_SYSCALL_ARG3 PT_INDEX(RDX)
68#define REGS_SYSCALL_ARG4 PT_INDEX(R10)
69#define REGS_SYSCALL_ARG5 PT_INDEX(R8)
70#define REGS_SYSCALL_ARG6 PT_INDEX(R9)
71
72#define REGS_IP_INDEX PT_INDEX(RIP)
73#define REGS_SP_INDEX PT_INDEX(RSP)
74
75#define FP_SIZE (HOST_FP_SIZE)
76
77#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/sc.h b/arch/um/include/shared/sysdep-x86_64/sc.h
new file mode 100644
index 00000000000..8aee45b0743
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/sc.h
@@ -0,0 +1,45 @@
1#ifndef __SYSDEP_X86_64_SC_H
2#define __SYSDEP_X86_64_SC_H
3
4/* Copyright (C) 2003 - 2004 PathScale, Inc
5 * Released under the GPL
6 */
7
8#include <user_constants.h>
9
10#define SC_OFFSET(sc, field) \
11 *((unsigned long *) &(((char *) (sc))[HOST_##field]))
12
13#define SC_RBX(sc) SC_OFFSET(sc, SC_RBX)
14#define SC_RCX(sc) SC_OFFSET(sc, SC_RCX)
15#define SC_RDX(sc) SC_OFFSET(sc, SC_RDX)
16#define SC_RSI(sc) SC_OFFSET(sc, SC_RSI)
17#define SC_RDI(sc) SC_OFFSET(sc, SC_RDI)
18#define SC_RBP(sc) SC_OFFSET(sc, SC_RBP)
19#define SC_RAX(sc) SC_OFFSET(sc, SC_RAX)
20#define SC_R8(sc) SC_OFFSET(sc, SC_R8)
21#define SC_R9(sc) SC_OFFSET(sc, SC_R9)
22#define SC_R10(sc) SC_OFFSET(sc, SC_R10)
23#define SC_R11(sc) SC_OFFSET(sc, SC_R11)
24#define SC_R12(sc) SC_OFFSET(sc, SC_R12)
25#define SC_R13(sc) SC_OFFSET(sc, SC_R13)
26#define SC_R14(sc) SC_OFFSET(sc, SC_R14)
27#define SC_R15(sc) SC_OFFSET(sc, SC_R15)
28#define SC_IP(sc) SC_OFFSET(sc, SC_IP)
29#define SC_SP(sc) SC_OFFSET(sc, SC_SP)
30#define SC_CR2(sc) SC_OFFSET(sc, SC_CR2)
31#define SC_ERR(sc) SC_OFFSET(sc, SC_ERR)
32#define SC_TRAPNO(sc) SC_OFFSET(sc, SC_TRAPNO)
33#define SC_CS(sc) SC_OFFSET(sc, SC_CS)
34#define SC_FS(sc) SC_OFFSET(sc, SC_FS)
35#define SC_GS(sc) SC_OFFSET(sc, SC_GS)
36#define SC_EFLAGS(sc) SC_OFFSET(sc, SC_EFLAGS)
37#define SC_SIGMASK(sc) SC_OFFSET(sc, SC_SIGMASK)
38#define SC_SS(sc) SC_OFFSET(sc, SC_SS)
39#if 0
40#define SC_ORIG_RAX(sc) SC_OFFSET(sc, SC_ORIG_RAX)
41#define SC_DS(sc) SC_OFFSET(sc, SC_DS)
42#define SC_ES(sc) SC_OFFSET(sc, SC_ES)
43#endif
44
45#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/sigcontext.h b/arch/um/include/shared/sysdep-x86_64/sigcontext.h
new file mode 100644
index 00000000000..0155133b145
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/sigcontext.h
@@ -0,0 +1,27 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#ifndef __SYSDEP_X86_64_SIGCONTEXT_H
8#define __SYSDEP_X86_64_SIGCONTEXT_H
9
10#include <sysdep/sc.h>
11
12#define IP_RESTART_SYSCALL(ip) ((ip) -= 2)
13
14#define GET_FAULTINFO_FROM_SC(fi, sc) \
15 { \
16 (fi).cr2 = SC_CR2(sc); \
17 (fi).error_code = SC_ERR(sc); \
18 (fi).trap_no = SC_TRAPNO(sc); \
19 }
20
21/* This is Page Fault */
22#define SEGV_IS_FIXABLE(fi) ((fi)->trap_no == 14)
23
24/* No broken SKAS API, which doesn't pass trap_no, here. */
25#define SEGV_MAYBE_FIXABLE(fi) 0
26
27#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/skas_ptrace.h b/arch/um/include/shared/sysdep-x86_64/skas_ptrace.h
new file mode 100644
index 00000000000..95db4be786e
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/skas_ptrace.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_X86_64_SKAS_PTRACE_H
7#define __SYSDEP_X86_64_SKAS_PTRACE_H
8
9struct ptrace_faultinfo {
10 int is_write;
11 unsigned long addr;
12};
13
14struct ptrace_ldt {
15 int func;
16 void *ptr;
17 unsigned long bytecount;
18};
19
20#define PTRACE_LDT 54
21
22#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/stub.h b/arch/um/include/shared/sysdep-x86_64/stub.h
new file mode 100644
index 00000000000..655f9c2de3a
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/stub.h
@@ -0,0 +1,108 @@
1/*
2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_STUB_H
7#define __SYSDEP_STUB_H
8
9#include <sys/mman.h>
10#include <asm/unistd.h>
11#include <sysdep/ptrace_user.h>
12#include "as-layout.h"
13#include "stub-data.h"
14#include "kern_constants.h"
15#include "uml-config.h"
16
17extern void stub_segv_handler(int sig);
18extern void stub_clone_handler(void);
19
20#define STUB_SYSCALL_RET PT_INDEX(RAX)
21#define STUB_MMAP_NR __NR_mmap
22#define MMAP_OFFSET(o) (o)
23
24#define __syscall_clobber "r11","rcx","memory"
25#define __syscall "syscall"
26
27static inline long stub_syscall0(long syscall)
28{
29 long ret;
30
31 __asm__ volatile (__syscall
32 : "=a" (ret)
33 : "0" (syscall) : __syscall_clobber );
34
35 return ret;
36}
37
38static inline long stub_syscall2(long syscall, long arg1, long arg2)
39{
40 long ret;
41
42 __asm__ volatile (__syscall
43 : "=a" (ret)
44 : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
45
46 return ret;
47}
48
49static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
50{
51 long ret;
52
53 __asm__ volatile (__syscall
54 : "=a" (ret)
55 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
56 : __syscall_clobber );
57
58 return ret;
59}
60
61static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
62 long arg4)
63{
64 long ret;
65
66 __asm__ volatile ("movq %5,%%r10 ; " __syscall
67 : "=a" (ret)
68 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
69 "g" (arg4)
70 : __syscall_clobber, "r10" );
71
72 return ret;
73}
74
75static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
76 long arg4, long arg5)
77{
78 long ret;
79
80 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
81 : "=a" (ret)
82 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
83 "g" (arg4), "g" (arg5)
84 : __syscall_clobber, "r10", "r8" );
85
86 return ret;
87}
88
89static inline void trap_myself(void)
90{
91 __asm("int3");
92}
93
94static inline void remap_stack(long fd, unsigned long offset)
95{
96 __asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; "
97 "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; "
98 "movq %%rax, (%%rbx)":
99 : "a" (STUB_MMAP_NR), "D" (STUB_DATA),
100 "S" (UM_KERN_PAGE_SIZE),
101 "d" (PROT_READ | PROT_WRITE),
102 "g" (MAP_FIXED | MAP_SHARED), "g" (fd),
103 "g" (offset),
104 "i" (&((struct stub_data *) STUB_DATA)->err)
105 : __syscall_clobber, "r10", "r8", "r9" );
106}
107
108#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/syscalls.h b/arch/um/include/shared/sysdep-x86_64/syscalls.h
new file mode 100644
index 00000000000..7cfb0b08565
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/syscalls.h
@@ -0,0 +1,33 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#ifndef __SYSDEP_X86_64_SYSCALLS_H__
8#define __SYSDEP_X86_64_SYSCALLS_H__
9
10#include <linux/msg.h>
11#include <linux/shm.h>
12#include <kern_constants.h>
13
14typedef long syscall_handler_t(void);
15
16extern syscall_handler_t *sys_call_table[];
17
18#define EXECUTE_SYSCALL(syscall, regs) \
19 (((long (*)(long, long, long, long, long, long)) \
20 (*sys_call_table[syscall]))(UPT_SYSCALL_ARG1(&regs->regs), \
21 UPT_SYSCALL_ARG2(&regs->regs), \
22 UPT_SYSCALL_ARG3(&regs->regs), \
23 UPT_SYSCALL_ARG4(&regs->regs), \
24 UPT_SYSCALL_ARG5(&regs->regs), \
25 UPT_SYSCALL_ARG6(&regs->regs)))
26
27extern long old_mmap(unsigned long addr, unsigned long len,
28 unsigned long prot, unsigned long flags,
29 unsigned long fd, unsigned long pgoff);
30extern syscall_handler_t sys_modify_ldt;
31extern syscall_handler_t sys_arch_prctl;
32
33#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/tls.h b/arch/um/include/shared/sysdep-x86_64/tls.h
new file mode 100644
index 00000000000..35f19f25bd3
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/tls.h
@@ -0,0 +1,29 @@
1#ifndef _SYSDEP_TLS_H
2#define _SYSDEP_TLS_H
3
4# ifndef __KERNEL__
5
6/* Change name to avoid conflicts with the original one from <asm/ldt.h>, which
7 * may be named user_desc (but in 2.4 and in header matching its API was named
8 * modify_ldt_ldt_s). */
9
10typedef struct um_dup_user_desc {
11 unsigned int entry_number;
12 unsigned int base_addr;
13 unsigned int limit;
14 unsigned int seg_32bit:1;
15 unsigned int contents:2;
16 unsigned int read_exec_only:1;
17 unsigned int limit_in_pages:1;
18 unsigned int seg_not_present:1;
19 unsigned int useable:1;
20 unsigned int lm:1;
21} user_desc_t;
22
23# else /* __KERNEL__ */
24
25# include <asm/ldt.h>
26typedef struct user_desc user_desc_t;
27
28# endif /* __KERNEL__ */
29#endif /* _SYSDEP_TLS_H */
diff --git a/arch/um/include/shared/sysrq.h b/arch/um/include/shared/sysrq.h
new file mode 100644
index 00000000000..c8d332b56b9
--- /dev/null
+++ b/arch/um/include/shared/sysrq.h
@@ -0,0 +1,7 @@
1#ifndef __UM_SYSRQ_H
2#define __UM_SYSRQ_H
3
4struct task_struct;
5extern void show_trace(struct task_struct* task, unsigned long *stack);
6
7#endif
diff --git a/arch/um/include/shared/task.h b/arch/um/include/shared/task.h
new file mode 100644
index 00000000000..3fe726b3cf4
--- /dev/null
+++ b/arch/um/include/shared/task.h
@@ -0,0 +1,9 @@
1#ifndef __TASK_H
2#define __TASK_H
3
4#include <kern_constants.h>
5
6#define TASK_REGS(task) ((struct uml_pt_regs *) &(((char *) (task))[HOST_TASK_REGS]))
7#define TASK_PID(task) *((int *) &(((char *) (task))[HOST_TASK_PID]))
8
9#endif
diff --git a/arch/um/include/shared/tlb.h b/arch/um/include/shared/tlb.h
new file mode 100644
index 00000000000..ecd2265b301
--- /dev/null
+++ b/arch/um/include/shared/tlb.h
@@ -0,0 +1,15 @@
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __TLB_H__
7#define __TLB_H__
8
9#include "um_mmu.h"
10
11extern void force_flush_all(void);
12extern int flush_tlb_kernel_range_common(unsigned long start,
13 unsigned long end);
14
15#endif
diff --git a/arch/um/include/shared/ubd_user.h b/arch/um/include/shared/ubd_user.h
new file mode 100644
index 00000000000..bb66517f073
--- /dev/null
+++ b/arch/um/include/shared/ubd_user.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Copyright (C) 2001 RidgeRun, Inc (glonnon@ridgerun.com)
4 * Licensed under the GPL
5 */
6
7#ifndef __UM_UBD_USER_H
8#define __UM_UBD_USER_H
9
10extern void ignore_sigwinch_sig(void);
11extern int start_io_thread(unsigned long sp, int *fds_out);
12extern int io_thread(void *arg);
13extern int kernel_fd;
14
15#endif
16
17/*
18 * Overrides for Emacs so that we follow Linus's tabbing style.
19 * Emacs will notice this stuff at the end of the file and automatically
20 * adjust the settings for this buffer only. This must remain at the end
21 * of the file.
22 * ---------------------------------------------------------------------------
23 * Local variables:
24 * c-file-style: "linux"
25 * End:
26 */
diff --git a/arch/um/include/shared/um_malloc.h b/arch/um/include/shared/um_malloc.h
new file mode 100644
index 00000000000..c554d706d10
--- /dev/null
+++ b/arch/um/include/shared/um_malloc.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) 2005 Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
3 * Licensed under the GPL
4 */
5
6#ifndef __UM_MALLOC_H__
7#define __UM_MALLOC_H__
8
9#include "kern_constants.h"
10
11extern void *uml_kmalloc(int size, int flags);
12extern void kfree(const void *ptr);
13
14extern void *vmalloc(unsigned long size);
15extern void vfree(void *ptr);
16
17#endif /* __UM_MALLOC_H__ */
18
19
diff --git a/arch/um/include/shared/um_mmu.h b/arch/um/include/shared/um_mmu.h
new file mode 100644
index 00000000000..f575ff91f2a
--- /dev/null
+++ b/arch/um/include/shared/um_mmu.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __ARCH_UM_MMU_H
7#define __ARCH_UM_MMU_H
8
9#include "uml-config.h"
10#include "mm_id.h"
11#include "asm/ldt.h"
12
13typedef struct mm_context {
14 struct mm_id id;
15 struct uml_ldt ldt;
16 struct page **stub_pages;
17} mm_context_t;
18
19extern void __switch_mm(struct mm_id * mm_idp);
20
21/* Avoid tangled inclusion with asm/ldt.h */
22extern long init_new_ldt(struct mm_context *to_mm, struct mm_context *from_mm);
23extern void free_ldt(struct mm_context *mm);
24
25#endif
diff --git a/arch/um/include/shared/um_uaccess.h b/arch/um/include/shared/um_uaccess.h
new file mode 100644
index 00000000000..45c04999d67
--- /dev/null
+++ b/arch/um/include/shared/um_uaccess.h
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __ARCH_UM_UACCESS_H
7#define __ARCH_UM_UACCESS_H
8
9#include <asm/elf.h>
10#include <asm/fixmap.h>
11#include "sysdep/archsetjmp.h"
12
13#define __under_task_size(addr, size) \
14 (((unsigned long) (addr) < TASK_SIZE) && \
15 (((unsigned long) (addr) + (size)) < TASK_SIZE))
16
17#define __access_ok_vsyscall(type, addr, size) \
18 ((type == VERIFY_READ) && \
19 ((unsigned long) (addr) >= FIXADDR_USER_START) && \
20 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
21 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
22
23#define __addr_range_nowrap(addr, size) \
24 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
25
26#define access_ok(type, addr, size) \
27 (__addr_range_nowrap(addr, size) && \
28 (__under_task_size(addr, size) || \
29 __access_ok_vsyscall(type, addr, size) || \
30 segment_eq(get_fs(), KERNEL_DS)))
31
32extern int copy_from_user(void *to, const void __user *from, int n);
33extern int copy_to_user(void __user *to, const void *from, int n);
34
35extern int __do_copy_to_user(void *to, const void *from, int n,
36 void **fault_addr, jmp_buf **fault_catcher);
37
38/*
39 * strncpy_from_user: - Copy a NUL terminated string from userspace.
40 * @dst: Destination address, in kernel space. This buffer must be at
41 * least @count bytes long.
42 * @src: Source address, in user space.
43 * @count: Maximum number of bytes to copy, including the trailing NUL.
44 *
45 * Copies a NUL-terminated string from userspace to kernel space.
46 *
47 * On success, returns the length of the string (not including the trailing
48 * NUL).
49 *
50 * If access to userspace fails, returns -EFAULT (some data may have been
51 * copied).
52 *
53 * If @count is smaller than the length of the string, copies @count bytes
54 * and returns @count.
55 */
56
57extern int strncpy_from_user(char *dst, const char __user *src, int count);
58
59/*
60 * __clear_user: - Zero a block of memory in user space, with less checking.
61 * @to: Destination address, in user space.
62 * @n: Number of bytes to zero.
63 *
64 * Zero a block of memory in user space. Caller must check
65 * the specified block with access_ok() before calling this function.
66 *
67 * Returns number of bytes that could not be cleared.
68 * On success, this will be zero.
69 */
70extern int __clear_user(void __user *mem, int len);
71
72/*
73 * clear_user: - Zero a block of memory in user space.
74 * @to: Destination address, in user space.
75 * @n: Number of bytes to zero.
76 *
77 * Zero a block of memory in user space.
78 *
79 * Returns number of bytes that could not be cleared.
80 * On success, this will be zero.
81 */
82extern int clear_user(void __user *mem, int len);
83
84/*
85 * strlen_user: - Get the size of a string in user space.
86 * @str: The string to measure.
87 * @n: The maximum valid length
88 *
89 * Get the size of a NUL-terminated string in user space.
90 *
91 * Returns the size of the string INCLUDING the terminating NUL.
92 * On exception, returns 0.
93 * If the string is too long, returns a value greater than @n.
94 */
95extern int strnlen_user(const void __user *str, int len);
96
97#endif
diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h
new file mode 100644
index 00000000000..1723fac6f40
--- /dev/null
+++ b/arch/um/include/shared/user.h
@@ -0,0 +1,45 @@
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __USER_H__
7#define __USER_H__
8
9#include "uml-config.h"
10
11/*
12 * The usual definition - copied here because the kernel provides its own,
13 * fancier, type-safe, definition. Using that one would require
14 * copying too much infrastructure for my taste, so userspace files
15 * get less checking than kernel files.
16 */
17#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
18
19/* This is to get size_t */
20#ifdef __KERNEL__
21#include <linux/types.h>
22#else
23#include <stddef.h>
24#endif
25
26extern void panic(const char *fmt, ...)
27 __attribute__ ((format (printf, 1, 2)));
28
29#ifdef UML_CONFIG_PRINTK
30extern int printk(const char *fmt, ...)
31 __attribute__ ((format (printf, 1, 2)));
32#else
33static inline int printk(const char *fmt, ...)
34{
35 return 0;
36}
37#endif
38
39extern void schedule(void);
40extern int in_aton(char *str);
41extern int open_gdb_chan(void);
42extern size_t strlcpy(char *, const char *, size_t);
43extern size_t strlcat(char *, const char *, size_t);
44
45#endif