linux24-ppc-has-no-setgroups32-20010420
[openafs.git] / src / afs / LINUX / osi_module.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * Linux module support routines.
12  *
13  */
14 #include "../afs/param.h"
15 #include "../afs/sysincludes.h"
16 #include "../afs/afsincludes.h"
17 #include "../h/unistd.h" /* For syscall numbers. */
18 #include "../h/mm.h"
19
20 #include <linux/module.h>
21
22
23
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);
30
31 #ifdef AFS_SPARC64_LINUX20_ENV
32 extern unsigned int sys_call_table[];  /* changed to uint because SPARC64 has syscaltable of 32bit items */
33 #else
34 extern void * sys_call_table[]; /* safer for other linuces */
35 #endif
36 extern struct file_system_type afs_file_system;
37
38 static long get_page_offset(void);
39
40 #if defined(AFS_LINUX24_ENV)
41 DECLARE_MUTEX(afs_global_lock);
42 #else
43 struct semaphore afs_global_lock = MUTEX;
44 #endif
45 int afs_global_owner = 0;
46 unsigned long afs_linux_page_offset = 0; /* contains the PAGE_OFFSET value */
47
48 /* Since sys_ni_syscall is not exported, I need to cache it in order to restore
49  * it.
50  */
51 #ifdef AFS_SPARC64_LINUX20_ENV
52 static unsigned int afs_ni_syscall = 0;
53 #else
54 static void* afs_ni_syscall = 0;
55 #endif
56  
57 #ifdef AFS_SPARC64_LINUX20_ENV
58 static unsigned int afs_ni_syscall32 = 0;
59 asmlinkage int (*sys_setgroupsp32)(int gidsetsize, __kernel_gid_t32 *grouplist);
60 extern unsigned int sys_call_table32[];
61
62 asmlinkage int afs_syscall32(long syscall, long parm1, long parm2, long parm3,
63                              long parm4, long parm5)
64 {
65 __asm__ __volatile__ ("
66         srl %o4, 0, %o4
67         mov %o7, %i7
68         call afs_syscall
69         srl %o5, 0, %o5
70         ret
71         nop
72 ");
73 }
74 #endif
75
76 #if defined(AFS_LINUX24_ENV)
77 asmlinkage int (*sys_setgroups32p)(int gidsetsize, __kernel_gid32_t *grouplist);
78 #endif 
79
80 #ifdef AFS_SPARC64_LINUX20_ENV
81 #define POINTER2SYSCALL (unsigned int)(unsigned long)
82 #define SYSCALL2POINTER (void *)(long)
83 #else
84 #define POINTER2SYSCALL (void *)
85 #define SYSCALL2POINTER (void *)
86 #endif
87
88 int init_module(void)
89 {
90     extern int afs_syscall();
91     extern int afs_xsetgroups();
92 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_LINUX24_ENV)
93     extern int afs_xsetgroups32();
94 #endif
95
96     /* obtain PAGE_OFFSET value */
97     afs_linux_page_offset = get_page_offset();
98
99 #ifndef AFS_S390_LINUX22_ENV
100     if (afs_linux_page_offset == 0) {
101         /* couldn't obtain page offset so can't continue */
102         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
103         return -EIO;
104     }
105 #endif
106
107     /* Initialize pointers to kernel syscalls. */
108     sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
109 #if !defined(AFS_ALPHA_LINUX20_ENV)
110     sys_socketcallp = SYSCALL2POINTER sys_call_table[__NR_socketcall];
111 #endif /* no socketcall on alpha */
112     sys_killp = SYSCALL2POINTER sys_call_table[__NR_kill];
113
114     /* setup AFS entry point. */
115     if (SYSCALL2POINTER sys_call_table[__NR_afs_syscall] == afs_syscall) {
116         printf("AFS syscall entry point already in use!\n");
117         return -EBUSY;
118     }
119
120
121     afs_ni_syscall = sys_call_table[__NR_afs_syscall];
122     sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
123 #ifdef AFS_SPARC64_LINUX20_ENV
124     afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
125     sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
126 #endif
127
128     osi_Init();
129     register_filesystem(&afs_file_system);
130
131     /* Intercept setgroups calls */
132     sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
133     sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
134 #ifdef AFS_SPARC64_LINUX20_ENV
135     sys_setgroupsp32 = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
136     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups32;
137 #endif
138 #if defined(__NR_setgroups32)
139     sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32];
140     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
141 #endif
142
143     return 0;
144 }
145
146 void cleanup_module(void)
147 {
148     struct task_struct *t;
149
150     sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
151     sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
152 #ifdef AFS_SPARC64_LINUX20_ENV
153     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp32;
154     sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
155 #endif
156 #if defined(__NR_setgroups32)
157     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
158 #endif
159     unregister_filesystem(&afs_file_system);
160
161     osi_linux_free_inode_pages(); /* Invalidate all pages using AFS inodes. */
162     osi_linux_free_afs_memory();
163
164     return;
165 }
166
167 static long get_page_offset(void)
168 {
169 #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)
170     return PAGE_OFFSET;
171 #else
172     struct task_struct *p;
173
174     /* search backward thru the circular list */
175     for(p = current; p; p = p->prev_task)
176         if (p->pid == 1)
177             return p->addr_limit.seg;
178
179     return 0;
180 #endif
181 }