2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Linux module support routines.
14 #include "../afs/param.h"
15 #include "../afs/sysincludes.h"
16 #include "../afs/afsincludes.h"
17 #include "../h/unistd.h" /* For syscall numbers. */
20 #include <linux/module.h>
24 asmlinkage int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz);
25 #if !defined(AFS_ALPHA_LINUX20_ENV)
26 asmlinkage int (*sys_socketcallp)(int call, long *args);
27 #endif /* no socketcall on alpha */
28 asmlinkage int (*sys_killp)(int pid, int signal);
29 asmlinkage int (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist);
31 #ifdef AFS_SPARC64_LINUX20_ENV
32 extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */
34 extern void * sys_call_table[]; /* safer for other linuces */
36 extern struct file_system_type afs_file_system;
38 static long get_page_offset(void);
40 #if defined(AFS_LINUX24_ENV)
41 DECLARE_MUTEX(afs_global_lock);
43 struct semaphore afs_global_lock = MUTEX;
45 int afs_global_owner = 0;
46 unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */
48 /* Since sys_ni_syscall is not exported, I need to cache it in order to restore
51 static unsigned int afs_ni_syscall = 0;
53 #ifdef AFS_SPARC64_LINUX20_ENV
54 static unsigned int afs_ni_syscall32 = 0;
55 asmlinkage int (*sys_setgroupsp32)(int gidsetsize, __kernel_gid_t32 *grouplist);
56 extern unsigned int sys_call_table32[];
58 asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3,
59 long parm4, long parm5)
61 __asm__ __volatile__ ("
72 #ifdef AFS_SPARC64_LINUX20_ENV
73 #define POINTER2SYSCALL (unsigned int)(unsigned long)
74 #define SYSCALL2POINTER (void *)(long)
76 #define POINTER2SYSCALL (void *)
77 #define SYSCALL2POINTER (void *)
82 extern int afs_syscall();
83 extern int afs_xsetgroups();
84 #ifdef AFS_SPARC64_LINUX20_ENV
85 extern int afs_xsetgroups32();
88 /* obtain PAGE_OFFSET value */
89 afs_linux_page_offset = get_page_offset();
91 if (afs_linux_page_offset == 0) {
92 /* couldn't obtain page offset so can't continue */
93 printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
97 /* Initialize pointers to kernel syscalls. */
98 sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
99 #if !defined(AFS_ALPHA_LINUX20_ENV)
100 sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall];
101 #endif /* no socketcall on alpha */
102 sys_killp = SYSCALL2POINTER sys_call_table[__NR_kill];
104 /* setup AFS entry point. */
105 if (SYSCALL2POINTER sys_call_table[__NR_afs_syscall] == afs_syscall) {
106 printf("AFS syscall entry point already in use!\n");
111 afs_ni_syscall = sys_call_table[__NR_afs_syscall];
112 sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
113 #ifdef AFS_SPARC64_LINUX20_ENV
114 afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
115 sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
119 register_filesystem(&afs_file_system);
121 /* Intercept setgroups calls */
122 sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
123 sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
124 #ifdef AFS_SPARC64_LINUX20_ENV
125 sys_setgroupsp32 = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
126 sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups32;
132 void cleanup_module(void)
134 struct task_struct *t;
136 sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
137 sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
138 #ifdef AFS_SPARC64_LINUX20_ENV
139 sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp32;
140 sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
143 unregister_filesystem(&afs_file_system);
145 osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */
146 osi_linux_free_afs_memory();
151 static long get_page_offset(void)
153 #if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV)
156 struct task_struct *p;
158 /* search backward thru the circular list */
159 for(p = current; p; p = p->prev_task)
161 return p->addr_limit.seg;