aboutsummaryrefslogtreecommitdiff
path: root/arch/um/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/drivers')
-rw-r--r--arch/um/drivers/Makefile46
-rw-r--r--arch/um/drivers/chan_kern.c577
-rw-r--r--arch/um/drivers/chan_user.c210
-rw-r--r--arch/um/drivers/cow.h42
-rw-r--r--arch/um/drivers/cow_sys.h48
-rw-r--r--arch/um/drivers/cow_user.c378
-rw-r--r--arch/um/drivers/daemon.h35
-rw-r--r--arch/um/drivers/daemon_kern.c108
-rw-r--r--arch/um/drivers/daemon_user.c197
-rw-r--r--arch/um/drivers/fd.c108
-rw-r--r--arch/um/drivers/harddog_kern.c190
-rw-r--r--arch/um/drivers/harddog_user.c143
-rw-r--r--arch/um/drivers/hostaudio_kern.c352
-rw-r--r--arch/um/drivers/line.c681
-rw-r--r--arch/um/drivers/mcast.h30
-rw-r--r--arch/um/drivers/mcast_kern.c143
-rw-r--r--arch/um/drivers/mcast_user.c177
-rw-r--r--arch/um/drivers/mconsole_kern.c619
-rw-r--r--arch/um/drivers/mconsole_user.c215
-rw-r--r--arch/um/drivers/mmapper_kern.c150
-rw-r--r--arch/um/drivers/net_kern.c896
-rw-r--r--arch/um/drivers/net_user.c255
-rw-r--r--arch/um/drivers/null.c56
-rw-r--r--arch/um/drivers/pcap_kern.c123
-rw-r--r--arch/um/drivers/pcap_user.c143
-rw-r--r--arch/um/drivers/pcap_user.h31
-rw-r--r--arch/um/drivers/port.h30
-rw-r--r--arch/um/drivers/port_kern.c309
-rw-r--r--arch/um/drivers/port_user.c225
-rw-r--r--arch/um/drivers/pty.c162
-rw-r--r--arch/um/drivers/random.c122
-rw-r--r--arch/um/drivers/slip.h39
-rw-r--r--arch/um/drivers/slip_kern.c109
-rw-r--r--arch/um/drivers/slip_proto.h93
-rw-r--r--arch/um/drivers/slip_user.c280
-rw-r--r--arch/um/drivers/slirp.h51
-rw-r--r--arch/um/drivers/slirp_kern.c135
-rw-r--r--arch/um/drivers/slirp_user.c201
-rw-r--r--arch/um/drivers/ssl.c251
-rw-r--r--arch/um/drivers/ssl.h23
-rw-r--r--arch/um/drivers/stderr_console.c45
-rw-r--r--arch/um/drivers/stdio_console.c205
-rw-r--r--arch/um/drivers/stdio_console.h21
-rw-r--r--arch/um/drivers/tty.c92
-rw-r--r--arch/um/drivers/ubd_kern.c1669
-rw-r--r--arch/um/drivers/ubd_user.c75
-rw-r--r--arch/um/drivers/xterm.c225
-rw-r--r--arch/um/drivers/xterm.h22
-rw-r--r--arch/um/drivers/xterm_kern.c93
49 files changed, 10430 insertions, 0 deletions
diff --git a/arch/um/drivers/Makefile b/arch/um/drivers/Makefile
new file mode 100644
index 00000000000..323f72c64cd
--- /dev/null
+++ b/arch/um/drivers/Makefile
@@ -0,0 +1,46 @@
+#
+# Copyright (C) 2000, 2002, 2003 Jeff Dike (jdike@karaya.com)
+# Licensed under the GPL
+#
+
+# pcap is broken in 2.5 because kbuild doesn't allow pcap.a to be linked
+# in to pcap.o
+
+slip-objs := slip_kern.o slip_user.o
+slirp-objs := slirp_kern.o slirp_user.o
+daemon-objs := daemon_kern.o daemon_user.o
+mcast-objs := mcast_kern.o mcast_user.o
+#pcap-objs := pcap_kern.o pcap_user.o $(PCAP)
+net-objs := net_kern.o net_user.o
+mconsole-objs := mconsole_kern.o mconsole_user.o
+hostaudio-objs := hostaudio_kern.o
+ubd-objs := ubd_kern.o ubd_user.o
+port-objs := port_kern.o port_user.o
+harddog-objs := harddog_kern.o harddog_user.o
+
+obj-y := stdio_console.o fd.o chan_kern.o chan_user.o line.o
+obj-$(CONFIG_SSL) += ssl.o
+obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o
+
+obj-$(CONFIG_UML_NET_SLIP) += slip.o
+obj-$(CONFIG_UML_NET_SLIRP) += slirp.o
+obj-$(CONFIG_UML_NET_DAEMON) += daemon.o
+obj-$(CONFIG_UML_NET_MCAST) += mcast.o
+#obj-$(CONFIG_UML_NET_PCAP) += pcap.o $(PCAP)
+obj-$(CONFIG_UML_NET) += net.o
+obj-$(CONFIG_MCONSOLE) += mconsole.o
+obj-$(CONFIG_MMAPPER) += mmapper_kern.o
+obj-$(CONFIG_BLK_DEV_UBD) += ubd.o
+obj-$(CONFIG_HOSTAUDIO) += hostaudio.o
+obj-$(CONFIG_NULL_CHAN) += null.o
+obj-$(CONFIG_PORT_CHAN) += port.o
+obj-$(CONFIG_PTY_CHAN) += pty.o
+obj-$(CONFIG_TTY_CHAN) += tty.o
+obj-$(CONFIG_XTERM_CHAN) += xterm.o xterm_kern.o
+obj-$(CONFIG_UML_WATCHDOG) += harddog.o
+obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
+obj-$(CONFIG_UML_RANDOM) += random.o
+
+USER_OBJS := fd.o null.o pty.o tty.o xterm.o
+
+include arch/um/scripts/Makefile.rules
diff --git a/arch/um/drivers/chan_kern.c b/arch/um/drivers/chan_kern.c
new file mode 100644
index 00000000000..1f77deb3fd2
--- /dev/null
+++ b/arch/um/drivers/chan_kern.c
@@ -0,0 +1,577 @@
+/*
+ * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Licensed under the GPL
+ */
+
+#include <linux/stddef.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/string.h>
+#include <linux/tty_flip.h>
+#include <asm/irq.h>
+#include "chan_kern.h"
+#include "user_util.h"
+#include "kern.h"
+#include "irq_user.h"
+#include "sigio.h"
+#include "line.h"
+#include "os.h"
+
+#ifdef CONFIG_NOCONFIG_CHAN
+static void *not_configged_init(char *str, int device, struct chan_opts *opts)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+ return(NULL);
+}
+
+static int not_configged_open(int input, int output, int primary, void *data,
+ char **dev_out)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+ return(-ENODEV);
+}
+
+static void not_configged_close(int fd, void *data)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+}
+
+static int not_configged_read(int fd, char *c_out, void *data)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+ return(-EIO);
+}
+
+static int not_configged_write(int fd, const char *buf, int len, void *data)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+ return(-EIO);
+}
+
+static int not_configged_console_write(int fd, const char *buf, int len,
+ void *data)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+ return(-EIO);
+}
+
+static int not_configged_window_size(int fd, void *data, unsigned short *rows,
+ unsigned short *cols)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+ return(-ENODEV);
+}
+
+static void not_configged_free(void *data)
+{
+ printk(KERN_ERR "Using a channel type which is configured out of "
+ "UML\n");
+}
+
+static struct chan_ops not_configged_ops = {
+ .init = not_configged_init,
+ .open = not_configged_open,
+ .close = not_configged_close,
+ .read = not_configged_read,
+ .write = not_configged_write,
+ .console_write = not_configged_console_write,
+ .window_size = not_configged_window_size,
+ .free = not_configged_free,
+ .winch = 0,
+};
+#endif /* CONFIG_NOCONFIG_CHAN */
+
+void generic_close(int fd, void *unused)
+{
+ os_close_file(fd);
+}
+
+int generic_read(int fd, char *c_out, void *unused)
+{
+ int n;
+
+ n = os_read_file(fd, c_out, sizeof(*c_out));
+
+ if(n == -EAGAIN)
+ return(0);
+ else if(n == 0)
+ return(-EIO);
+ return(n);
+}
+
+/* XXX Trivial wrapper around os_write_file */
+
+int generic_write(int fd, const char *buf, int n, void *unused)
+{
+ return(os_write_file(fd, buf, n));
+}
+
+int generic_window_size(int fd, void *unused, unsigned short *rows_out,
+ unsigned short *cols_out)
+{
+ int rows, cols;
+ int ret;
+
+ ret = os_window_size(fd, &rows, &cols);
+ if(ret < 0)
+ return(ret);
+
+ ret = ((*rows_out != rows) || (*cols_out != cols));
+
+ *rows_out = rows;
+ *cols_out = cols;
+
+ return(ret);
+}
+
+void generic_free(void *data)
+{
+ kfree(data);
+}
+
+static void tty_receive_char(struct tty_struct *tty, char ch)
+{
+ if(tty == NULL) return;
+
+ if(I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) {
+ if(ch == STOP_CHAR(tty)){
+ stop_tty(tty);
+ return;
+ }
+ else if(ch == START_CHAR(tty)){
+ start_tty(tty);
+ return;
+ }
+ }
+
+ if((tty->flip.flag_buf_ptr == NULL) ||
+ (tty->flip.char_buf_ptr == NULL))
+ return;
+ tty_insert_flip_char(tty, ch, TTY_NORMAL);
+}
+
+static int open_one_chan(struct chan *chan, int input, int output, int primary)
+{
+ int fd;
+
+ if(chan->opened) return(0);
+ if(chan->ops->open == NULL) fd = 0;
+ else fd = (*chan->ops->open)(input, output, primary, chan->data,
+ &chan->dev);
+ if(fd < 0) return(fd);
+ chan->fd = fd;
+
+ chan->opened = 1;
+ return(0);
+}
+
+int open_chan(struct list_head *chans)
+{
+ struct list_head *ele;
+ struct chan *chan;
+ int ret, err = 0;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ ret = open_one_chan(chan, chan->input, chan->output,
+ chan->primary);
+ if(chan->primary) err = ret;
+ }
+ return(err);
+}
+
+void chan_enable_winch(struct list_head *chans, struct tty_struct *tty)
+{
+ struct list_head *ele;
+ struct chan *chan;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(chan->primary && chan->output && chan->ops->winch){
+ register_winch(chan->fd, tty);
+ return;
+ }
+ }
+}
+
+void enable_chan(struct list_head *chans, struct tty_struct *tty)
+{
+ struct list_head *ele;
+ struct chan *chan;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(!chan->opened) continue;
+
+ line_setup_irq(chan->fd, chan->input, chan->output, tty);
+ }
+}
+
+void close_chan(struct list_head *chans)
+{
+ struct chan *chan;
+
+ /* Close in reverse order as open in case more than one of them
+ * refers to the same device and they save and restore that device's
+ * state. Then, the first one opened will have the original state,
+ * so it must be the last closed.
+ */
+ list_for_each_entry_reverse(chan, chans, list) {
+ if(!chan->opened) continue;
+ if(chan->ops->close != NULL)
+ (*chan->ops->close)(chan->fd, chan->data);
+ chan->opened = 0;
+ chan->fd = -1;
+ }
+}
+
+int write_chan(struct list_head *chans, const char *buf, int len,
+ int write_irq)
+{
+ struct list_head *ele;
+ struct chan *chan = NULL;
+ int n, ret = 0;
+
+ list_for_each(ele, chans) {
+ chan = list_entry(ele, struct chan, list);
+ if (!chan->output || (chan->ops->write == NULL))
+ continue;
+ n = chan->ops->write(chan->fd, buf, len, chan->data);
+ if (chan->primary) {
+ ret = n;
+ if ((ret == -EAGAIN) || ((ret >= 0) && (ret < len)))
+ reactivate_fd(chan->fd, write_irq);
+ }
+ }
+ return(ret);
+}
+
+int console_write_chan(struct list_head *chans, const char *buf, int len)
+{
+ struct list_head *ele;
+ struct chan *chan;
+ int n, ret = 0;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(!chan->output || (chan->ops->console_write == NULL))
+ continue;
+ n = chan->ops->console_write(chan->fd, buf, len, chan->data);
+ if(chan->primary) ret = n;
+ }
+ return(ret);
+}
+
+int console_open_chan(struct line *line, struct console *co, struct chan_opts *opts)
+{
+ if (!list_empty(&line->chan_list))
+ return 0;
+
+ if (0 != parse_chan_pair(line->init_str, &line->chan_list,
+ line->init_pri, co->index, opts))
+ return -1;
+ if (0 != open_chan(&line->chan_list))
+ return -1;
+ printk("Console initialized on /dev/%s%d\n",co->name,co->index);
+ return 0;
+}
+
+int chan_window_size(struct list_head *chans, unsigned short *rows_out,
+ unsigned short *cols_out)
+{
+ struct list_head *ele;
+ struct chan *chan;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(chan->primary){
+ if(chan->ops->window_size == NULL) return(0);
+ return(chan->ops->window_size(chan->fd, chan->data,
+ rows_out, cols_out));
+ }
+ }
+ return(0);
+}
+
+void free_one_chan(struct chan *chan)
+{
+ list_del(&chan->list);
+ if(chan->ops->free != NULL)
+ (*chan->ops->free)(chan->data);
+ free_irq_by_fd(chan->fd);
+ if(chan->primary && chan->output) ignore_sigio_fd(chan->fd);
+ kfree(chan);
+}
+
+void free_chan(struct list_head *chans)
+{
+ struct list_head *ele, *next;
+ struct chan *chan;
+
+ list_for_each_safe(ele, next, chans){
+ chan = list_entry(ele, struct chan, list);
+ free_one_chan(chan);
+ }
+}
+
+static int one_chan_config_string(struct chan *chan, char *str, int size,
+ char **error_out)
+{
+ int n = 0;
+
+ if(chan == NULL){
+ CONFIG_CHUNK(str, size, n, "none", 1);
+ return(n);
+ }
+
+ CONFIG_CHUNK(str, size, n, chan->ops->type, 0);
+
+ if(chan->dev == NULL){
+ CONFIG_CHUNK(str, size, n, "", 1);
+ return(n);
+ }
+
+ CONFIG_CHUNK(str, size, n, ":", 0);
+ CONFIG_CHUNK(str, size, n, chan->dev, 0);
+
+ return(n);
+}
+
+static int chan_pair_config_string(struct chan *in, struct chan *out,
+ char *str, int size, char **error_out)
+{
+ int n;
+
+ n = one_chan_config_string(in, str, size, error_out);
+ str += n;
+ size -= n;
+
+ if(in == out){
+ CONFIG_CHUNK(str, size, n, "", 1);
+ return(n);
+ }
+
+ CONFIG_CHUNK(str, size, n, ",", 1);
+ n = one_chan_config_string(out, str, size, error_out);
+ str += n;
+ size -= n;
+ CONFIG_CHUNK(str, size, n, "", 1);
+
+ return(n);
+}
+
+int chan_config_string(struct list_head *chans, char *str, int size,
+ char **error_out)
+{
+ struct list_head *ele;
+ struct chan *chan, *in = NULL, *out = NULL;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(!chan->primary)
+ continue;
+ if(chan->input)
+ in = chan;
+ if(chan->output)
+ out = chan;
+ }
+
+ return(chan_pair_config_string(in, out, str, size, error_out));
+}
+
+struct chan_type {
+ char *key;
+ struct chan_ops *ops;
+};
+
+struct chan_type chan_table[] = {
+ { "fd", &fd_ops },
+
+#ifdef CONFIG_NULL_CHAN
+ { "null", &null_ops },
+#else
+ { "null", &not_configged_ops },
+#endif
+
+#ifdef CONFIG_PORT_CHAN
+ { "port", &port_ops },
+#else
+ { "port", &not_configged_ops },
+#endif
+
+#ifdef CONFIG_PTY_CHAN
+ { "pty", &pty_ops },
+ { "pts", &pts_ops },
+#else
+ { "pty", &not_configged_ops },
+ { "pts", &not_configged_ops },
+#endif
+
+#ifdef CONFIG_TTY_CHAN
+ { "tty", &tty_ops },
+#else
+ { "tty", &not_configged_ops },
+#endif
+
+#ifdef CONFIG_XTERM_CHAN
+ { "xterm", &xterm_ops },
+#else
+ { "xterm", &not_configged_ops },
+#endif
+};
+
+static struct chan *parse_chan(char *str, int pri, int device,
+ struct chan_opts *opts)
+{
+ struct chan_type *entry;
+ struct chan_ops *ops;
+ struct chan *chan;
+ void *data;
+ int i;
+
+ ops = NULL;
+ data = NULL;
+ for(i = 0; i < sizeof(chan_table)/sizeof(chan_table[0]); i++){
+ entry = &chan_table[i];
+ if(!strncmp(str, entry->key, strlen(entry->key))){
+ ops = entry->ops;
+ str += strlen(entry->key);
+ break;
+ }
+ }
+ if(ops == NULL){
+ printk(KERN_ERR "parse_chan couldn't parse \"%s\"\n",
+ str);
+ return(NULL);
+ }
+ if(ops->init == NULL) return(NULL);
+ data = (*ops->init)(str, device, opts);
+ if(data == NULL) return(NULL);
+
+ chan = kmalloc(sizeof(*chan), GFP_KERNEL);
+ if(chan == NULL) return(NULL);
+ *chan = ((struct chan) { .list = LIST_HEAD_INIT(chan->list),
+ .primary = 1,
+ .input = 0,
+ .output = 0,
+ .opened = 0,
+ .fd = -1,
+ .pri = pri,
+ .ops = ops,
+ .data = data });
+ return(chan);
+}
+
+int parse_chan_pair(char *str, struct list_head *chans, int pri, int device,
+ struct chan_opts *opts)
+{
+ struct chan *new, *chan;
+ char *in, *out;
+
+ if(!list_empty(chans)){
+ chan = list_entry(chans->next, struct chan, list);
+ if(chan->pri >= pri) return(0);
+ free_chan(chans);
+ INIT_LIST_HEAD(chans);
+ }
+
+ out = strchr(str, ',');
+ if(out != NULL){
+ in = str;
+ *out = '\0';
+ out++;
+ new = parse_chan(in, pri, device, opts);
+ if(new == NULL) return(-1);
+ new->input = 1;
+ list_add(&new->list, chans);
+
+ new = parse_chan(out, pri, device, opts);
+ if(new == NULL) return(-1);
+ list_add(&new->list, chans);
+ new->output = 1;
+ }
+ else {
+ new = parse_chan(str, pri, device, opts);
+ if(new == NULL) return(-1);
+ list_add(&new->list, chans);
+ new->input = 1;
+ new->output = 1;
+ }
+ return(0);
+}
+
+int chan_out_fd(struct list_head *chans)
+{
+ struct list_head *ele;
+ struct chan *chan;
+
+ list_for_each(ele, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(chan->primary && chan->output)
+ return(chan->fd);
+ }
+ return(-1);
+}
+
+void chan_interrupt(struct list_head *chans, struct work_struct *task,
+ struct tty_struct *tty, int irq)
+{
+ struct list_head *ele, *next;
+ struct chan *chan;
+ int err;
+ char c;
+
+ list_for_each_safe(ele, next, chans){
+ chan = list_entry(ele, struct chan, list);
+ if(!chan->input || (chan->ops->read == NULL)) continue;
+ do {
+ if((tty != NULL) &&
+ (tty->flip.count >= TTY_FLIPBUF_SIZE)){
+ schedule_work(task);
+ goto out;
+ }
+ err = chan->ops->read(chan->fd, &c, chan->data);
+ if(err > 0)
+ tty_receive_char(tty, c);
+ } while(err > 0);
+
+ if(err == 0) reactivate_fd(chan->fd, irq);
+ if(err == -EIO){
+ if(chan->primary){
+ if(tty != NULL)
+ tty_hangup(tty);
+ line_disable(tty, irq);
+ close_chan(chans);
+ free_chan(chans);
+ return;
+ }
+ else {
+ if(chan->ops->close != NULL)
+ chan->ops->close(chan->fd, chan->data);
+ free_one_chan(chan);
+ }
+ }
+ }
+ out:
+ if(tty) tty_flip_buffer_push(tty);
+}
+
+/*
+ * 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/drivers/chan_user.c b/arch/um/drivers/chan_user.c
new file mode 100644
index 00000000000..583b8e137c3
--- /dev/null
+++ b/arch/um/drivers/chan_user.c
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
+ * Licensed under the GPL
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <termios.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include "kern_util.h"
+#include "user_util.h"
+#include "chan_user.h"
+#include "user.h"
+#include "helper.h"
+#include "os.h"
+#include "choose-mode.h"
+#include "mode.h"
+
+int generic_console_write(int fd, const char *buf, int n, void *unused)
+{
+ struct termios save, new;
+ int err;
+
+ if(isatty(fd)){
+ CATCH_EINTR(err = tcgetattr(fd, &save));
+ if (err)
+ goto error;
+ new = save;
+ /* The terminal becomes a bit less raw, to handle \n also as
+ * "Carriage Return", not only as "New Line". Otherwise, the new
+ * line won't start at the first column.*/
+ new.c_oflag |= OPOST;
+ CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new));
+ if (err)
+ goto error;
+ }
+ err = generic_write(fd, buf, n, NULL);
+ /* Restore raw mode, in any case; we *must* ignore any error apart
+ * EINTR, except for debug.*/
+ if(isatty(fd))
+ CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
+ return(err);
+error:
+ return(-errno);
+}
+
+/*
+ * UML SIGWINCH handling
+ *
+ * The point of this is to handle SIGWINCH on consoles which have host ttys and
+ * relay them inside UML to whatever might be running on the console and cares
+ * about the window size (since SIGWINCH notifies about terminal size changes).
+ *
+ * So, we have a separate thread for each host tty attached to a UML device
+ * (side-issue - I'm annoyed that one thread can't have multiple controlling
+ * ttys for purposed of handling SIGWINCH, but I imagine there are other reasons
+ * that doesn't make any sense).
+ *
+ * SIGWINCH can't be received synchronously, so you have to set up to receive it
+ * as a signal. That being the case, if you are going to wait for it, it is
+ * convenient to sit in a pause() and wait for the signal to bounce you out of
+ * it (see below for how we make sure to exit only on SIGWINCH).
+ */
+
+static void winch_handler(int sig)
+{
+}
+
+struct winch_data {
+ int pty_fd;
+ int pipe_fd;
+ int close_me;
+};
+
+static int winch_thread(void *arg)
+{
+ struct winch_data *data = arg;
+ sigset_t sigs;
+ int pty_fd, pipe_fd;
+ int count, err;
+ char c = 1;
+
+ os_close_file(data->close_me);
+ pty_fd = data->pty_fd;
+ pipe_fd = data->pipe_fd;
+ count = os_write_file(pipe_fd, &c, sizeof(c));
+ if(count != sizeof(c))
+ printk("winch_thread : failed to write synchronization "
+ "byte, err = %d\n", -count);
+
+ /* We are not using SIG_IGN on purpose, so don't fix it as I thought to
+ * do! If using SIG_IGN, the pause() call below would not stop on
+ * SIGWINCH. */
+
+ signal(SIGWINCH, winch_handler);
+ sigfillset(&sigs);
+ sigdelset(&sigs, SIGWINCH);
+ /* Block anything else than SIGWINCH. */
+ if(sigprocmask(SIG_SETMASK, &sigs, NULL) < 0){
+ printk("winch_thread : sigprocmask failed, errno = %d\n",
+ errno);
+ exit(1);
+ }
+
+ if(setsid() < 0){
+ printk("winch_thread : setsid failed, errno = %d\n", errno);
+ exit(1);
+ }
+
+ err = os_new_tty_pgrp(pty_fd, os_getpid());
+ if(err < 0){
+ printk("winch_thread : new_tty_pgrp failed, err = %d\n", -err);
+ exit(1);
+ }
+
+ /* These are synchronization calls between various UML threads on the
+ * host - since they are not different kernel threads, we cannot use
+ * kernel semaphores. We don't use SysV semaphores because they are
+ * persistant. */
+ count = os_read_file(pipe_fd, &c, sizeof(c));
+ if(count != sizeof(c))
+ printk("winch_thread : failed to read synchronization byte, "
+ "err = %d\n", -count);
+
+ while(1){
+ /* This will be interrupted by SIGWINCH only, since other signals
+ * are blocked.*/
+ pause();
+
+ count = os_write_file(pipe_fd, &c, sizeof(c));
+ if(count != sizeof(c))
+ printk("winch_thread : write failed, err = %d\n",
+ -count);
+ }
+}
+
+static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out)
+{
+ struct winch_data data;
+ unsigned long stack;
+ int fds[2], pid, n, err;
+ char c;
+
+ err = os_pipe(fds, 1, 1);
+ if(err < 0){
+ printk("winch_tramp : os_pipe failed, err = %d\n", -err);
+ return(err);
+ }
+
+ data = ((struct winch_data) { .pty_fd = fd,
+ .pipe_fd = fds[1],
+ .close_me = fds[0] } );
+ pid = run_helper_thread(winch_thread, &data, 0, &stack, 0);
+ if(pid < 0){
+ printk("fork of winch_thread failed - errno = %d\n", errno);
+ return(pid);
+ }
+
+ os_close_file(fds[1]);
+ *fd_out = fds[0];
+ n = os_read_file(fds[0], &c, sizeof(c));
+ if(n != sizeof(c)){
+ printk("winch_tramp : failed to read synchronization byte\n");
+ printk("read failed, err = %d\n", -n);
+ printk("fd %d will not support SIGWINCH\n", fd);
+ *fd_out = -1;
+ }
+ return(pid);
+}
+
+void register_winch(int fd, struct tty_struct *tty)
+{
+ int pid, thread, thread_fd;
+ int count;
+ char c = 1;
+
+ if(!isatty(fd))
+ return;
+
+ pid = tcgetpgrp(fd);
+ if(!CHOOSE_MODE_PROC(is_tracer_winch, is_skas_winch, pid, fd,
+ tty) && (pid == -1)){
+ thread = winch_tramp(fd, tty, &thread_fd);
+ if(fd != -1){
+ register_winch_irq(thread_fd, fd, thread, tty);
+
+ count = os_write_file(thread_fd, &c, sizeof(c));