Commit e46b25f0 authored by Jeff Dike's avatar Jeff Dike

Forward ported a bunch of cleanups from 2.4. Improved error messages,

slightly different formatting, removal of dead code, and some stray
C99 initializer conversions.
parent 6cc944b6
......@@ -35,7 +35,7 @@ void line_timer_cb(void *arg)
line_interrupt(dev->driver->read_irq, dev, NULL);
}
void buffer_data(struct line *line, const char *buf, int len)
static void buffer_data(struct line *line, const char *buf, int len)
{
int end;
......
......@@ -31,9 +31,8 @@ struct port_list {
struct port_dev {
struct port_list *port;
int fd;
int helper_pid;
int telnetd_pid;
int helper_pid;
int telnetd_pid;
};
struct connection {
......@@ -55,7 +54,8 @@ static void pipe_interrupt(int irq, void *data, struct pt_regs *regs)
if(fd == -EAGAIN)
return;
printk("os_rcv_fd returned %d\n", -fd);
printk(KERN_ERR "pipe_interrupt : os_rcv_fd returned %d\n",
-fd);
os_close_file(conn->fd);
}
......@@ -75,26 +75,29 @@ static int port_accept(struct port_list *port)
fd = port_connection(port->fd, socket, &pid);
if(fd < 0){
if(fd != -EAGAIN)
printk("port_connection returned %d\n", -fd);
printk(KERN_ERR "port_accept : port_connection "
"returned %d\n", -fd);
goto out;
}
conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
if(conn == NULL){
printk("port_interrupt : failed to allocate connection\n");
printk(KERN_ERR "port_accept : failed to allocate "
"connection\n");
goto out_close;
}
*conn = ((struct connection)
{ list : LIST_HEAD_INIT(conn->list),
fd : fd,
socket : { socket[0], socket[1] },
telnetd_pid : pid,
port : port });
{ .list = LIST_HEAD_INIT(conn->list),
.fd = fd,
.socket = { socket[0], socket[1] },
.telnetd_pid = pid,
.port = port });
if(um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
"telnetd", conn)){
printk(KERN_ERR "Failed to get IRQ for telnetd\n");
printk(KERN_ERR "port_accept : failed to get IRQ for "
"telnetd\n");
goto out_free;
}
......@@ -106,7 +109,8 @@ static int port_accept(struct port_list *port)
kfree(conn);
out_close:
os_close_file(fd);
if(pid != -1) os_kill_process(pid, 0);
if(pid != -1)
os_kill_process(pid, 0);
out:
return(ret);
}
......@@ -205,38 +209,16 @@ void *port_data(int port_num)
return(dev);
}
void port_remove_dev(void *d)
{
struct port_dev *dev = d;
if(dev->helper_pid != -1)
os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1)
os_kill_process(dev->telnetd_pid, 0);
dev->helper_pid = -1;
}
static void free_port(void)
{
struct list_head *ele;
struct port_list *port;
list_for_each(ele, &ports){
port = list_entry(ele, struct port_list, list);
os_close_file(port->fd);
}
}
__uml_exitcall(free_port);
int port_wait(void *data)
{
struct port_dev *dev = data;
struct connection *conn;
struct port_list *port = dev->port;
int fd;
while(1){
if(down_interruptible(&port->sem)) return(-ERESTARTSYS);
if(down_interruptible(&port->sem))
return(-ERESTARTSYS);
spin_lock(&port->lock);
......@@ -263,23 +245,48 @@ int port_wait(void *data)
kfree(conn);
}
dev->fd = conn->fd;
fd = conn->fd;
dev->helper_pid = conn->helper_pid;
dev->telnetd_pid = conn->telnetd_pid;
kfree(conn);
return(dev->fd);
return(fd);
}
void port_remove_dev(void *d)
{
struct port_dev *dev = d;
if(dev->helper_pid != -1)
os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1)
os_kill_process(dev->telnetd_pid, 0);
dev->helper_pid = -1;
dev->telnetd_pid = -1;
}
void port_kern_free(void *d)
{
struct port_dev *dev = d;
if(dev->helper_pid != -1) os_kill_process(dev->telnetd_pid, 0);
if(dev->telnetd_pid != -1) os_kill_process(dev->telnetd_pid, 0);
port_remove_dev(dev);
kfree(dev);
}
static void free_port(void)
{
struct list_head *ele;
struct port_list *port;
list_for_each(ele, &ports){
port = list_entry(ele, struct port_list, list);
free_irq_by_fd(port->fd);
os_close_file(port->fd);
}
}
__uml_exitcall(free_port);
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
......
......@@ -47,14 +47,28 @@ void *port_init(char *str, int device, struct chan_opts *opts)
return(NULL);
}
if((kern_data = port_data(port)) == NULL) return(NULL);
if((kern_data = port_data(port)) == NULL)
return(NULL);
if((data = um_kmalloc(sizeof(*data))) == NULL)
goto err;
if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL);
*data = ((struct port_chan) { raw : opts->raw,
kernel_data : kern_data });
*data = ((struct port_chan) { .raw = opts->raw,
.kernel_data = kern_data });
sprintf(data->dev, "%d", port);
return(data);
err:
port_kern_free(kern_data);
return(NULL);
}
void port_free(void *d)
{
struct port_chan *data = d;
port_kern_free(data->kernel_data);
kfree(data);
}
int port_open(int input, int output, int primary, void *d, char **dev_out)
......@@ -86,25 +100,17 @@ int port_console_write(int fd, const char *buf, int n, void *d)
return(generic_console_write(fd, buf, n, &data->tt));
}
void port_free(void *d)
{
struct port_chan *data = d;
port_kern_free(data->kernel_data);
kfree(data);
}
struct chan_ops port_ops = {
type: "port",
init: port_init,
open: port_open,
close: port_close,
read: generic_read,
write: generic_write,
console_write: port_console_write,
window_size: generic_window_size,
free: port_free,
winch: 1,
.type = "port",
.init = port_init,
.open = port_open,
.close = port_close,
.read = generic_read,
.write = generic_write,
.console_write = port_console_write,
.window_size = generic_window_size,
.free = port_free,
.winch = 1,
};
int port_listen_fd(int port)
......@@ -113,7 +119,8 @@ int port_listen_fd(int port)
int fd, err;
fd = socket(PF_INET, SOCK_STREAM, 0);
if(fd == -1) return(-errno);
if(fd == -1)
return(-errno);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
......@@ -163,14 +170,16 @@ int port_connection(int fd, int *socket, int *pid_out)
return(-errno);
err = os_pipe(socket, 0, 0);
if(err) goto out_close;
if(err)
goto out_close;
data = ((struct port_pre_exec_data)
{ sock_fd : new,
pipe_fd : socket[1] });
{ .sock_fd = new,
.pipe_fd = socket[1] });
err = run_helper(port_pre_exec, &data, argv, NULL);
if(err < 0) goto out_shutdown;
if(err < 0)
goto out_shutdown;
*pid_out = err;
return(new);
......
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
......@@ -86,34 +86,15 @@ int getmaster(char *line)
return(-1);
}
struct grantpt_info {
int fd;
int res;
int err;
};
static void grantpt_cb(void *arg)
{
struct grantpt_info *info = arg;
info->res = grantpt(info->fd);
info->err = errno;
}
int pty_open(int input, int output, int primary, void *d, char **dev_out)
{
struct pty_chan *data = d;
int fd;
char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx";
struct grantpt_info info;
fd = getmaster(dev);
if(fd < 0) return(-errno);
info.fd = fd;
initial_thread_cb(grantpt_cb, &info);
unlockpt(fd);
if(data->raw) raw(fd, 0);
if(data->announce) (*data->announce)(dev, data->dev);
......
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SIGNAL_KERN_H__
#define __SIGNAL_KERN_H__
#include "sysdep/ptrace.h"
extern void signal_deliverer(int sig);
extern int probe_stack(unsigned long sp, int delta);
extern int have_signals(void *t);
#endif
......
......@@ -3,8 +3,13 @@
* Licensed under the GPL
*/
#ifndef __UMID_H__
#define __UMID_H__
extern int umid_file_name(char *name, char *buf, int len);
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
......
......@@ -78,7 +78,8 @@ static int capture_stack(int (*child)(void *arg), void *arg, void *sp,
/* It has outlived its usefulness, so continue it so it can exit */
if(ptrace(PTRACE_CONT, pid, 0, 0) < 0){
printf("capture_stack : mmap failed - errno = %d\n", errno);
printf("capture_stack : PTRACE_CONT failed - errno = %d\n",
errno);
exit(1);
}
if(waitpid(pid, &status, 0) < 0){
......
......@@ -14,6 +14,7 @@
#include "asm/processor.h"
#include "asm/unistd.h"
#include "asm/pgalloc.h"
#include "asm/pgtable.h"
#include "asm/page.h"
#include "asm/tlbflush.h"
#include "kern_util.h"
......@@ -42,7 +43,11 @@ EXPORT_SYMBOL(page_to_phys);
EXPORT_SYMBOL(phys_to_page);
EXPORT_SYMBOL(high_physmem);
EXPORT_SYMBOL(empty_zero_page);
EXPORT_SYMBOL(um_virt_to_phys);
EXPORT_SYMBOL(mode_tt);
EXPORT_SYMBOL(handle_page_fault);
EXPORT_SYMBOL(os_getpid);
EXPORT_SYMBOL(os_open_file);
EXPORT_SYMBOL(os_read_file);
EXPORT_SYMBOL(os_write_file);
......
......@@ -420,7 +420,8 @@ int read_sigio_fd(int fd)
static void sigio_cleanup(void)
{
if(write_sigio_pid != -1) kill(write_sigio_pid, SIGKILL);
if(write_sigio_pid != -1)
kill(write_sigio_pid, SIGKILL);
}
__uml_exitcall(sigio_cleanup);
......
......@@ -29,18 +29,6 @@
EXPORT_SYMBOL(block_signals);
EXPORT_SYMBOL(unblock_signals);
int probe_stack(unsigned long sp, int delta)
{
int n;
if((get_user(n, (int *) sp) != 0) ||
(put_user(n, (int *) sp) != 0) ||
(get_user(n, (int *) (sp - delta)) != 0) ||
(put_user(n, (int *) (sp - delta)) != 0))
return(-EFAULT);
return(0);
}
static void force_segv(int sig)
{
if(sig == SIGSEGV){
......
......@@ -27,9 +27,6 @@ static inline int verify_area_skas(int type, const void * addr,
return(access_ok_skas(type, addr, size) ? 0 : -EFAULT);
}
extern void *um_virt_to_phys(struct task_struct *task, unsigned long virt,
pte_t *pte_out);
static inline unsigned long maybe_map(unsigned long virt, int is_write)
{
pte_t pte;
......
......@@ -99,7 +99,6 @@ static void flush_kernel_vm_range(unsigned long start, unsigned long end)
protect_memory(addr, PAGE_SIZE, 1, 1, 1, 1);
}
addr += PAGE_SIZE;
}
else {
if(pmd_newpage(*pmd)){
......
......@@ -108,7 +108,7 @@ void idle_sleep(int secs)
ts.tv_sec = secs;
ts.tv_nsec = 0;
nanosleep(&ts, &ts);
nanosleep(&ts, NULL);
}
/*
......
......@@ -109,7 +109,8 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
flush_tlb_kernel_vm();
return(0);
}
if(current->mm == NULL) panic("Segfault with no mm");
if(current->mm == NULL)
panic("Segfault with no mm");
err = handle_page_fault(address, ip, is_write, is_user, &si.si_code);
catcher = current->thread.fault_catcher;
......
......@@ -13,9 +13,9 @@ extern int gdb_config(char *str);
extern int gdb_remove(char *unused);
static struct mc_device gdb_mc = {
name: "gdb",
config: gdb_config,
remove: gdb_remove,
.name = "gdb",
.config = gdb_config,
.remove = gdb_remove,
};
int gdb_mc_init(void)
......
......@@ -317,6 +317,11 @@ int linux_main(int argc, char **argv)
if(physmem_size > max_physmem){
highmem = physmem_size - max_physmem;
physmem_size -= highmem;
#ifndef CONFIG_HIGHMEM
highmem = 0;
printf("CONFIG_HIGHMEM not enabled - physical memory shrunk "
"to %ld bytes\n", physmem_size);
#endif
}
high_physmem = uml_physmem + physmem_size;
......
......@@ -186,7 +186,6 @@ int not_dead_yet(char *dir)
}
if(!dead) return(1);
return(actually_do_remove(dir));
return(0);
}
static int __init set_uml_dir(char *name, int *add)
......
......@@ -9,6 +9,7 @@ USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o
USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
SYMLINKS = semaphore.c extable.c highmem.c module.c
SYMLINKS := $(foreach f,$(SYMLINKS),$(src)/$f)
semaphore.c-dir = kernel
extable.c-dir = mm
......@@ -23,7 +24,7 @@ endef
$(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
$(foreach f,$(SYMLINKS),$(src)/$f):
$(SYMLINKS):
$(call make_link,$@)
clean:
......
......@@ -14,6 +14,9 @@
extern pgd_t swapper_pg_dir[1024];
extern void *um_virt_to_phys(struct task_struct *task, unsigned long virt,
pte_t *pte_out);
/* zero page used for uninitialized stuff */
extern unsigned long *empty_zero_page;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment