From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <199610160022.TAA24271@atheist.tamu.edu> Date: Tue, 15 Oct 1996 19:22:46 -0500 (CDT) From: Richard Henderson Subject: 2.1.4 exception question I am aware that quite a bit was hashed about on linux-kernel recently, but to clarify, I'm wondering about the implementation of read/write as they exist in 2.1.4. I take as my example the routines from drivers/char/mem.c. As it stands, copy_{to,from}_user correctly trap the exception, but the surrounding code does nothing with the status returned from those functions. According to my understanding of the recent discussion, the appended patch is required to make the code correct. Specifically, it actually tests the return values and returns the amount actually written. Is this indeed correct? Should this pattern be replicated to the other drivers? What about bits like those in, e.g., arch/alpha/kernel/osf_sys.c osf_filldir() that similarly assume that the entire buffer is valid, and blithely attempts to fill it all despite the fact that it generates oodles of exceptions? Or, on a slightly different tack, sys_newstat that never returns an error. Or the set_termios bits which don't recognize that the copy_from_user failed. True, POSIX says we needn't reliably report such errors, but is this what _we_ want in this situation? Just wondering what the Official Position on these issues are before doing wholesale changes. r~ *** mem.c.orig Tue Oct 15 18:42:40 1996 --- mem.c Tue Oct 15 18:51:59 1996 *************** static long read_mem(struct inode * inod *** 51,57 **** { unsigned long p = file->f_pos; unsigned long end_mem; ! int read; if (count < 0) return -EINVAL; --- 51,57 ---- { unsigned long p = file->f_pos; unsigned long end_mem; ! long read; if (count < 0) return -EINVAL; *************** static long read_mem(struct inode * inod *** 60,79 **** return 0; if (count > end_mem - p) count = end_mem - p; read = 0; #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */ ! while (p < PAGE_SIZE && count > 0) { ! put_user(0,buf); buf++; p++; - count--; read++; } #endif ! copy_to_user(buf, __va(p), count); ! read += count; file->f_pos += read; ! return read; } static long write_mem(struct inode * inode, struct file * file, --- 60,81 ---- return 0; if (count > end_mem - p) count = end_mem - p; + read = 0; #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */ ! while (p < PAGE_SIZE && read < count) { ! if (put_user(0,buf)) ! goto error; buf++; p++; read++; } #endif ! read += count - copy_to_user(buf, __va(p), count); ! ! error: file->f_pos += read; ! return read || !count ? read : -EFAULT; } static long write_mem(struct inode * inode, struct file * file, *************** static long write_mem(struct inode * ino *** 81,87 **** { unsigned long p = file->f_pos; unsigned long end_mem; ! int written; if (count < 0) return -EINVAL; --- 83,89 ---- { unsigned long p = file->f_pos; unsigned long end_mem; ! long written; if (count < 0) return -EINVAL; *************** static long write_mem(struct inode * ino *** 90,109 **** return 0; if (count > end_mem - p) count = end_mem - p; written = 0; #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */ ! while (p < PAGE_SIZE && count > 0) { /* Hmm. Do something? */ buf++; p++; - count--; written++; } #endif ! copy_from_user(__va(p), buf, count); ! written += count; file->f_pos += written; ! return count; } static int mmap_mem(struct inode * inode, struct file * file, struct vm_area_struct * vma) --- 92,111 ---- return 0; if (count > end_mem - p) count = end_mem - p; + written = 0; #if defined(__sparc__) /* we don't have page 0 mapped on sparc.. */ ! while (p < PAGE_SIZE && written < count) { /* Hmm. Do something? */ buf++; p++; written++; } #endif ! written += count - copy_from_user(__va(p), buf, count); ! file->f_pos += written; ! return written || !count ? written : -EFAULT; } static int mmap_mem(struct inode * inode, struct file * file, struct vm_area_struct * vma) -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null