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 afs_lock_t afs_ftf; /* flush text lock */
30 lock_t afs_event_lock;
37 struct AFS_UCRED *afs_osi_credp;
39 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
40 kmutex_t afs_global_lock;
41 kmutex_t afs_rxglobal_lock;
44 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
45 long afs_global_owner;
48 #if defined(AFS_OSF_ENV)
49 simple_lock_data_t afs_global_lock;
52 #if defined(AFS_DARWIN_ENV)
53 #ifdef AFS_DARWIN80_ENV
54 lck_mtx_t *afs_global_lock;
56 struct lock__bsd__ afs_global_lock;
60 #if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD50_ENV)
61 struct lock afs_global_lock;
62 struct proc *afs_global_owner;
65 struct mtx afs_global_mtx;
68 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
69 thread_t afs_global_owner;
70 #endif /* AFS_OSF_ENV */
72 #if defined(AFS_AIX41_ENV)
73 simple_lock_data afs_global_lock;
80 if (once++ > 0) /* just in case */
82 #if defined(AFS_HPUX_ENV)
84 #else /* AFS_HPUX_ENV */
85 #if defined(AFS_GLOBAL_SUNLOCK)
86 #if defined(AFS_SGI62_ENV)
87 mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock");
88 #elif defined(AFS_OSF_ENV)
89 usimple_lock_init(&afs_global_lock);
90 afs_global_owner = (thread_t) 0;
91 #elif defined(AFS_FBSD50_ENV)
92 #if defined(AFS_FBSD80_ENV) && defined(WITNESS)
93 /* "lock_initalized" (sic) can panic, checks a flag bit
94 * is unset _before_ init */
95 memset(&afs_global_mtx, 0, sizeof(struct mtx));
97 mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF);
98 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
99 #if !defined(AFS_DARWIN80_ENV)
100 lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0);
102 afs_global_owner = 0;
103 #elif defined(AFS_AIX41_ENV)
104 lock_alloc((void *)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1);
105 simple_lock_init((void *)&afs_global_lock);
106 #elif !defined(AFS_LINUX22_ENV)
107 /* Linux initialization in osi directory. Should move the others. */
108 mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
110 #endif /* AFS_GLOBAL_SUNLOCK */
111 #endif /* AFS_HPUX_ENV */
113 if (!afs_osicred_initialized) {
114 #if defined(AFS_DARWIN80_ENV)
115 afs_osi_ctxtp_initialized = 0;
116 afs_osi_ctxtp = NULL; /* initialized in afs_Daemon since it has
117 a proc reference that cannot be changed */
119 #if defined(AFS_XBSD_ENV)
120 /* Can't just invent one, must use crget() because of mutex */
121 afs_osi_credp = crdup(osi_curcred());
123 memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
124 #if defined(AFS_LINUX26_ENV)
125 afs_osi_cred.cr_group_info = groups_alloc(0);
127 #if defined(AFS_DARWIN80_ENV)
128 afs_osi_cred.cr_ref = 1; /* kauth_cred_get_ref needs 1 existing ref */
130 crhold(&afs_osi_cred); /* don't let it evaporate */
133 afs_osi_credp = &afs_osi_cred;
135 afs_osicred_initialized = 1;
138 osi_flid.fl_pid = osi_flid.fl_sysid = 0;
141 init_et_to_sys_error();
144 /* mask signals in afsds */
146 afs_osi_MaskSignals(void)
148 #ifdef AFS_LINUX22_ENV
153 /* unmask signals in rxk listener */
155 afs_osi_UnmaskRxkSignals(void)
159 /* Two hacks to try and fix afsdb */
161 afs_osi_MaskUserLoop()
163 #ifdef AFS_DARWIN_ENV
165 afs_osi_fullSigMask();
167 afs_osi_MaskSignals();
172 afs_osi_UnmaskUserLoop(void)
174 #ifdef AFS_DARWIN_ENV
175 afs_osi_fullSigRestore();
179 /* register rxk listener proc info */
181 afs_osi_RxkRegister(void)
185 /* procedure for making our processes as invisible as we can */
187 afs_osi_Invisible(void)
189 #ifdef AFS_LINUX22_ENV
190 afs_osi_MaskSignals();
191 #elif defined(AFS_SUN5_ENV)
192 curproc->p_flag |= SSYS;
193 #elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV)
194 set_system_proc(u.u_procp);
195 #elif defined(AFS_DARWIN80_ENV)
196 #elif defined(AFS_DARWIN_ENV)
197 /* maybe call init_process instead? */
198 current_proc()->p_flag |= P_SYSTEM;
199 #elif defined(AFS_XBSD_ENV)
200 curproc->p_flag |= P_SYSTEM;
201 #elif defined(AFS_SGI_ENV)
205 AFS_STATCNT(osi_Invisible);
209 afs_osi_Visible(void)
211 #if defined(AFS_SUN5_ENV)
212 curproc->p_flag &= ~SSYS;
213 #elif defined(AFS_DARWIN80_ENV)
214 #elif defined(AFS_DARWIN_ENV)
215 /* maybe call init_process instead? */
216 current_proc()->p_flag &= ~P_SYSTEM;
217 #elif defined(AFS_XBSD_ENV)
218 curproc->p_flag &= ~P_SYSTEM;
222 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
223 /* set the real time */
225 afs_osi_SetTime(osi_timeval_t * atv)
227 #if defined(AFS_AIX32_ENV)
228 struct timestruc_t t;
230 t.tv_sec = atv->tv_sec;
231 t.tv_nsec = atv->tv_usec * 1000;
232 ksettimer(&t); /* Was -> settimer(TIMEOFDAY, &t); */
233 #elif defined(AFS_SUN55_ENV)
235 #elif defined(AFS_SUN5_ENV)
237 * To get more than second resolution we can use adjtime. The problem
238 * is that the usecs from the server are wrong (by now) so it isn't
239 * worth complicating the following code.
245 sta.time = atv->tv_sec;
248 #elif defined(AFS_SGI_ENV)
254 sta.time = atv->tv_sec;
257 #elif defined(AFS_DARWIN_ENV)
258 #ifndef AFS_DARWIN80_ENV
264 /* stolen from kern_time.c */
266 boottime.tv_sec += atv->tv_sec - time.tv_sec;
270 #if !defined(AFS_HPUX1122_ENV)
271 /* drop the setting of the clock for now. spl7 is not
276 t.tv_sec = atv->tv_sec;
277 t.tv_usec = atv->tv_usec;
294 logtchg(atv->tv_sec);
296 #endif /* AFS_DARWIN_ENV */
297 AFS_STATCNT(osi_SetTime);
299 #endif /* AFS_LINUX20_ENV */
305 AFS_STATCNT(shutdown_osi);
306 #ifdef AFS_DARWIN80_ENV
307 if (afs_osi_ctxtp_initialized && afs_osi_ctxtp) {
308 vfs_context_rele(afs_osi_ctxtp);
309 afs_osi_ctxtp = NULL;
310 afs_osi_ctxtp_initialized = 0;
314 if (afs_cold_shutdown) {
315 LOCK_INIT(&afs_ftf, "afs_ftf");
321 afs_osi_suser(void *cr)
323 #if defined(AFS_SUN510_ENV)
324 return (priv_policy(cr, PRIV_SYS_SUSER_COMPAT, B_FALSE, EPERM, NULL) == 0);
325 #elif defined(AFS_SUN5_ENV)
326 return afs_suser(cr);
328 return afs_suser(NULL);