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 afs_ucred_t *afs_osi_credp;
39 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
40 kmutex_t afs_global_lock;
43 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
44 long afs_global_owner;
47 #if defined(AFS_DARWIN_ENV)
48 thread_t afs_global_owner;
49 #ifdef AFS_DARWIN80_ENV
50 lck_mtx_t *afs_global_lock;
52 struct lock__bsd__ afs_global_lock;
56 #if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD_ENV)
57 # if defined(AFS_NBSD50_ENV)
58 kmutex_t afs_global_mtx;
60 struct lock afs_global_lock;
61 afs_proc_t *afs_global_owner;
63 #elif defined(AFS_FBSD_ENV)
64 struct mtx afs_global_mtx;
65 struct thread *afs_global_owner;
68 #if defined(AFS_AIX41_ENV)
69 simple_lock_data afs_global_lock;
76 if (once++ > 0) /* just in case */
81 if (!afs_osicred_initialized) {
82 #if defined(AFS_DARWIN80_ENV)
83 afs_osi_ctxtp_initialized = 0;
84 afs_osi_ctxtp = NULL; /* initialized in afs_Daemon since it has
85 a proc reference that cannot be changed */
87 #if defined(AFS_XBSD_ENV)
88 /* Can't just invent one, must use crget() because of mutex */
92 memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
93 #if defined(AFS_LINUX26_ENV)
94 afs_set_cr_group_info(&afs_osi_cred, groups_alloc(0));
96 #if defined(AFS_DARWIN80_ENV)
97 afs_osi_cred.cr_ref = 1; /* kauth_cred_get_ref needs 1 existing ref */
99 # if !(defined(AFS_LINUX26_ENV) && defined(STRUCT_TASK_STRUCT_HAS_CRED))
100 crhold(&afs_osi_cred); /* don't let it evaporate */
104 afs_osi_credp = &afs_osi_cred;
106 afs_osicred_initialized = 1;
109 osi_flid.fl_pid = osi_flid.fl_sysid = 0;
112 init_et_to_sys_error();
115 /* mask signals in afsds */
117 afs_osi_MaskSignals(void)
119 #ifdef AFS_LINUX22_ENV
124 /* unmask signals in rxk listener */
126 afs_osi_UnmaskRxkSignals(void)
130 /* Two hacks to try and fix afsdb */
132 afs_osi_MaskUserLoop(void)
134 #ifdef AFS_DARWIN_ENV
136 afs_osi_fullSigMask();
138 afs_osi_MaskSignals();
143 afs_osi_UnmaskUserLoop(void)
145 #ifdef AFS_DARWIN_ENV
146 afs_osi_fullSigRestore();
150 /* register rxk listener proc info */
152 afs_osi_RxkRegister(void)
156 /* procedure for making our processes as invisible as we can */
158 afs_osi_Invisible(void)
160 #ifdef AFS_LINUX22_ENV
161 afs_osi_MaskSignals();
162 #elif defined(AFS_SUN5_ENV)
163 curproc->p_flag |= SSYS;
164 #elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV)
165 set_system_proc(u.u_procp);
166 #elif defined(AFS_DARWIN80_ENV)
167 #elif defined(AFS_DARWIN_ENV)
168 /* maybe call init_process instead? */
169 current_proc()->p_flag |= P_SYSTEM;
170 #elif defined(AFS_NBSD50_ENV)
171 /* XXX in netbsd a system thread is more than invisible */
172 #elif defined(AFS_XBSD_ENV)
173 curproc->p_flag |= P_SYSTEM;
174 #elif defined(AFS_SGI_ENV)
178 AFS_STATCNT(osi_Invisible);
182 afs_osi_Visible(void)
184 #if defined(AFS_SUN5_ENV)
185 curproc->p_flag &= ~SSYS;
186 #elif defined(AFS_DARWIN80_ENV)
187 #elif defined(AFS_DARWIN_ENV)
188 /* maybe call init_process instead? */
189 current_proc()->p_flag &= ~P_SYSTEM;
190 #elif defined(AFS_NBSD50_ENV)
191 /* XXX in netbsd a system thread is more than invisible */
192 #elif defined(AFS_XBSD_ENV)
193 curproc->p_flag &= ~P_SYSTEM;
197 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
198 /* set the real time */
200 afs_osi_SetTime(osi_timeval_t * atv)
202 #if defined(AFS_AIX32_ENV)
203 struct timestruc_t t;
205 t.tv_sec = atv->tv_sec;
206 t.tv_nsec = atv->tv_usec * 1000;
207 ksettimer(&t); /* Was -> settimer(TIMEOFDAY, &t); */
208 #elif defined(AFS_SUN55_ENV)
210 #elif defined(AFS_SUN5_ENV)
212 * To get more than second resolution we can use adjtime. The problem
213 * is that the usecs from the server are wrong (by now) so it isn't
214 * worth complicating the following code.
220 sta.time = atv->tv_sec;
223 #elif defined(AFS_SGI_ENV)
229 sta.time = atv->tv_sec;
232 #elif defined(AFS_DARWIN_ENV)
233 #ifndef AFS_DARWIN80_ENV
239 /* stolen from kern_time.c */
241 boottime.tv_sec += atv->tv_sec - time.tv_sec;
245 #if !defined(AFS_HPUX1122_ENV)
246 /* drop the setting of the clock for now. spl7 is not
251 t.tv_sec = atv->tv_sec;
252 t.tv_usec = atv->tv_usec;
269 logtchg(atv->tv_sec);
271 #endif /* AFS_DARWIN_ENV */
272 AFS_STATCNT(osi_SetTime);
274 #endif /* AFS_LINUX20_ENV */
280 AFS_STATCNT(shutdown_osi);
281 #ifdef AFS_DARWIN80_ENV
282 if (afs_osi_ctxtp_initialized && afs_osi_ctxtp) {
283 vfs_context_rele(afs_osi_ctxtp);
284 afs_osi_ctxtp = NULL;
285 afs_osi_ctxtp_initialized = 0;
289 if (afs_cold_shutdown) {
290 LOCK_INIT(&afs_ftf, "afs_ftf");
294 #if !defined(AFS_OBSD_ENV) && !defined(AFS_NBSD40_ENV)
296 afs_osi_suser(void *cr)
298 #if defined(AFS_SUN510_ENV)
299 return (priv_policy(cr, PRIV_SYS_SUSER_COMPAT, B_FALSE, EPERM, NULL) == 0);
300 #elif defined(AFS_SUN5_ENV)
301 return afs_suser(cr);
303 return afs_suser(NULL);