patch-2.1.51 linux/arch/ppc/kernel/syscalls.c

Next file: linux/arch/ppc/kernel/time.c
Previous file: linux/arch/ppc/kernel/strcase.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.50/linux/arch/ppc/kernel/syscalls.c linux/arch/ppc/kernel/syscalls.c
@@ -1,15 +1,25 @@
 /*
  * linux/arch/ppc/kernel/sys_ppc.c
  *
+ *  PowerPC version 
+ *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
+ *
+ * Derived from "arch/i386/kernel/sys_i386.c"
  * Adapted from the i386 version by Gary Thomas
  * Modified by Cort Dougan (cort@cs.nmt.edu)
+ * and Paul Mackerras (paulus@cs.anu.edu.au).
  *
  * This file contains various random system calls that
  * have a non-standard calling sequence on the Linux/PPC
  * platform.
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version
+ *  2 of the License, or (at your option) any later version.
+ *
  */
 
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
@@ -20,11 +30,11 @@
 #include <linux/shm.h>
 #include <linux/stat.h>
 #include <linux/mman.h>
+#include <linux/sys.h>
 #include <linux/ipc.h>
 #include <asm/uaccess.h>
 #include <asm/ipc.h>
 
-
 void
 check_bugs(void)
 {
@@ -32,32 +42,32 @@
 
 asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int on)
 {
-	printk("sys_ioperm()\n");
+	printk(KERN_ERR "sys_ioperm()\n");
 	return -EIO;
 }
 
 int sys_iopl(int a1, int a2, int a3, int a4)
 {
 	lock_kernel();
-	printk( "sys_iopl(%x, %x, %x, %x)!\n", a1, a2, a3, a4);
+	printk(KERN_ERR "sys_iopl(%x, %x, %x, %x)!\n", a1, a2, a3, a4);
 	unlock_kernel();
-	return (ENOSYS);
+	return (-ENOSYS);
 }
 
 int sys_vm86(int a1, int a2, int a3, int a4)
 {
 	lock_kernel();
-	printk( "sys_vm86(%x, %x, %x, %x)!\n", a1, a2, a3, a4);
+	printk(KERN_ERR "sys_vm86(%x, %x, %x, %x)!\n", a1, a2, a3, a4);
 	unlock_kernel();
-	return (ENOSYS);
+	return (-ENOSYS);
 }
 
 int sys_modify_ldt(int a1, int a2, int a3, int a4)
 {
 	lock_kernel();
-	printk( "sys_modify_ldt(%x, %x, %x, %x)!\n", a1, a2, a3, a4);
+	printk(KERN_ERR "sys_modify_ldt(%x, %x, %x, %x)!\n", a1, a2, a3, a4);
 	unlock_kernel();
-	return (ENOSYS);
+	return (-ENOSYS);
 }
 
 /*
@@ -65,7 +75,8 @@
  *
  * This is really horribly ugly.
  */
-asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
+asmlinkage int 
+sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
 {
 	int version, ret;
 
@@ -73,138 +84,113 @@
 	version = call >> 16; /* hack for backward compatibility */
 	call &= 0xffff;
 
-	if (call <= SEMCTL)
-		switch (call) {
-		case SEMOP:
-			ret = sys_semop (first, (struct sembuf *)ptr, second);
-			goto out;
-		case SEMGET:
-			ret = sys_semget (first, second, third);
-			goto out;
-		case SEMCTL: {
-			union semun fourth;
-			ret = -EINVAL;
-			if (!ptr)
-				goto out;
-			ret = -EFAULT;
-			if (get_user(fourth.__pad, (void **) ptr))
-				goto out;	
-			ret = sys_semctl (first, second, third, fourth);
-			goto out;
-		}
-		default:
-			ret = -EINVAL;
-			goto out;
+	ret = -EINVAL;
+	switch (call) {
+	case SEMOP:
+		ret = sys_semop (first, (struct sembuf *)ptr, second);
+		break;
+	case SEMGET:
+		ret = sys_semget (first, second, third);
+		break;
+	case SEMCTL: {
+		union semun fourth;
+
+		if (!ptr)
+			break;
+		if ((ret = verify_area (VERIFY_READ, ptr, sizeof(long)))
+		    || (ret = get_user(fourth.__pad, (void **)ptr)))
+			break;
+		ret = sys_semctl (first, second, third, fourth);
+		break;
 		}
-	if (call <= MSGCTL) 
-		switch (call) {
-		case MSGSND:
-			ret = sys_msgsnd (first, (struct msgbuf *) ptr, 
-					  second, third);
-			goto out;
-		case MSGRCV:
-			switch (version) {
-			case 0: {
-				struct ipc_kludge tmp;
-				ret = -EINVAL;
-				if (!ptr)
-					goto out;
-				ret = -EFAULT;
-				if (copy_from_user(&tmp,(struct ipc_kludge *) ptr, 
-						   sizeof (tmp)))
-					goto out; 	
-				ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
-				goto out;
-			}
-			case 1: default:
-				ret = sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
-				goto out;
+	case MSGSND:
+		ret = sys_msgsnd (first, (struct msgbuf *) ptr, second, third);
+		break;
+	case MSGRCV:
+		switch (version) {
+		case 0: {
+			struct ipc_kludge tmp;
+
+			if (!ptr)
+				break;
+			if ((ret = verify_area (VERIFY_READ, ptr, sizeof(tmp)))
+			    || (ret = copy_from_user(&tmp,
+						(struct ipc_kludge *) ptr,
+						sizeof (tmp))))
+				break;
+			ret = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
+					  third);
+			break;
 			}
-		case MSGGET:
-			ret = sys_msgget ((key_t) first, second);
-			goto out;
-		case MSGCTL:
-			ret = sys_msgctl (first, second, (struct msqid_ds *) ptr);
-			goto out;
 		default:
-			ret = -EINVAL;
-			goto out;
+			ret = sys_msgrcv (first, (struct msgbuf *) ptr,
+					  second, fifth, third);
+			break;
 		}
-	if (call <= SHMCTL) 
-		switch (call) {
-		case SHMAT:
-			switch (version) {
-			case 0: default: {
-				ulong raddr;
-				ret = sys_shmat (first, (char *) ptr, second, &raddr);
-				if (ret)
-					goto out;
-				ret = put_user (raddr, (ulong *) third);
-				goto out;
+		break;
+	case MSGGET:
+		ret = sys_msgget ((key_t) first, second);
+		break;
+	case MSGCTL:
+		ret = sys_msgctl (first, second, (struct msqid_ds *) ptr);
+		break;
+	case SHMAT:
+		switch (version) {
+		default: {
+			ulong raddr;
+
+			if ((ret = verify_area(VERIFY_WRITE, (ulong*) third,
+					       sizeof(ulong))))
+				break;
+			ret = sys_shmat (first, (char *) ptr, second, &raddr);
+			if (ret)
+				break;
+			ret = put_user (raddr, (ulong *) third);
+			break;
 			}
-			case 1:	/* iBCS2 emulator entry point */
-				ret = -EINVAL;
-				if (get_fs() != get_ds())
-					goto out;
-				ret = sys_shmat (first, (char *) ptr, second, (ulong *) third);
-				goto out;
-			}
-		case SHMDT: 
-			ret = sys_shmdt ((char *)ptr);
-			goto out;
-		case SHMGET:
-			ret = sys_shmget (first, second, third);
-			goto out;
-		case SHMCTL:
-			ret = sys_shmctl (first, second, (struct shmid_ds *) ptr);
-			goto out;
-		default:
-			ret = -EINVAL;
-			goto out;
+		case 1:	/* iBCS2 emulator entry point */
+			if (get_fs() != get_ds())
+				break;
+			ret = sys_shmat (first, (char *) ptr, second,
+					 (ulong *) third);
+			break;
 		}
-	else
-		ret = -EINVAL;
-out:
-	unlock_kernel();
-	return ret;
-}
-
+		break;
+	case SHMDT: 
+		ret = sys_shmdt ((char *)ptr);
+		break;
+	case SHMGET:
+		ret = sys_shmget (first, second, third);
+		break;
+	case SHMCTL:
+		ret = sys_shmctl (first, second, (struct shmid_ds *) ptr);
+		break;
+	}
 
-#ifndef CONFIG_MODULES
-void
-scsi_register_module(void)
-{
-	lock_kernel();
-	panic("scsi_register_module");
-	unlock_kernel();
-}
-
-void
-scsi_unregister_module(void)
-{
-	lock_kernel();
-	panic("scsi_unregister_module");
 	unlock_kernel();
+	return ret;
 }
-#endif
 
 /*
  * sys_pipe() is the normal C calling standard for creating
  * a pipe. It's not the way unix traditionally does this, though.
  */
-asmlinkage int sys_pipe(unsigned long * fildes)
+asmlinkage int sys_pipe(int *fildes)
 {
 	int fd[2];
 	int error;
 
-	error = verify_area(VERIFY_WRITE,fildes,8);
+	error = verify_area(VERIFY_WRITE, fildes, 8);
 	if (error)
 		return error;
+	lock_kernel();
 	error = do_pipe(fd);
+	unlock_kernel();
 	if (error)
 		return error;
-	put_user(fd[0],0+fildes);
-	put_user(fd[1],1+fildes);
+	if (__put_user(fd[0],0+fildes)
+	    || __put_user(fd[1],1+fildes))
+		return -EFAULT;	/* should we close the fds? */
 	return 0;
 }
 
@@ -213,13 +199,18 @@
 				  unsigned long fd, off_t offset)
 {
 	struct file * file = NULL;
+	int ret = -EBADF;
+
+	lock_kernel();
 	if (!(flags & MAP_ANONYMOUS)) {
 		if (fd >= NR_OPEN || !(file = current->files->fd[fd]))
-			return -EBADF;
+			goto out;
 	}
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
-
-	return do_mmap(file, addr, len, prot, flags, offset);
+	ret = do_mmap(file, addr, len, prot, flags, offset);
+out:
+	unlock_kernel();
+	return ret;
 }
 
 extern asmlinkage int sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
@@ -233,15 +224,15 @@
 asmlinkage int 
 ppc_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval *tvp)
 {
-	int err;
 	if ( (unsigned long)n >= 4096 )
 	{
 		unsigned long *buffer = (unsigned long *)n;
-		if ( get_user(n, buffer) ||
-		     get_user(inp,buffer+1) ||
-		     get_user(outp,buffer+2) ||
-		     get_user(exp,buffer+3) ||
-		     get_user(tvp,buffer+4) )
+		if (verify_area(VERIFY_READ, buffer, 5*sizeof(unsigned long))
+		    || __get_user(n, buffer)
+		    || __get_user(inp, ((fd_set **)(buffer+1)))
+		    || __get_user(outp, ((fd_set **)(buffer+2)))
+		    || __get_user(exp, ((fd_set **)(buffer+3)))
+		    || __get_user(tvp, ((struct timeval **)(buffer+4))))
 			return -EFAULT;
 	}
 	return sys_select(n, inp, outp, exp, tvp);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov