2 * Copyrigh 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
10 #include <afsconfig.h>
11 #include "afs/param.h"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
18 #include <sys/adspace.h> /* for vm_att(), vm_det() */
21 /* osi_Init -- do once per kernel installation initialization.
22 * -- On Solaris this is called from modload initialization.
23 * -- On AIX called from afs_config.
24 * -- On HP called from afsc_link.
25 * -- On SGI called from afs_init. */
27 /* No hckernel-specific header for this prototype. */
29 extern void init_hckernel_mutex(void);
32 afs_lock_t afs_ftf
; /* flush text lock */
35 lock_t afs_event_lock
;
42 afs_ucred_t
*afs_osi_credp
;
44 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
45 kmutex_t afs_global_lock
;
48 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
49 long afs_global_owner
;
52 #if defined(AFS_DARWIN_ENV)
53 thread_t afs_global_owner
;
54 #ifdef AFS_DARWIN80_ENV
55 lck_mtx_t
*afs_global_lock
;
57 struct lock__bsd__ afs_global_lock
;
61 #if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD_ENV)
62 # if defined(AFS_NBSD50_ENV)
63 kmutex_t afs_global_mtx
;
65 struct lock afs_global_lock
;
66 afs_proc_t
*afs_global_owner
;
68 #elif defined(AFS_FBSD_ENV)
69 struct mtx afs_global_mtx
;
70 struct thread
*afs_global_owner
;
73 #if defined(AFS_AIX41_ENV)
74 simple_lock_data afs_global_lock
;
81 if (once
++ > 0) /* just in case */
86 /* Initialize a lock for the kernel hcrypto bits. */
88 init_hckernel_mutex();
92 if (!afs_osicred_initialized
) {
93 #if defined(AFS_DARWIN80_ENV)
94 afs_osi_ctxtp_initialized
= 0;
95 afs_osi_ctxtp
= NULL
; /* initialized in afs_Daemon since it has
96 a proc reference that cannot be changed */
98 #if defined(AFS_XBSD_ENV)
99 /* Can't just invent one, must use crget() because of mutex */
101 crdup(osi_curcred());
102 #elif defined(AFS_SUN5_ENV)
103 afs_osi_credp
= kcred
;
105 memset(&afs_osi_cred
, 0, sizeof(afs_ucred_t
));
106 #if defined(AFS_LINUX26_ENV)
107 afs_set_cr_group_info(&afs_osi_cred
, groups_alloc(0));
109 #if defined(AFS_DARWIN80_ENV)
110 afs_osi_cred
.cr_ref
= 1; /* kauth_cred_get_ref needs 1 existing ref */
112 # if !(defined(AFS_LINUX26_ENV) && defined(STRUCT_TASK_STRUCT_HAS_CRED))
113 crhold(&afs_osi_cred
); /* don't let it evaporate */
117 afs_osi_credp
= &afs_osi_cred
;
119 afs_osicred_initialized
= 1;
122 osi_flid
.fl_pid
= osi_flid
.fl_sysid
= 0;
125 init_et_to_sys_error();
128 /* mask signals in afsds */
130 afs_osi_MaskSignals(void)
132 #ifdef AFS_LINUX22_ENV
137 /* unmask signals in rxk listener */
139 afs_osi_UnmaskRxkSignals(void)
141 #ifdef AFS_LINUX22_ENV
142 osi_linux_unmaskrxk();
146 /* Two hacks to try and fix afsdb */
148 afs_osi_MaskUserLoop(void)
150 #ifdef AFS_DARWIN_ENV
152 afs_osi_fullSigMask();
154 afs_osi_MaskSignals();
159 afs_osi_UnmaskUserLoop(void)
161 #ifdef AFS_DARWIN_ENV
162 afs_osi_fullSigRestore();
166 /* register rxk listener proc info */
168 afs_osi_RxkRegister(void)
172 /* procedure for making our processes as invisible as we can */
174 afs_osi_Invisible(void)
176 #ifdef AFS_LINUX22_ENV
177 afs_osi_MaskSignals();
178 #elif defined(AFS_SUN5_ENV)
179 curproc
->p_flag
|= SSYS
;
180 #elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV)
181 set_system_proc(u
.u_procp
);
182 #elif defined(AFS_DARWIN80_ENV)
183 #elif defined(AFS_DARWIN_ENV)
184 /* maybe call init_process instead? */
185 current_proc()->p_flag
|= P_SYSTEM
;
186 #elif defined(AFS_NBSD50_ENV)
187 /* XXX in netbsd a system thread is more than invisible */
188 #elif defined(AFS_XBSD_ENV)
189 curproc
->p_flag
|= P_SYSTEM
;
190 #elif defined(AFS_SGI_ENV)
194 AFS_STATCNT(osi_Invisible
);
198 afs_osi_Visible(void)
200 #if defined(AFS_SUN5_ENV)
201 curproc
->p_flag
&= ~SSYS
;
202 #elif defined(AFS_DARWIN80_ENV)
203 #elif defined(AFS_DARWIN_ENV)
204 /* maybe call init_process instead? */
205 current_proc()->p_flag
&= ~P_SYSTEM
;
206 #elif defined(AFS_NBSD50_ENV)
207 /* XXX in netbsd a system thread is more than invisible */
208 #elif defined(AFS_XBSD_ENV)
209 curproc
->p_flag
&= ~P_SYSTEM
;
216 AFS_STATCNT(shutdown_osi
);
217 #ifdef AFS_DARWIN80_ENV
218 if (afs_osi_ctxtp_initialized
&& afs_osi_ctxtp
) {
219 vfs_context_rele(afs_osi_ctxtp
);
220 afs_osi_ctxtp
= NULL
;
221 afs_osi_ctxtp_initialized
= 0;
224 #if !defined(AFS_HPUX_ENV) && !defined(UKERNEL) && !defined(AFS_DFBSD_ENV) && !defined(AFS_LINUX26_ENV)
225 /* LINUX calls this from afs_cleanup() which hooks into module_exit */
228 if (afs_cold_shutdown
) {
229 LOCK_INIT(&afs_ftf
, "afs_ftf");
233 #if !defined(AFS_HPUX_ENV) && !defined(UKERNEL) && !defined(AFS_DFBSD_ENV) && !defined(AFS_DARWIN_ENV)
234 /* DARWIN uses locking, and so must provide its own */
236 shutdown_osisleep(void)
241 for (i
=0;i
<AFS_EVHASHSIZE
;i
++) {
242 while ((tmp
= afs_evhasht
[i
]) != NULL
) {
243 afs_evhasht
[i
] = tmp
->next
;
244 if (tmp
->refcount
> 0) {
245 afs_warn("nonzero refcount in shutdown_osisleep()\n");
247 #if defined(AFS_AIX_ENV)
249 #elif defined(AFS_FBSD_ENV)
250 afs_osi_Free(tmp
, sizeof(*tmp
));
251 #elif defined(AFS_SGI_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_SUN5_ENV)
252 osi_FreeSmallSpace(tmp
);
253 #elif defined(AFS_LINUX26_ENV)
255 #elif defined(AFS_LINUX20_ENV)
264 #if !defined(AFS_OBSD_ENV) && !defined(AFS_NBSD40_ENV)
266 afs_osi_suser(void *cr
)
268 #if defined(AFS_SUN510_ENV)
269 return (priv_policy(cr
, PRIV_SYS_SUSER_COMPAT
, B_FALSE
, EPERM
, NULL
) == 0);
270 #elif defined(AFS_SUN5_ENV)
271 return afs_suser(cr
);
273 return afs_suser(NULL
);