summaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r--arch/um/os-Linux/Makefile16
-rw-r--r--arch/um/os-Linux/drivers/ethertap_kern.c13
-rw-r--r--arch/um/os-Linux/drivers/tuntap_kern.c13
-rw-r--r--arch/um/os-Linux/irq.c162
-rw-r--r--arch/um/os-Linux/mem.c27
-rw-r--r--arch/um/os-Linux/process.c44
-rw-r--r--arch/um/os-Linux/sigio.c323
-rw-r--r--arch/um/os-Linux/start_up.c146
-rw-r--r--arch/um/os-Linux/sys-i386/Makefile2
-rw-r--r--arch/um/os-Linux/sys-i386/tls.c33
-rw-r--r--arch/um/os-Linux/tls.c76
-rw-r--r--arch/um/os-Linux/tt.c10
-rw-r--r--arch/um/os-Linux/tty_log.c218
-rw-r--r--arch/um/os-Linux/umid.c33
14 files changed, 1028 insertions, 88 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile
index 08a4e628b24..f4bfc4c7cca 100644
--- a/arch/um/os-Linux/Makefile
+++ b/arch/um/os-Linux/Makefile
@@ -3,17 +3,17 @@
# Licensed under the GPL
#
-obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \
- start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o user_syms.o \
- util.o drivers/ sys-$(SUBARCH)/
+obj-y = aio.o elf_aux.o file.o helper.o irq.o main.o mem.o process.o sigio.o \
+ signal.o start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o tls.o \
+ user_syms.o util.o drivers/ sys-$(SUBARCH)/
obj-$(CONFIG_MODE_SKAS) += skas/
+obj-$(CONFIG_TTY_LOG) += tty_log.o
+user-objs-$(CONFIG_TTY_LOG) += tty_log.o
-USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \
- start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o util.o
-
-elf_aux.o: $(ARCH_DIR)/kernel-offsets.h
-CFLAGS_elf_aux.o += -I$(objtree)/arch/um
+USER_OBJS := $(user-objs-y) aio.o elf_aux.o file.o helper.o irq.o main.o mem.o \
+ process.o sigio.o signal.o start_up.o time.o trap.o tt.o tty.o tls.o \
+ uaccess.o umid.o util.o
CFLAGS_user_syms.o += -DSUBARCH_$(SUBARCH)
diff --git a/arch/um/os-Linux/drivers/ethertap_kern.c b/arch/um/os-Linux/drivers/ethertap_kern.c
index 6ae4b19d9f5..768606bec23 100644
--- a/arch/um/os-Linux/drivers/ethertap_kern.c
+++ b/arch/um/os-Linux/drivers/ethertap_kern.c
@@ -102,18 +102,7 @@ static struct transport ethertap_transport = {
static int register_ethertap(void)
{
register_transport(&ethertap_transport);
- return(1);
+ return 0;
}
__initcall(register_ethertap);
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only. This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
diff --git a/arch/um/os-Linux/drivers/tuntap_kern.c b/arch/um/os-Linux/drivers/tuntap_kern.c
index 4202b9ebad4..190009a6f89 100644
--- a/arch/um/os-Linux/drivers/tuntap_kern.c
+++ b/arch/um/os-Linux/drivers/tuntap_kern.c
@@ -87,18 +87,7 @@ static struct transport tuntap_transport = {
static int register_tuntap(void)
{
register_transport(&tuntap_transport);
- return(1);
+ return 0;
}
__initcall(register_tuntap);
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only. This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
diff --git a/arch/um/os-Linux/irq.c b/arch/um/os-Linux/irq.c
new file mode 100644
index 00000000000..e599be423da
--- /dev/null
+++ b/arch/um/os-Linux/irq.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Licensed under the GPL
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/poll.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include "user_util.h"
+#include "kern_util.h"
+#include "user.h"
+#include "process.h"
+#include "sigio.h"
+#include "irq_user.h"
+#include "os.h"
+
+static struct pollfd *pollfds = NULL;
+static int pollfds_num = 0;
+static int pollfds_size = 0;
+
+int os_waiting_for_events(struct irq_fd *active_fds)
+{
+ struct irq_fd *irq_fd;
+ int i, n, err;
+
+ n = poll(pollfds, pollfds_num, 0);
+ if(n < 0){
+ err = -errno;
+ if(errno != EINTR)
+ printk("sigio_handler: os_waiting_for_events:"
+ " poll returned %d, errno = %d\n", n, errno);
+ return err;
+ }
+
+ if(n == 0)
+ return 0;
+
+ irq_fd = active_fds;
+
+ for(i = 0; i < pollfds_num; i++){
+ if(pollfds[i].revents != 0){
+ irq_fd->current_events = pollfds[i].revents;
+ pollfds[i].fd = -1;
+ }
+ irq_fd = irq_fd->next;
+ }
+ return n;
+}
+
+int os_isatty(int fd)
+{
+ return(isatty(fd));
+}
+
+int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
+{
+ if (pollfds_num == pollfds_size) {
+ if (size_tmpfds <= pollfds_size * sizeof(pollfds[0])) {
+ /* return min size needed for new pollfds area */
+ return((pollfds_size + 1) * sizeof(pollfds[0]));
+ }
+
+ if(pollfds != NULL){
+ memcpy(tmp_pfd, pollfds,
+ sizeof(pollfds[0]) * pollfds_size);
+ /* remove old pollfds */
+ kfree(pollfds);
+ }
+ pollfds = tmp_pfd;
+ pollfds_size++;
+ } else {
+ /* remove not used tmp_pfd */
+ if (tmp_pfd != NULL)
+ kfree(tmp_pfd);
+ }
+
+ pollfds[pollfds_num] = ((struct pollfd) { .fd = fd,
+ .events = events,
+ .revents = 0 });
+ pollfds_num++;
+
+ return(0);
+}
+
+void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
+ struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2)
+{
+ struct irq_fd **prev;
+ int i = 0;
+
+ prev = &active_fds;
+ while(*prev != NULL){
+ if((*test)(*prev, arg)){
+ struct irq_fd *old_fd = *prev;
+ if((pollfds[i].fd != -1) &&
+ (pollfds[i].fd != (*prev)->fd)){
+ printk("os_free_irq_by_cb - mismatch between "
+ "active_fds and pollfds, fd %d vs %d\n",
+ (*prev)->fd, pollfds[i].fd);
+ goto out;
+ }
+
+ pollfds_num--;
+
+ /* This moves the *whole* array after pollfds[i]
+ * (though it doesn't spot as such)!
+ */
+
+ memmove(&pollfds[i], &pollfds[i + 1],
+ (pollfds_num - i) * sizeof(pollfds[0]));
+ if(*last_irq_ptr2 == &old_fd->next)
+ *last_irq_ptr2 = prev;
+
+ *prev = (*prev)->next;
+ if(old_fd->type == IRQ_WRITE)
+ ignore_sigio_fd(old_fd->fd);
+ kfree(old_fd);
+ continue;
+ }
+ prev = &(*prev)->next;
+ i++;
+ }
+ out:
+ return;
+}
+
+
+int os_get_pollfd(int i)
+{
+ return(pollfds[i].fd);
+}
+
+void os_set_pollfd(int i, int fd)
+{
+ pollfds[i].fd = fd;
+}
+
+void os_set_ioignore(void)
+{
+ set_handler(SIGIO, SIG_IGN, 0, -1);
+}
+
+void init_irq_signals(int on_sigstack)
+{
+ __sighandler_t h;
+ int flags;
+
+ flags = on_sigstack ? SA_ONSTACK : 0;
+ if(timer_irq_inited) h = (__sighandler_t) alarm_handler;
+ else h = boot_timer_handler;
+
+ set_handler(SIGVTALRM, h, flags | SA_RESTART,
+ SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1);
+ set_handler(SIGIO, (__sighandler_t) sig_handler, flags | SA_RESTART,
+ SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1);
+ signal(SIGWINCH, SIG_IGN);
+}
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index 9d7d69a523b..6ab372da965 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -121,36 +121,11 @@ int create_tmp_file(unsigned long long len)
return(fd);
}
-static int create_anon_file(unsigned long long len)
-{
- void *addr;
- int fd;
-
- fd = open("/dev/anon", O_RDWR);
- if(fd < 0) {
- perror("opening /dev/anon");
- exit(1);
- }
-
- addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
- if(addr == MAP_FAILED){
- perror("mapping physmem file");
- exit(1);
- }
- munmap(addr, len);
-
- return(fd);
-}
-
-extern int have_devanon;
-
int create_mem_file(unsigned long long len)
{
int err, fd;
- if(have_devanon)
- fd = create_anon_file(len);
- else fd = create_tmp_file(len);
+ fd = create_tmp_file(len);
err = os_set_exec_close(fd, 1);
if(err < 0){
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
index d261888f39c..8176b0b5204 100644
--- a/arch/um/os-Linux/process.c
+++ b/arch/um/os-Linux/process.c
@@ -11,6 +11,7 @@
#include <linux/unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
+#include <sys/mman.h>
#include "ptrace_user.h"
#include "os.h"
#include "user.h"
@@ -20,6 +21,7 @@
#include "kern_util.h"
#include "longjmp.h"
#include "skas_ptrace.h"
+#include "kern_constants.h"
#define ARBITRARY_ADDR -1
#define FAILURE_PID -1
@@ -187,6 +189,48 @@ int os_unmap_memory(void *addr, int len)
return(0);
}
+#ifndef MADV_REMOVE
+#define MADV_REMOVE 0x5 /* remove these pages & resources */
+#endif
+
+int os_drop_memory(void *addr, int length)
+{
+ int err;
+
+ err = madvise(addr, length, MADV_REMOVE);
+ if(err < 0)
+ err = -errno;
+ return err;
+}
+
+int can_drop_memory(void)
+{
+ void *addr;
+ int fd;
+
+ printk("Checking host MADV_REMOVE support...");
+ fd = create_mem_file(UM_KERN_PAGE_SIZE);
+ if(fd < 0){
+ printk("Creating test memory file failed, err = %d\n", -fd);
+ return 0;
+ }
+
+ addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE, fd, 0);
+ if(addr == MAP_FAILED){
+ printk("Mapping test memory file failed, err = %d\n", -errno);
+ return 0;
+ }
+
+ if(madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0){
+ printk("MADV_REMOVE failed, err = %d\n", -errno);
+ return 0;
+ }
+
+ printk("OK\n");
+ return 1;
+}
+
void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))
{
int flags = 0, pages;
diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
new file mode 100644
index 00000000000..9ba94294714
--- /dev/null
+++ b/arch/um/os-Linux/sigio.c
@@ -0,0 +1,323 @@
+/*
+ * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Licensed under the GPL
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <pty.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <sched.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include "init.h"
+#include "user.h"
+#include "kern_util.h"
+#include "user_util.h"
+#include "sigio.h"
+#include "os.h"
+
+/* Protected by sigio_lock(), also used by sigio_cleanup, which is an
+ * exitcall.
+ */
+static int write_sigio_pid = -1;
+
+/* These arrays are initialized before the sigio thread is started, and
+ * the descriptors closed after it is killed. So, it can't see them change.
+ * On the UML side, they are changed under the sigio_lock.
+ */
+#define SIGIO_FDS_INIT {-1, -1}
+
+static int write_sigio_fds[2] = SIGIO_FDS_INIT;
+static int sigio_private[2] = SIGIO_FDS_INIT;
+
+struct pollfds {
+ struct pollfd *poll;
+ int size;
+ int used;
+};
+
+/* Protected by sigio_lock(). Used by the sigio thread, but the UML thread
+ * synchronizes with it.
+ */
+struct pollfds current_poll = {
+ .poll = NULL,
+ .size = 0,
+ .used = 0
+};
+
+struct pollfds next_poll = {
+ .poll = NULL,
+ .size = 0,
+ .used = 0
+};
+
+static int write_sigio_thread(void *unused)
+{
+ struct pollfds *fds, tmp;
+ struct pollfd *p;
+ int i, n, respond_fd;
+ char c;
+
+ signal(SIGWINCH, SIG_IGN);
+ fds = &current_poll;
+ while(1){
+ n = poll(fds->poll, fds->used, -1);
+ if(n < 0){
+ if(errno == EINTR) continue;
+ printk("write_sigio_thread : poll returned %d, "
+ "errno = %d\n", n, errno);
+ }
+ for(i = 0; i < fds->used; i++){
+ p = &fds->poll[i];
+ if(p->revents == 0) continue;
+ if(p->fd == sigio_private[1]){
+ n = os_read_file(sigio_private[1], &c, sizeof(c));
+ if(n != sizeof(c))
+ printk("write_sigio_thread : "
+ "read failed, err = %d\n", -n);
+ tmp = current_poll;
+ current_poll = next_poll;
+ next_poll = tmp;
+ respond_fd = sigio_private[1];
+ }
+ else {
+ respond_fd = write_sigio_fds[1];
+ fds->used--;
+ memmove(&fds->poll[i], &fds->poll[i + 1],
+ (fds->used - i) * sizeof(*fds->poll));
+ }
+
+ n = os_write_file(respond_fd, &c, sizeof(c));
+ if(n != sizeof(c))
+ printk("write_sigio_thread : write failed, "
+ "err = %d\n", -n);
+ }
+ }
+
+ return 0;
+}
+
+static int need_poll(int n)
+{
+ if(n <= next_poll.size){
+ next_poll.used = n;
+ return(0);
+ }
+ kfree(next_poll.poll);
+ next_poll.poll = um_kmalloc_atomic(n * sizeof(struct pollfd));
+ if(next_poll.poll == NULL){
+ printk("need_poll : failed to allocate new pollfds\n");
+ next_poll.size = 0;
+ next_poll.used = 0;
+ return(-1);
+ }
+ next_poll.size = n;
+ next_poll.used = n;
+ return(0);
+}
+
+/* Must be called with sigio_lock held, because it's needed by the marked
+ * critical section. */
+static void update_thread(void)
+{
+ unsigned long flags;
+ int n;
+ char c;
+
+ flags = set_signals(0);
+ n = os_write_file(sigio_private[0], &c, sizeof(c));
+ if(n != sizeof(c)){
+ printk("update_thread : write failed, err = %d\n", -n);
+ goto fail;
+ }
+
+ n = os_read_file(sigio_private[0], &c, sizeof(c));
+ if(n != sizeof(c)){
+ printk("update_thread : read failed, err = %d\n", -n);
+ goto fail;
+ }
+
+ set_signals(flags);
+ return;
+ fail:
+ /* Critical section start */
+ if(write_sigio_pid != -1)
+ os_kill_process(write_sigio_pid, 1);
+ write_sigio_pid = -1;
+ close(sigio_private[0]);
+ close(sigio_private[1]);
+ close(write_sigio_fds[0]);
+ close(write_sigio_fds[1]);
+ /* Critical section end */
+ set_signals(flags);
+}
+
+int add_sigio_fd(int fd, int read)
+{
+ int err = 0, i, n, events;
+
+ sigio_lock();
+ for(i = 0; i < current_poll.used; i++){
+ if(current_poll.poll[i].fd == fd)
+ goto out;
+ }
+
+ n = current_poll.used + 1;
+ err = need_poll(n);
+ if(err)
+ goto out;
+
+ for(i = 0; i < current_poll.used; i++)
+ next_poll.poll[i] = current_poll.poll[i];
+
+ if(read) events = POLLIN;
+ else events = POLLOUT;
+
+ next_poll.poll[n - 1] = ((struct pollfd) { .fd = fd,
+ .events = events,
+ .revents = 0 });
+ update_thread();
+ out:
+ sigio_unlock();
+ return(err);
+}
+
+int ignore_sigio_fd(int fd)
+{
+ struct pollfd *p;
+ int err = 0, i, n = 0;
+
+ sigio_lock();
+ for(i = 0; i < current_poll.used; i++){
+ if(current_poll.poll[i].fd == fd) break;
+ }
+ if(i == current_poll.used)
+ goto out;
+
+ err = need_poll(current_poll.used - 1);
+ if(err)
+ goto out;
+
+ for(i = 0; i < current_poll.used; i++){
+ p = &current_poll.poll[i];
+ if(p->fd != fd) next_poll.poll[n++] = current_poll.poll[i];
+ }
+ if(n == i){
+ printk("ignore_sigio_fd : fd %d not found\n", fd);
+ err = -1;
+ goto out;
+ }
+
+ update_thread();
+ out:
+ sigio_unlock();
+ return(err);
+}
+
+static struct pollfd *setup_initial_poll(int fd)
+{
+ struct pollfd *p;
+
+ p = um_kmalloc(sizeof(struct pollfd));
+ if (p == NULL) {
+ printk("setup_initial_poll : failed to allocate poll\n");
+ return NULL;
+ }
+ *p = ((struct pollfd) { .fd = fd,
+ .events = POLLIN,
+ .revents = 0 });
+ return p;
+}
+
+void write_sigio_workaround(void)
+{
+ unsigned long stack;
+ struct pollfd *p;
+ int err;
+ int l_write_sigio_fds[2];
+ int l_sigio_private[2];
+ int l_write_sigio_pid;
+
+ /* We call this *tons* of times - and most ones we must just fail. */
+ sigio_lock();
+ l_write_sigio_pid = write_sigio_pid;
+ sigio_unlock();
+
+ if (l_write_sigio_pid != -1)
+ return;
+
+ err = os_pipe(l_write_sigio_fds, 1, 1);
+ if(err < 0){
+ printk("write_sigio_workaround - os_pipe 1 failed, "
+ "err = %d\n", -err);
+ return;
+ }
+ err = os_pipe(l_sigio_private, 1, 1);
+ if(err < 0){
+ printk("write_sigio_workaround - os_pipe 2 failed, "
+ "err = %d\n", -err);
+ goto out_close1;
+ }
+
+ p = setup_initial_poll(l_sigio_private[1]);
+ if(!p)
+ goto out_close2;
+
+ sigio_lock();
+
+ /* Did we race? Don't try to optimize this, please, it's not so likely
+ * to happen, and no more than once at the boot. */
+ if(write_sigio_pid != -1)
+ goto out_free;
+
+ current_poll = ((struct pollfds) { .poll = p,
+ .used = 1,
+ .size = 1 });
+
+ if (write_sigio_irq(l_write_sigio_fds[0]))
+ goto out_clear_poll;
+
+ memcpy(write_sigio_fds, l_write_sigio_fds, sizeof(l_write_sigio_fds));
+ memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private));
+
+ write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
+ CLONE_FILES | CLONE_VM, &stack, 0);
+
+ if (write_sigio_pid < 0)
+ goto out_clear;
+
+ sigio_unlock();
+ return;
+
+out_clear:
+ write_sigio_pid = -1;
+ write_sigio_fds[0] = -1;
+ write_sigio_fds[1] = -1;
+ sigio_private[0] = -1;
+ sigio_private[1] = -1;
+out_clear_poll:
+ current_poll = ((struct pollfds) { .poll = NULL,
+ .size = 0,
+ .used = 0 });
+out_free:
+ kfree(p);
+ sigio_unlock();
+out_close2:
+ close(l_sigio_private[0]);
+ close(l_sigio_private[1]);
+out_close1:
+ close(l_write_sigio_fds[0]);
+ close(l_write_sigio_fds[1]);
+}
+
+void sigio_cleanup(void)
+{
+ if(write_sigio_pid != -1){
+ os_kill_process(write_sigio_pid, 1);
+ write_sigio_pid = -1;
+ }
+}
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c
index 829d6b0d8b0..387e26af301 100644
--- a/arch/um/os-Linux/start_up.c
+++ b/arch/um/os-Linux/start_up.c
@@ -3,6 +3,7 @@
* Licensed under the GPL
*/
+#include <pty.h>
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
@@ -469,25 +470,6 @@ int can_do_skas(void)
}
#endif
-int have_devanon = 0;
-
-/* Runs on boot kernel stack - already safe to use printk. */
-
-void check_devanon(void)
-{
- int fd;
-
- printk("Checking for /dev/anon on the host...");
- fd = open("/dev/anon", O_RDWR);
- if(fd < 0){
- printk("Not available (open failed with errno %d)\n", errno);
- return;
- }
-
- printk("OK\n");
- have_devanon = 1;
-}
-
int __init parse_iomem(char *str, int *add)
{
struct iomem_region *new;
@@ -539,3 +521,129 @@ int __init parse_iomem(char *str, int *add)
return(1);
}
+
+/* Changed during early boot */
+int pty_output_sigio = 0;
+int pty_close_sigio = 0;
+
+/* Used as a flag during SIGIO testing early in boot */
+static volatile int got_sigio = 0;
+
+static void __init handler(int sig)
+{
+ got_sigio = 1;
+}
+
+struct openpty_arg {
+ int master;
+ int slave;
+ int err;
+};
+
+static void openpty_cb(void *arg)
+{
+ struct openpty_arg *info = arg;
+
+ info->err = 0;
+ if(openpty(&info->master, &info->slave, NULL, NULL, NULL))
+ info->err = -errno;
+}
+
+static void __init check_one_sigio(void (*proc)(int, int))
+{
+ struct sigaction old, new;
+ struct openpty_arg pty = { .master = -1, .slave = -1 };
+ int master, slave, err;
+
+ initial_thread_cb(openpty_cb, &pty);
+ if(pty.err){
+ printk("openpty failed, errno = %d\n", -pty.err);
+ return;
+ }
+
+ master = pty.master;
+ slave = pty.slave;
+
+ if((master == -1) || (slave == -1)){
+ printk("openpty failed to allocate a pty\n");
+ return;
+ }
+
+ /* Not now, but complain so we now where we failed. */
+ err = raw(master);
+ if (err < 0)
+ panic("check_sigio : __raw failed, errno = %d\n", -err);
+
+ err = os_sigio_async(master, slave);
+ if(err < 0)
+ panic("tty_fds : sigio_async failed, err = %d\n", -err);
+
+ if(sigaction(SIGIO, NULL, &old) < 0)
+ panic("check_sigio : sigaction 1 failed, errno = %d\n", errno);
+ new = old;
+ new.sa_handler = handler;
+ if(sigaction(SIGIO, &new, NULL) < 0)
+ panic("check_sigio : sigaction 2 failed, errno = %d\n", errno);
+
+ got_sigio = 0;
+ (*proc)(master, slave);
+
+ close(master);
+ close(slave);
+
+ if(sigaction(SIGIO, &old, NULL) < 0)
+ panic("check_sigio : sigaction 3 failed, errno = %d\n", errno);
+}
+
+static void tty_output(int master, int slave)
+{
+ int n;
+ char buf[512];
+
+ printk("Checking that host ptys support output SIGIO...");
+
+ memset(buf, 0, sizeof(buf));
+
+ while(os_write_file(master, buf, sizeof(buf)) > 0) ;
+ if(errno != EAGAIN)
+ panic("check_sigio : write failed, errno = %d\n", errno);
+ while(((n = os_read_file(slave, buf, sizeof(buf))) > 0) && !got_sigio) ;
+
+ if(got_sigio){
+ printk("Yes\n");
+ pty_output_sigio = 1;
+ }
+ else if(n == -EAGAIN) printk("No, enabling workaround\n");
+ else panic("check_sigio : read failed, err = %d\n", n);
+}
+
+static void tty_close(int master, int slave)
+{
+ printk("Checking that host ptys support SIGIO on close...");
+
+ close(slave);
+ if(got_sigio){
+ printk("Yes\n");
+ pty_close_sigio = 1;
+ }
+ else printk("No, enabling workaround\n");
+}
+
+void __init check_sigio(void)
+{
+ if((os_access("/dev/ptmx", OS_ACC_R_OK) < 0) &&
+ (os_access("/dev/ptyp0", OS_ACC_R_OK) < 0)){
+ printk("No pseudo-terminals available - skipping pty SIGIO "
+ "check\n");
+ return;
+ }
+ check_one_sigio(tty_output);
+ check_one_sigio(tty_close);
+}
+
+void os_check_bugs(void)
+{
+ check_ptrace();
+ check_sigio();
+}
+
diff --git a/arch/um/os-Linux/sys-i386/Makefile b/arch/um/os-Linux/sys-i386/Makefile
index 340ef26f594..b3213613c41 100644
--- a/arch/um/os-Linux/sys-i386/Makefile
+++ b/arch/um/os-Linux/sys-i386/Makefile
@@ -3,7 +3,7 @@
# Licensed under the GPL
#
-obj-$(CONFIG_MODE_SKAS) = registers.o
+obj-$(CONFIG_MODE_SKAS) = registers.o tls.o
USER_OBJS := $(obj-y)
diff --git a/arch/um/os-Linux/sys-i386/tls.c b/arch/um/os-Linux/sys-i386/tls.c
new file mode 100644
index 00000000000..ba21f0e04a2
--- /dev/null
+++ b/arch/um/os-Linux/sys-i386/tls.c
@@ -0,0 +1,33 @@
+#include <linux/unistd.h>
+#include "sysdep/tls.h"
+#include "user_util.h"
+
+static _syscall1(int, get_thread_area, user_desc_t *, u_info);
+
+/* Checks whether host supports TLS, and sets *tls_min according to the value
+ * valid on the host.
+ * i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */
+void check_host_supports_tls(int *supports_tls, int *tls_min) {
+ /* Values for x86 and x86_64.*/
+ int val[] = {GDT_ENTRY_TLS_MIN_I386, GDT_ENTRY_TLS_MIN_X86_64};
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(val); i++) {
+ user_desc_t info;
+ info.entry_number = val[i];
+
+ if (get_thread_area(&info) == 0) {
+ *tls_min = val[i];
+ *supports_tls = 1;
+ return;
+ } else {
+ if (errno == EINVAL)
+ continue;
+ else if (errno == ENOSYS)
+ *supports_tls = 0;
+ return;
+ }
+ }
+
+ *supports_tls = 0;
+}
diff --git a/arch/um/os-Linux/tls.c b/arch/um/os-Linux/tls.c
new file mode 100644
index 00000000000..9cb09a45546
--- /dev/null
+++ b/arch/um/os-Linux/tls.c
@@ -0,0 +1,76 @@
+#include <errno.h>
+#include <sys/ptrace.h>
+#include <asm/ldt.h>
+#include "sysdep/tls.h"
+#include "uml-config.h"
+
+/* TLS support - we basically rely on the host's one.*/
+
+/* In TT mode, this should be called only by the tracing thread, and makes sense
+ * only for PTRACE_SET_THREAD_AREA. In SKAS mode, it's used normally.
+ *
+ */
+
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
+#ifndef PTRACE_SET_THREAD_AREA
+#define PTRACE_SET_THREAD_AREA 26
+#endif
+
+int os_set_thread_area(user_desc_t *info, int pid)
+{
+ int ret;
+
+ ret = ptrace(PTRACE_SET_THREAD_AREA, pid, info->entry_number,
+ (unsigned long) info);
+ if (ret < 0)
+ ret = -errno;
+ return ret;
+}
+
+#ifdef UML_CONFIG_MODE_SKAS
+
+int os_get_thread_area(user_desc_t *info, int pid)
+{
+ int ret;
+
+ ret = ptrace(PTRACE_GET_THREAD_AREA, pid, info->entry_number,
+ (unsigned long) info);
+ if (ret < 0)
+ ret = -errno;
+ return ret;
+}
+
+#endif
+
+#ifdef UML_CONFIG_MODE_TT
+#include "linux/unistd.h"
+
+static _syscall1(int, get_thread_area, user_desc_t *, u_info);
+static _syscall1(int, set_thread_area, user_desc_t *, u_info);
+
+int do_set_thread_area_tt(user_desc_t *info)
+{
+ int ret;
+
+ ret = set_thread_area(info);
+ if (ret < 0) {
+ ret = -errno;
+ }
+ return ret;
+}
+
+int do_get_thread_area_tt(user_desc_t *info)
+{
+ int ret;
+
+ ret = get_thread_area(info);
+ if (ret < 0) {
+ ret = -errno;
+ }
+ return ret;
+}
+
+#endif /* UML_CONFIG_MODE_TT */
diff --git a/arch/um/os-Linux/tt.c b/arch/um/os-Linux/tt.c
index 919d19f1153..5461a065bbb 100644
--- a/arch/um/os-Linux/tt.c
+++ b/arch/um/os-Linux/tt.c
@@ -110,6 +110,16 @@ int wait_for_stop(int pid, int sig, int cont_type, void *relay)
}
}
+void forward_ipi(int fd, int pid)
+{
+ int err;
+
+ err = os_set_owner(fd, pid);
+ if(err < 0)
+ printk("forward_ipi: set_owner failed, fd = %d, me = %d, "
+ "target = %d, err = %d\n", fd, os_getpid(), pid, -err);
+}
+
/*
*-------------------------
* only for tt mode (will be deleted in future...)
diff --git a/arch/um/os-Linux/tty_log.c b/arch/um/os-Linux/tty_log.c
new file mode 100644
index 00000000000..c6ba56c1560
--- /dev/null
+++ b/arch/um/os-Linux/tty_log.c
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) and
+ * geoffrey hing <ghing@net.ohio-state.edu>
+ * Licensed under the GPL
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include "init.h"
+#include "user.h"
+#include "kern_util.h"
+#include "os.h"
+
+#define TTY_LOG_DIR "./"
+
+/* Set early in boot and then unchanged */
+static char *tty_log_dir = TTY_LOG_DIR;
+static int tty_log_fd = -1;
+
+#define TTY_LOG_OPEN 1
+#define TTY_LOG_CLOSE 2
+#define TTY_LOG_WRITE 3
+#define TTY_LOG_EXEC 4
+
+#define TTY_READ 1
+#define TTY_WRITE 2
+
+struct tty_log_buf {
+ int what;
+ unsigned long tty;
+ int len;
+ int direction;
+ unsigned long sec;
+ unsigned long usec;
+};
+
+int open_tty_log(void *tty, void *current_tty)
+{
+ struct timeval tv;
+ struct tty_log_buf data;
+ char buf[strlen(tty_log_dir) + sizeof("01234567890-01234567\0")];
+ int fd;
+
+ gettimeofday(&tv, NULL);
+ if(tty_log_fd != -1){
+ data = ((struct tty_log_buf) { .what = TTY_LOG_OPEN,
+ .tty = (unsigned long) tty,
+ .len = sizeof(current_tty),
+ .direction = 0,
+ .sec = tv.tv_sec,
+ .usec = tv.tv_usec } );
+ os_write_file(tty_log_fd, &data, sizeof(data));
+ os_write_file(tty_log_fd, &current_tty, data.len);
+ return(tty_log_fd);
+ }
+
+ sprintf(buf, "%s/%0u-%0u", tty_log_dir, (unsigned int) tv.tv_sec,
+ (unsigned int) tv.tv_usec);
+
+ fd = os_open_file(buf, of_append(of_create(of_rdwr(OPENFLAGS()))),
+ 0644);
+ if(fd < 0){
+ printk("open_tty_log : couldn't open '%s', errno = %d\n",
+ buf, -fd);
+ }
+ return(fd);
+}
+
+void close_tty_log(int fd, void *tty)
+{
+ struct tty_log_buf data;
+ struct timeval tv;
+
+ if(tty_log_fd != -1){
+ gettimeofday(&tv, NULL);
+ data = ((struct tty_log_buf) { .what = TTY_LOG_CLOSE,
+ .tty = (unsigned long) tty,
+ .len = 0,
+ .direction = 0,
+ .sec = tv.tv_sec,
+ .usec = tv.tv_usec } );
+ os_write_file(tty_log_fd, &data, sizeof(data));
+ return;
+ }
+ os_close_file(fd);
+}
+
+static int log_chunk(int fd, const char *buf, int len)
+{
+ int total = 0, try, missed, n;
+ char chunk[64];
+
+ while(len > 0){
+ try = (len > sizeof(chunk)) ? sizeof(chunk) : len;
+ missed = copy_from_user_proc(chunk, (char *) buf, try);
+ try -= missed;
+ n = os_write_file(fd, chunk, try);
+ if(n != try) {
+ if(n < 0)
+ return(n);
+ return(-EIO);
+ }
+ if(missed != 0)
+ return(-EFAULT);
+
+ len -= try;
+ total += try;
+ buf += try;
+ }
+
+ return(total);
+}
+
+int write_tty_log(int fd, const char *buf, int len, void *tty, int is_read)
+{
+ struct timeval tv;
+ struct tty_log_buf data;
+ int direction;
+
+ if(fd == tty_log_fd){
+ gettimeofday(&tv, NULL);
+ direction = is_read ? TTY_READ : TTY_WRITE;
+ data = ((struct tty_log_buf) { .what = TTY_LOG_WRITE,
+ .tty = (unsigned long) tty,
+ .len = len,
+ .direction = direction,
+ .sec = tv.tv_sec,
+ .usec = tv.tv_usec } );
+ os_write_file(tty_log_fd, &data, sizeof(data));
+ }
+
+ return(log_chunk(fd, buf, len));
+}
+
+void log_exec(char **argv, void *tty)
+{
+ struct timeval tv;
+ struct tty_log_buf data;
+ char **ptr,*arg;
+ int len;
+
+ if(tty_log_fd == -1) return;
+
+ gettimeofday(&tv, NULL);
+
+ len = 0;
+ for(ptr = argv; ; ptr++){
+ if(copy_from_user_proc(&arg, ptr, sizeof(arg)))
+ return;
+ if(arg == NULL) break;
+ len += strlen_user_proc(arg);
+ }
+
+ data = ((struct tty_log_buf) { .what = TTY_LOG_EXEC,
+ .tty = (unsigned long) tty,
+ .len = len,
+ .direction = 0,
+ .sec = tv.tv_sec,
+ .usec = tv.tv_usec } );
+ os_write_file(tty_log_fd, &data, sizeof(data));
+
+ for(ptr = argv; ; ptr++){
+ if(copy_from_user_proc(&arg, ptr, sizeof(arg)))
+ return;
+ if(arg == NULL) break;
+ log_chunk(tty_log_fd, arg, strlen_user_proc(arg));
+ }
+}
+
+extern void register_tty_logger(int (*opener)(void *, void *),
+ int (*writer)(int, const char *, int,
+ void *, int),
+ void (*closer)(int, void *));
+
+static int register_logger(void)
+{
+ register_tty_logger(open_tty_log, write_tty_log, close_tty_log);
+ return(0);
+}
+
+__uml_initcall(register_logger);
+
+static int __init set_tty_log_dir(char *name, int *add)
+{
+ tty_log_dir = name;
+ return 0;
+}
+
+__uml_setup("tty_log_dir=", set_tty_log_dir,
+"tty_log_dir=<directory>\n"
+" This is used to specify the directory where the logs of all pty\n"
+" data from this UML machine will be written.\n\n"
+);
+
+static int __init set_tty_log_fd(char *name, int *add)
+{
+ char *end;
+
+ tty_log_fd = strtoul(name, &end, 0);
+ if((*end != '\0') || (end == name)){
+ printf("set_tty_log_fd - strtoul failed on '%s'\n", name);
+ tty_log_fd = -1;
+ }
+
+ *add = 0;
+ return 0;
+}
+
+__uml_setup("tty_log_fd=", set_tty_log_fd,
+"tty_log_fd=<fd>\n"
+" This is used to specify a preconfigured file descriptor to which all\n"
+" tty data will be written. Preconfigure the descriptor with something\n"
+" like '10>tty_log tty_log_fd=10'.\n\n"
+);
diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c
index ecf107ae5ac..198e5916328 100644
--- a/arch/um/os-Linux/umid.c
+++ b/arch/um/os-Linux/umid.c
@@ -143,8 +143,10 @@ static int not_dead_yet(char *dir)
goto out_close;
}
- if((kill(p, 0) == 0) || (errno != ESRCH))
+ if((kill(p, 0) == 0) || (errno != ESRCH)){
+ printk("umid \"%s\" is already in use by pid %d\n", umid, p);
return 1;
+ }
err = actually_do_remove(dir);
if(err)
@@ -234,33 +236,44 @@ int __init make_umid(void)
err = mkdir(tmp, 0777);
if(err < 0){
err = -errno;
- if(errno != EEXIST)
+ if(err != -EEXIST)
goto err;
- if(not_dead_yet(tmp) < 0)
+ /* 1 -> this umid is already in use
+ * < 0 -> we couldn't remove the umid directory
+ * In either case, we can't use this umid, so return -EEXIST.
+ */
+ if(not_dead_yet(tmp) != 0)
goto err;
err = mkdir(tmp, 0777);
}
- if(err < 0){
- printk("Failed to create '%s' - err = %d\n", umid, err);
- goto err_rmdir;
+ if(err){
+ err = -errno;
+ printk("Failed to create '%s' - err = %d\n", umid, -errno);
+ goto err;
}
umid_setup = 1;
create_pid_file();
- return 0;
-
- err_rmdir:
- rmdir(tmp);
+ err = 0;
err:
return err;
}
static int __init make_umid_init(void)
{
+ if(!make_umid())
+ return 0;
+
+ /* If initializing with the given umid failed, then try again with
+ * a random one.
+ */
+ printk("Failed to initialize umid \"%s\", trying with a random umid\n",
+ umid);
+ *umid = '\0';
make_umid();
return 0;