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>
23 #ifdef AFS_SPARC64_LINUX24_ENV
24 #define __NR_setgroups32 82 /* This number is not exported for some bizarre reason. */
27 asmlinkage int (*sys_settimeofdayp)(struct timeval *tv, struct timezone *tz);
28 #if !defined(AFS_ALPHA_LINUX20_ENV)
29 asmlinkage int (*sys_socketcallp)(int call, long *args);
30 #endif /* no socketcall on alpha */
31 asmlinkage int (*sys_killp)(int pid, int signal);
32 asmlinkage int (*sys_setgroupsp)(int gidsetsize, gid_t *grouplist);
34 #ifdef AFS_SPARC64_LINUX20_ENV
35 extern unsigned int sys_call_table[]; /* changed to uint because SPARC64 has syscaltable of 32bit items */
37 extern void * sys_call_table[]; /* safer for other linuces */
39 extern struct file_system_type afs_file_system;
41 static long get_page_offset(void);
43 #if defined(AFS_LINUX24_ENV)
44 DECLARE_MUTEX(afs_global_lock);
46 struct semaphore afs_global_lock = MUTEX;
48 int afs_global_owner = 0;
49 unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */
51 /* Since sys_ni_syscall is not exported, I need to cache it in order to restore
54 #ifdef AFS_SPARC64_LINUX20_ENV
55 static unsigned int afs_ni_syscall = 0;
57 static void* afs_ni_syscall = 0;
60 #ifdef AFS_SPARC64_LINUX20_ENV
61 static unsigned int afs_ni_syscall32 = 0;
62 asmlinkage int (*sys32_setgroupsp)(int gidsetsize, __kernel_gid_t32 *grouplist);
63 #if defined(__NR_setgroups32)
64 asmlinkage int (*sys32_setgroups32p)(int gidsetsize, __kernel_gid_t32 *grouplist);
66 extern unsigned int sys_call_table32[];
68 asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3,
69 long parm4, long parm5)
71 __asm__ __volatile__ ("
82 #ifdef AFS_LINUX24_ENV
83 asmlinkage int (*sys_setgroups32p)(int gidsetsize, __kernel_gid32_t *grouplist);
86 #ifdef AFS_SPARC64_LINUX20_ENV
87 #define POINTER2SYSCALL (unsigned int)(unsigned long)
88 #define SYSCALL2POINTER (void *)(long)
90 #define POINTER2SYSCALL (void *)
91 #define SYSCALL2POINTER (void *)
96 extern int afs_syscall();
97 extern int afs_xsetgroups();
98 #if defined(__NR_setgroups32)
99 extern int afs_xsetgroups32();
101 #ifdef AFS_SPARC64_LINUX20_ENV
102 extern int afs32_xsetgroups();
103 #if defined(__NR_setgroups32)
104 extern int afs32_xsetgroups32();
108 /* obtain PAGE_OFFSET value */
109 afs_linux_page_offset = get_page_offset();
111 #ifndef AFS_S390_LINUX22_ENV
112 if (afs_linux_page_offset == 0) {
113 /* couldn't obtain page offset so can't continue */
114 printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
119 /* Initialize pointers to kernel syscalls. */
120 sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
121 #if !defined(AFS_ALPHA_LINUX20_ENV)
122 sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall];
123 #endif /* no socketcall on alpha */
124 sys_killp = SYSCALL2POINTER sys_call_table[__NR_kill];
126 /* setup AFS entry point. */
127 if (SYSCALL2POINTER sys_call_table[__NR_afs_syscall] == afs_syscall) {
128 printf("AFS syscall entry point already in use!\n");
133 afs_ni_syscall = sys_call_table[__NR_afs_syscall];
134 sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
135 #ifdef AFS_SPARC64_LINUX20_ENV
136 afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
137 sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
141 register_filesystem(&afs_file_system);
143 /* Intercept setgroups calls */
144 sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
145 sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
146 #ifdef AFS_SPARC64_LINUX20_ENV
147 sys32_setgroupsp = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
148 sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
150 #if defined(__NR_setgroups32)
151 sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32];
152 sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
153 #ifdef AFS_SPARC64_LINUX20_ENV
154 sys32_setgroups32p = SYSCALL2POINTER sys_call_table32[__NR_setgroups32];
155 sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL afs32_xsetgroups32;
162 void cleanup_module(void)
164 struct task_struct *t;
166 sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
167 sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
168 #ifdef AFS_SPARC64_LINUX20_ENV
169 sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys32_setgroupsp;
170 sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
172 #if defined(__NR_setgroups32)
173 sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
174 #ifdef AFS_SPARC64_LINUX20_ENV
175 sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL sys32_setgroups32p;
178 unregister_filesystem(&afs_file_system);
180 osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */
181 osi_linux_free_afs_memory();
186 static long get_page_offset(void)
188 #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)
191 struct task_struct *p;
193 /* search backward thru the circular list */
194 for(p = current; p; p = p->prev_task)
196 return p->addr_limit.seg;