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 <afsconfig.h>
15 #include "../afs/param.h"
19 #include "../afs/sysincludes.h"
20 #include "../afs/afsincludes.h"
21 #include "../h/unistd.h" /* For syscall numbers. */
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
27 #include <linux/init.h>
32 #ifdef AFS_SPARC64_LINUX24_ENV
33 #define __NR_setgroups32 82 /* This number is not exported for some bizarre reason. */
36 asmlinkage int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz);
37 #if !defined(AFS_ALPHA_LINUX20_ENV)
38 asmlinkage int (*sys_socketcallp)(int call, long *args);
39 #endif /* no socketcall on alpha */
40 asmlinkage int (*sys_killp)(int pid, int signal);
41 asmlinkage long (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist);
43 #ifdef AFS_SPARC64_LINUX20_ENV
44 extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */
46 extern void * sys_call_table[]; /* safer for other linuces */
48 extern struct file_system_type afs_file_system;
50 static long get_page_offset(void);
52 #if defined(AFS_LINUX24_ENV)
53 DECLARE_MUTEX(afs_global_lock);
55 struct semaphore afs_global_lock = MUTEX;
57 int afs_global_owner = 0;
58 unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */
60 /* Since sys_ni_syscall is not exported, I need to cache it in order to restore
63 #ifdef AFS_SPARC64_LINUX20_ENV
64 static unsigned int afs_ni_syscall = 0;
66 static void* afs_ni_syscall = 0;
69 #ifdef AFS_SPARC64_LINUX20_ENV
70 static unsigned int afs_ni_syscall32 = 0;
71 asmlinkage int (*sys32_setgroupsp)(int gidsetsize, __kernel_gid_t32 *grouplist);
72 #if defined(__NR_setgroups32)
73 asmlinkage int (*sys32_setgroups32p)(int gidsetsize, __kernel_gid_t32 *grouplist);
75 extern unsigned int sys_call_table32[];
77 asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3,
78 long parm4, long parm5)
80 __asm__ __volatile__ ("
91 #ifdef AFS_IA64_LINUX20_ENV
94 afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp)
96 __asm__ __volatile__ ("
97 alloc r42 = ar.pfs, 8, 3, 6, 0
98 mov r41 = b0 /* save rp */
104 mov out5 = gp /* save gp */
108 addl r15=.fptr_afs_syscall-.L1,r3
116 br.call.sptk.many b0 = b6
120 mov gp = r48 /* restore gp */
123 data8 @fptr(afs_syscall)
128 afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp)
130 __asm__ __volatile__ ("
131 alloc r42 = ar.pfs, 8, 3, 6, 0
132 mov r41 = b0 /* save rp */
138 mov out5 = gp /* save gp */
142 addl r15=.fptr_afs_xsetgroups - .L2,r3
150 br.call.sptk.many b0 = b6
154 mov gp = r48 /* restore gp */
156 .fptr_afs_xsetgroups:
157 data8 @fptr(afs_xsetgroups)
167 #endif /* AFS_IA64_LINUX20_ENV */
169 #ifdef AFS_LINUX24_ENV
170 asmlinkage int (*sys_setgroups32p)(int gidsetsize, __kernel_gid32_t *grouplist);
173 #ifdef AFS_SPARC64_LINUX20_ENV
174 #define POINTER2SYSCALL (unsigned int)(unsigned long)
175 #define SYSCALL2POINTER (void *)(long)
177 #define POINTER2SYSCALL (void *)
178 #define SYSCALL2POINTER (void *)
181 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
182 int __init afs_init(void)
184 int init_module(void)
187 #if defined(AFS_IA64_LINUX20_ENV)
188 unsigned long kernel_gp;
189 static struct fptr sys_kill, sys_settimeofday, sys_setgroups;
191 extern int afs_syscall();
192 extern long afs_xsetgroups();
193 #if defined(__NR_setgroups32)
194 extern int afs_xsetgroups32();
196 #ifdef AFS_SPARC64_LINUX20_ENV
197 extern int afs32_xsetgroups();
198 #if defined(__NR_setgroups32)
199 extern int afs32_xsetgroups32();
203 RWLOCK_INIT(&afs_xosi, "afs_xosi");
205 /* obtain PAGE_OFFSET value */
206 afs_linux_page_offset = get_page_offset();
208 #ifndef AFS_S390_LINUX22_ENV
209 if (afs_linux_page_offset == 0) {
210 /* couldn't obtain page offset so can't continue */
211 printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
216 /* Initialize pointers to kernel syscalls. */
217 #if defined(AFS_IA64_LINUX20_ENV)
218 kernel_gp = ((struct fptr *)printk)->gp;
220 sys_settimeofdayp = (void *) &sys_settimeofday;
221 sys_killp = (void *) &sys_kill;
223 ((struct fptr *)sys_settimeofdayp)->ip =
224 SYSCALL2POINTER sys_call_table[__NR_settimeofday - 1024];
225 ((struct fptr *)sys_settimeofdayp)->gp = kernel_gp;
227 ((struct fptr *)sys_killp)->ip =
228 SYSCALL2POINTER sys_call_table[__NR_kill - 1024];
229 ((struct fptr *)sys_killp)->gp = kernel_gp;
230 #else /* !AFS_IA64_LINUX20_ENV */
231 sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
232 #ifdef __NR_socketcall
233 sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall];
234 #endif /* no socketcall on alpha */
235 sys_killp = SYSCALL2POINTER sys_call_table[__NR_kill];
236 #endif /* AFS_IA64_LINUX20_ENV */
238 /* setup AFS entry point. */
240 #if defined(AFS_IA64_LINUX20_ENV)
241 SYSCALL2POINTER sys_call_table[__NR_afs_syscall - 1024]
243 SYSCALL2POINTER sys_call_table[__NR_afs_syscall]
246 printf("AFS syscall entry point already in use!\n");
251 #if defined(AFS_IA64_LINUX20_ENV)
252 afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024];
253 sys_call_table[__NR_afs_syscall - 1024] = POINTER2SYSCALL ((struct fptr *)afs_syscall_stub)->ip;
254 #else /* AFS_IA64_LINUX20_ENV */
255 afs_ni_syscall = sys_call_table[__NR_afs_syscall];
256 sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
257 # ifdef AFS_SPARC64_LINUX20_ENV
258 afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
259 sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
261 #endif /* AFS_IA64_LINUX20_ENV */
264 register_filesystem(&afs_file_system);
266 /* Intercept setgroups calls */
267 #if defined(AFS_IA64_LINUX20_ENV)
268 sys_setgroupsp = (void *) &sys_setgroups;
270 ((struct fptr *)sys_setgroupsp)->ip =
271 SYSCALL2POINTER sys_call_table[__NR_setgroups - 1024];
272 ((struct fptr *)sys_setgroupsp)->gp = kernel_gp;
274 sys_call_table[__NR_setgroups - 1024] = POINTER2SYSCALL ((struct fptr *)afs_xsetgroups_stub)->ip;
275 #else /* AFS_IA64_LINUX20_ENV */
276 sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
277 sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
278 # ifdef AFS_SPARC64_LINUX20_ENV
279 sys32_setgroupsp = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
280 sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
282 # if defined(__NR_setgroups32)
283 sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32];
284 sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
285 # ifdef AFS_SPARC64_LINUX20_ENV
286 sys32_setgroups32p = SYSCALL2POINTER sys_call_table32[__NR_setgroups32];
287 sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL afs32_xsetgroups32;
290 #endif /* AFS_IA64_LINUX20_ENV */
297 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
298 void __exit afs_cleanup(void)
300 void cleanup_module(void)
303 struct task_struct *t;
307 #if defined(AFS_IA64_LINUX20_ENV)
308 sys_call_table[__NR_setgroups - 1024] = POINTER2SYSCALL ((struct fptr *) sys_setgroupsp)->ip;
309 sys_call_table[__NR_afs_syscall - 1024] = afs_ni_syscall;
310 #else /* AFS_IA64_LINUX20_ENV */
311 sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
312 sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
313 # ifdef AFS_SPARC64_LINUX20_ENV
314 sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys32_setgroupsp;
315 sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
317 # if defined(__NR_setgroups32)
318 sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
319 # ifdef AFS_SPARC64_LINUX20_ENV
320 sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL sys32_setgroups32p;
323 #endif /* AFS_IA64_LINUX20_ENV */
324 unregister_filesystem(&afs_file_system);
326 osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */
327 osi_linux_free_afs_memory();
332 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
333 module_init(afs_init);
334 module_exit(afs_cleanup);
338 static long get_page_offset(void)
340 #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)
343 struct task_struct *p;
345 /* search backward thru the circular list */
346 for(p = current; p; p = p->prev_task)
348 return p->addr_limit.seg;