*
*/
#include <afsconfig.h>
-#include "../afs/param.h"
+#include "afs/param.h"
RCSID("$Header$");
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
-#include "../h/unistd.h" /* For syscall numbers. */
-#include "../h/mm.h"
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
+#include "h/unistd.h" /* For syscall numbers. */
+#include "h/mm.h"
#include <linux/module.h>
#include <linux/slab.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
#include <linux/init.h>
+#include <linux/sched.h>
+#endif
+#ifndef EXPORTED_SYS_CALL_TABLE
+#include <linux/syscall.h>
#endif
#endif
asmlinkage int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz);
-#if !defined(AFS_ALPHA_LINUX20_ENV)
-asmlinkage int (*sys_socketcallp)(int call, long *args);
-#endif /* no socketcall on alpha */
-asmlinkage int (*sys_killp)(int pid, int signal);
asmlinkage long (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist);
+#ifdef EXPORTED_SYS_CALL_TABLE
#ifdef AFS_SPARC64_LINUX20_ENV
extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */
#else
extern void * sys_call_table[]; /* safer for other linuces */
#endif
+#else /* EXPORTED_SYS_CALL_TABLE */
+#ifdef AFS_SPARC64_LINUX20_ENV
+static unsigned int *sys_call_table; /* changed to uint because SPARC64 has syscaltable of 32bit items */
+#else
+static void ** sys_call_table; /* safer for other linuces */
+#endif
+#endif
extern struct file_system_type afs_file_system;
static long get_page_offset(void);
#if defined(__NR_setgroups32)
asmlinkage int (*sys32_setgroups32p)(int gidsetsize, __kernel_gid_t32 *grouplist);
#endif
+#ifdef EXPORTED_SYS_CALL_TABLE
extern unsigned int sys_call_table32[];
+#else
+static unsigned int *sys_call_table32;
+#endif
asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3,
long parm4, long parm5)
{
-__asm__ __volatile__ ("
- srl %o4, 0, %o4
- mov %o7, %i7
- call afs_syscall
- srl %o5, 0, %o5
- ret
- nop
-");
+__asm__ __volatile__ ("srl %o4, 0, %o4\n\t"
+ "mov %o7, %i7\n\t"
+ "call afs_syscall\n\t"
+ "srl %o5, 0, %o5\n\t"
+ "ret\n\t"
+ "nop");
}
#endif
asmlinkage long
afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp)
{
-__asm__ __volatile__ ("
- alloc r42 = ar.pfs, 8, 3, 6, 0
- mov r41 = b0 /* save rp */
- mov out0 = in0
- mov out1 = in1
- mov out2 = in2
- mov out3 = in3
- mov out4 = in4
- mov out5 = gp /* save gp */
- ;;
-.L1: mov r3 = ip
- ;;
- addl r15=.fptr_afs_syscall-.L1,r3
- ;;
- ld8 r15=[r15]
- ;;
- ld8 r16=[r15],8
- ;;
- ld8 gp=[r15]
- mov b6=r16
- br.call.sptk.many b0 = b6
- ;;
- mov ar.pfs = r42
- mov b0 = r41
- mov gp = r48 /* restore gp */
- br.ret.sptk.many b0
-.fptr_afs_syscall:
- data8 @fptr(afs_syscall)
-");
+__asm__ __volatile__ ("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t"
+ "mov r41 = b0\n\t" /* save rp */
+ "mov out0 = in0\n\t"
+ "mov out1 = in1\n\t"
+ "mov out2 = in2\n\t"
+ "mov out3 = in3\n\t"
+ "mov out4 = in4\n\t"
+ "mov out5 = gp\n\t" /* save gp */
+ ";;\n"
+ ".L1: mov r3 = ip\n\t"
+ ";;\n\t"
+ "addl r15=.fptr_afs_syscall-.L1,r3\n\t"
+ ";;\n\t"
+ "ld8 r15=[r15]\n\t"
+ ";;\n\t"
+ "ld8 r16=[r15],8\n\t"
+ ";;\n\t"
+ "ld8 gp=[r15]\n\t"
+ "mov b6=r16\n\t"
+ "br.call.sptk.many b0 = b6\n\t"
+ ";;\n\t"
+ "mov ar.pfs = r42\n\t"
+ "mov b0 = r41\n\t"
+ "mov gp = r48\n\t" /* restore gp */
+ "br.ret.sptk.many b0\n"
+ ".fptr_afs_syscall:\n\t"
+ "data8 @fptr(afs_syscall)");
}
asmlinkage long
afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp)
{
-__asm__ __volatile__ ("
- alloc r42 = ar.pfs, 8, 3, 6, 0
- mov r41 = b0 /* save rp */
- mov out0 = in0
- mov out1 = in1
- mov out2 = in2
- mov out3 = in3
- mov out4 = in4
- mov out5 = gp /* save gp */
- ;;
-.L2: mov r3 = ip
- ;;
- addl r15=.fptr_afs_xsetgroups - .L2,r3
- ;;
- ld8 r15=[r15]
- ;;
- ld8 r16=[r15],8
- ;;
- ld8 gp=[r15]
- mov b6=r16
- br.call.sptk.many b0 = b6
- ;;
- mov ar.pfs = r42
- mov b0 = r41
- mov gp = r48 /* restore gp */
- br.ret.sptk.many b0
-.fptr_afs_xsetgroups:
- data8 @fptr(afs_xsetgroups)
-");
+__asm__ __volatile__ ("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t"
+ "mov r41 = b0\n\t" /* save rp */
+ "mov out0 = in0\n\t"
+ "mov out1 = in1\n\t"
+ "mov out2 = in2\n\t"
+ "mov out3 = in3\n\t"
+ "mov out4 = in4\n\t"
+ "mov out5 = gp\n\t" /* save gp */
+ ";;\n"
+ ".L2: mov r3 = ip\n\t"
+ ";;\n\t"
+ "addl r15=.fptr_afs_xsetgroups - .L2,r3\n\t"
+ ";;\n\t"
+ "ld8 r15=[r15]\n\t"
+ ";;\n\t"
+ "ld8 r16=[r15],8\n\t"
+ ";;\n\t"
+ "ld8 gp=[r15]\n\t"
+ "mov b6=r16\n\t"
+ "br.call.sptk.many b0 = b6\n\t"
+ ";;\n\t"
+ "mov ar.pfs = r42\n\t"
+ "mov b0 = r41\n\t"
+ "mov gp = r48\n\t" /* restore gp */
+ "br.ret.sptk.many b0\n"
+ ".fptr_afs_xsetgroups:\n\t"
+ "data8 @fptr(afs_xsetgroups)");
}
struct fptr
{
#if defined(AFS_IA64_LINUX20_ENV)
unsigned long kernel_gp;
- static struct fptr sys_kill, sys_settimeofday, sys_setgroups;
+ static struct fptr sys_settimeofday, sys_setgroups;
#endif
extern int afs_syscall();
extern long afs_xsetgroups();
#endif
#endif
+#ifndef EXPORTED_SYS_CALL_TABLE
+ unsigned long *ptr;
+ unsigned long offset;
+ unsigned long datalen;
+ int ret;
+ unsigned long token;
+ char *mod_name;
+ unsigned long mod_start;
+ unsigned long mod_end;
+ char *sec_name;
+ unsigned long sec_start;
+ unsigned long sec_end;
+ char *sym_name;
+ unsigned long sym_start;
+ unsigned long sym_end;
+#endif
+
RWLOCK_INIT(&afs_xosi, "afs_xosi");
/* obtain PAGE_OFFSET value */
return -EIO;
}
#endif
-
+#ifndef EXPORTED_SYS_CALL_TABLE
+ sys_call_table=0;
+
+#ifdef EXPORTED_KALLSYMS_SYMBOL
+ ret=1;
+ token=0;
+ while (ret) {
+ sym_start=0;
+ ret=kallsyms_symbol_to_address("sys_call_table", &token, &mod_name,
+ &mod_start, &mod_end, &sec_name, &sec_start, &sec_end,
+ &sym_name, &sym_start, &sym_end);
+ if (ret && !strcmp(mod_name, "kernel"))
+ break;
+ }
+ if (ret && sym_start) {
+ sys_call_table=sym_start;
+ }
+#else
+#ifdef EXPORTED_KALLSYMS_ADDRESS
+ ret=kallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name,
+ &mod_start, &mod_end, &sec_name, &sec_start, &sec_end,
+ &sym_name, &sym_start, &sym_end);
+ ptr=(unsigned long *)sec_start;
+ datalen=(sec_end-sec_start)/sizeof(unsigned long);
+#else
+#if defined(AFS_IA64_LINUX20_ENV)
+ ptr = (unsigned long *) (&sys_close - 0x180000);
+ datalen=0x180000/sizeof(ptr);
+#else
+ ptr=(unsigned long *)&init_mm;
+ datalen=16384;
+#endif
+#endif
+ for (offset=0;offset <datalen;ptr++,offset++) {
+#if defined(AFS_IA64_LINUX20_ENV)
+ unsigned long close_ip=(unsigned long) ((struct fptr *)&sys_close)->ip;
+ unsigned long chdir_ip=(unsigned long) ((struct fptr *)&sys_chdir)->ip;
+ unsigned long write_ip=(unsigned long) ((struct fptr *)&sys_write)->ip;
+ if (ptr[0] == close_ip &&
+ ptr[__NR_chdir - __NR_close] == chdir_ip &&
+ ptr[__NR_write - __NR_close] == write_ip) {
+ sys_call_table=(void *) &(ptr[ -1 * (__NR_close-1024)]);
+ break;
+ }
+#else
+#if defined(EXPORTED_SYS_CHDIR) && defined(EXPORTED_SYS_CLOSE)
+ if (ptr[0] == (unsigned long)&sys_close &&
+ ptr[__NR_chdir - __NR_close] == (unsigned long)&sys_chdir) {
+ sys_call_table=ptr - __NR_close;
+ break;
+ }
+#else
+ if (ptr[0] == (unsigned long)&sys_exit &&
+ ptr[__NR_open - __NR_exit] == (unsigned long)&sys_open) {
+ sys_call_table=ptr - __NR_exit;
+ break;
+ }
+#endif
+#endif
+ }
+#ifdef EXPORTED_KALLSYMS_ADDRESS
+ ret=kallsyms_address_to_symbol((unsigned long)sys_call_table, &mod_name,
+ &mod_start, &mod_end, &sec_name, &sec_start, &sec_end,
+ &sym_name, &sym_start, &sym_end);
+ if (ret && strcmp(sym_name, "sys_call_table"))
+ sys_call_table=0;
+#endif
+#endif
+ if (!sys_call_table) {
+ printf("Failed to find address of sys_call_table\n");
+ return -EIO;
+ }
+ printf("Found sys_call_table at %x\n", sys_call_table);
+# ifdef AFS_SPARC64_LINUX20_ENV
+ error cant support this yet.
+#endif
+#endif /* EXPORTED_SYS_CALL_TABLE */
+
/* Initialize pointers to kernel syscalls. */
#if defined(AFS_IA64_LINUX20_ENV)
kernel_gp = ((struct fptr *)printk)->gp;
sys_settimeofdayp = (void *) &sys_settimeofday;
- sys_killp = (void *) &sys_kill;
((struct fptr *)sys_settimeofdayp)->ip =
SYSCALL2POINTER sys_call_table[__NR_settimeofday - 1024];
((struct fptr *)sys_settimeofdayp)->gp = kernel_gp;
- ((struct fptr *)sys_killp)->ip =
- SYSCALL2POINTER sys_call_table[__NR_kill - 1024];
- ((struct fptr *)sys_killp)->gp = kernel_gp;
#else /* !AFS_IA64_LINUX20_ENV */
sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
-#ifdef __NR_socketcall
- sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall];
-#endif /* no socketcall on alpha */
- sys_killp = SYSCALL2POINTER sys_call_table[__NR_kill];
#endif /* AFS_IA64_LINUX20_ENV */
/* setup AFS entry point. */
return -EBUSY;
}
-
#if defined(AFS_IA64_LINUX20_ENV)
afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024];
sys_call_table[__NR_afs_syscall - 1024] = POINTER2SYSCALL ((struct fptr *)afs_syscall_stub)->ip;
static long get_page_offset(void)
{
-#if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV)
+#if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV)
return PAGE_OFFSET;
#else
- struct task_struct *p;
+ struct task_struct *p, *q;
/* search backward thru the circular list */
- for(p = current; p; p = p->prev_task)
- if (p->pid == 1)
- return p->addr_limit.seg;
-
- return 0;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ read_lock(&tasklist_lock);
+#endif
+ /* search backward thru the circular list */
+#ifdef DEFINED_PREV_TASK
+ for(q = current; p = q; q = prev_task(p)) {
+#else
+ for(p = current; p; p = p->prev_task) {
+#endif
+ if (p->pid == 1) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ read_unlock(&tasklist_lock);
+#endif
+ return p->addr_limit.seg;
+ }
+ }
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ read_unlock(&tasklist_lock);
+#endif
+ return 0;
#endif
}