[PATCH] New phys_addr() syscall

Richard.Gooch@atnf.csiro.au
Sun, 19 Jul 1998 15:53:24 +1000


Hi, all. I've implemented a simple new system call called
phys_addr() which converts a virtual address to a physical
address. This is useful for memory testing programmes so you can find
out which SIMM/DIMM is causing trouble (yeah, I've got intermittent
memory problems in one of my machines, and I want to nail the bugger).
Sure, I know about memtest86, but it doesn't seem to find the problem,
whereas my userspace tester does.

People writing pure userspace network drivers may also find this handy
if they want to DMA directly into userspace.

I've only bothered with ix86 syscalls for now. Comments welcome. Patch
against 2.1.109 below.

Regards,

Richard....

diff -urN linux-2.1.109/arch/i386/kernel/entry.S linux/arch/i386/kernel/entry.S
--- linux-2.1.109/arch/i386/kernel/entry.S Sat Jul 18 23:41:30 1998
+++ linux/arch/i386/kernel/entry.S Sun Jul 19 11:56:53 1998
@@ -561,7 +561,8 @@
.long SYMBOL_NAME(sys_capset) /* 185 */
.long SYMBOL_NAME(sys_sigaltstack)
.long SYMBOL_NAME(sys_sendfile)
+ .long SYMBOL_NAME(sys_phys_addr)

- .rept NR_syscalls-187
+ .rept NR_syscalls-188
.long SYMBOL_NAME(sys_ni_syscall)
.endr
diff -urN linux-2.1.109/include/asm-i386/unistd.h linux/include/asm-i386/unistd.h
--- linux-2.1.109/include/asm-i386/unistd.h Thu Jul 2 13:02:21 1998
+++ linux/include/asm-i386/unistd.h Sun Jul 19 11:28:45 1998
@@ -193,6 +193,7 @@
#define __NR_capset 185
#define __NR_sigaltstack 186
#define __NR_sendfile 187
+#define __NR_phys_addr 188

/* user-visible error numbers are in the range -1 - -122: see <asm-i386/errno.h> */

diff -urN linux-2.1.109/kernel/sys.c linux/kernel/sys.c
--- linux-2.1.109/kernel/sys.c Thu Jun 25 16:38:00 1998
+++ linux/kernel/sys.c Sun Jul 19 13:10:49 1998
@@ -27,6 +27,7 @@

#include <asm/uaccess.h>
#include <asm/io.h>
+#include <asm/page.h>

/*
* this indicates whether you can reboot with ctrl-alt-del: the default is yes
@@ -992,7 +993,7 @@
mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
return mask;
}
-
+
asmlinkage int sys_prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5)
{
@@ -1015,3 +1016,17 @@
return error;
}

+asmlinkage int sys_phys_addr(unsigned long *address)
+{
+ int error = 0;
+ unsigned long addr;
+ pte_t *pte;
+
+ error = copy_from_user (&addr, address, sizeof addr);
+ if (error < 0) return error;
+ pte = pte_offset (pmd_offset (pgd_offset (current->mm, addr), addr),
+ addr);
+ if ( !pte_present (*pte) ) return -EINVAL;
+ addr = __pa (pte_page (*pte)) + (addr & (PAGE_SIZE-1));
+ return copy_to_user (address, &addr, sizeof addr) ? -EFAULT : 0;
+}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html