Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 24231
b: refs/heads/master
c: 8e36706
h: refs/heads/master
i:
  24229: 1d85a19
  24227: cf1c1ac
  24223: 55326a7
v: v3
  • Loading branch information
Jeff Dike authored and Linus Torvalds committed Mar 27, 2006
1 parent 93fe75f commit 5892158
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 158 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9b4f018d92dbeff9305b4cf4aa80874c3974cfcc
refs/heads/master: 8e367065eea04a6fde5cb8f3854164af99c45693
1 change: 1 addition & 0 deletions trunk/arch/um/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extern int os_lock_file(int fd, int excl);
/* start_up.c */
extern void os_early_checks(void);
extern int can_do_skas(void);
extern void os_check_bugs(void);

/* Make sure they are clear when running in TT mode. Required by
* SEGV_MAYBE_FIXABLE */
Expand Down
1 change: 0 additions & 1 deletion trunk/arch/um/include/sigio.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

extern int write_sigio_irq(int fd);
extern int register_sigio_fd(int fd);
extern int read_sigio_fd(int fd);
extern int add_sigio_fd(int fd, int read);
extern int ignore_sigio_fd(int fd);
extern void sigio_lock(void);
Expand Down
10 changes: 8 additions & 2 deletions trunk/arch/um/kernel/sigio_kern.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
* Licensed under the GPL
*/
Expand All @@ -12,13 +12,16 @@
#include "sigio.h"
#include "irq_user.h"
#include "irq_kern.h"
#include "os.h"

/* Protected by sigio_lock() called from write_sigio_workaround */
static int sigio_irq_fd = -1;

static irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused)
{
read_sigio_fd(sigio_irq_fd);
char c;

os_read_file(sigio_irq_fd, &c, sizeof(c));
reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ);
return(IRQ_HANDLED);
}
Expand Down Expand Up @@ -51,6 +54,9 @@ void sigio_unlock(void)
spin_unlock(&sigio_spinlock);
}

extern void sigio_cleanup(void);
__uml_exitcall(sigio_cleanup);

/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
Expand Down
162 changes: 10 additions & 152 deletions trunk/arch/um/kernel/sigio_user.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
Expand All @@ -20,127 +20,6 @@
#include "sigio.h"
#include "os.h"

/* 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;

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;
}

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);

os_close_file(master);
os_close_file(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...");

os_close_file(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);
}

/* Protected by sigio_lock(), also used by sigio_cleanup, which is an
* exitcall.
*/
Expand Down Expand Up @@ -267,10 +146,10 @@ static void update_thread(void)
if(write_sigio_pid != -1)
os_kill_process(write_sigio_pid, 1);
write_sigio_pid = -1;
os_close_file(sigio_private[0]);
os_close_file(sigio_private[1]);
os_close_file(write_sigio_fds[0]);
os_close_file(write_sigio_fds[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);
}
Expand Down Expand Up @@ -428,39 +307,18 @@ void write_sigio_workaround(void)
out_free:
kfree(p);
out_close2:
os_close_file(l_sigio_private[0]);
os_close_file(l_sigio_private[1]);
close(l_sigio_private[0]);
close(l_sigio_private[1]);
out_close1:
os_close_file(l_write_sigio_fds[0]);
os_close_file(l_write_sigio_fds[1]);
close(l_write_sigio_fds[0]);
close(l_write_sigio_fds[1]);
return;
}

int read_sigio_fd(int fd)
{
int n;
char c;

n = os_read_file(fd, &c, sizeof(c));
if(n != sizeof(c)){
if(n < 0) {
printk("read_sigio_fd - read failed, err = %d\n", -n);
return(n);
}
else {
printk("read_sigio_fd - short read, bytes = %d\n", n);
return(-EIO);
}
}
return(n);
}

static void sigio_cleanup(void)
void sigio_cleanup(void)
{
if (write_sigio_pid != -1) {
os_kill_process(write_sigio_pid, 1);
write_sigio_pid = -1;
}
}

__uml_exitcall(sigio_cleanup);
3 changes: 1 addition & 2 deletions trunk/arch/um/kernel/um_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ void __init setup_arch(char **cmdline_p)
void __init check_bugs(void)
{
arch_check_bugs();
check_sigio();
check_devanon();
os_check_bugs();
}

void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
Expand Down
128 changes: 128 additions & 0 deletions trunk/arch/um/os-Linux/start_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the GPL
*/

#include <pty.h>
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
Expand Down Expand Up @@ -539,3 +540,130 @@ 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();
check_devanon();
}

0 comments on commit 5892158

Please sign in to comment.