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
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
20 #include <sys/adspace.h> /* for vm_att(), vm_det() */
23 static char memZero; /* address of 0 bytes for kmem_alloc */
29 /* osi_Init -- do once per kernel installation initialization.
30 * -- On Solaris this is called from modload initialization.
31 * -- On AIX called from afs_config.
32 * -- On HP called from afsc_link.
33 * -- On SGI called from afs_init. */
36 lock_t afs_event_lock;
43 struct AFS_UCRED *afs_osi_credp;
49 if (once++ > 0) /* just in case */
51 #if defined(AFS_HPUX_ENV)
53 #else /* AFS_HPUX_ENV */
54 #if defined(AFS_GLOBAL_SUNLOCK)
55 #if defined(AFS_SGI62_ENV)
56 mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock");
57 #elif defined(AFS_OSF_ENV)
58 usimple_lock_init(&afs_global_lock);
59 afs_global_owner = (thread_t) 0;
60 #elif defined(AFS_FBSD50_ENV)
61 mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF);
62 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
63 lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0);
65 #elif defined(AFS_AIX41_ENV)
66 lock_alloc((void *)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1);
67 simple_lock_init((void *)&afs_global_lock);
68 #elif !defined(AFS_LINUX22_ENV)
69 /* Linux initialization in osi directory. Should move the others. */
70 mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
72 /* afs_rxglobal_lock is initialized in rx_Init. */
73 #endif /* AFS_GLOBAL_SUNLOCK */
74 #endif /* AFS_HPUX_ENV */
76 if (!afs_osicred_initialized) {
77 #if defined(AFS_XBSD_ENV)
78 /* Can't just invent one, must use crget() because of mutex */
79 afs_osi_credp = crdup(osi_curcred());
81 memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
82 #if defined(AFS_LINUX26_ENV)
83 afs_osi_cred.cr_group_info = groups_alloc(0);
85 crhold(&afs_osi_cred); /* don't let it evaporate */
86 afs_osi_credp = &afs_osi_cred;
88 afs_osicred_initialized = 1;
91 osi_flid.fl_pid = osi_flid.fl_sysid = 0;
94 init_et_to_sys_error();
98 osi_Active(register struct vcache *avc)
100 AFS_STATCNT(osi_Active);
101 #if defined(AFS_SUN_ENV) || defined(AFS_AIX_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || (AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
102 if ((avc->opens > 0) || (avc->states & CMAPPED))
103 return 1; /* XXX: Warning, verify this XXX */
104 #elif defined(AFS_MACH_ENV)
106 || ((avc->v.v_flag & VTEXT) && !inode_uncache_try(avc)))
108 #elif defined(AFS_SGI_ENV)
109 if ((avc->opens > 0) || AFS_VN_MAPPED(AFSTOV(avc)))
112 if (avc->opens > 0 || (AFSTOV(avc)->v_flag & VTEXT))
118 /* this call, unlike osi_FlushText, is supposed to discard caches that may
119 contain invalid information if a file is written remotely, but that may
120 contain valid information that needs to be written back if the file is
121 being written locally. It doesn't subsume osi_FlushText, since the latter
122 function may be needed to flush caches that are invalidated by local writes.
124 avc->pvnLock is already held, avc->lock is guaranteed not to be held (by
128 osi_FlushPages(register struct vcache *avc, struct AFS_UCRED *credp)
131 ObtainReadLock(&avc->lock);
132 /* If we've already purged this version, or if we're the ones
133 * writing this version, don't flush it (could lose the
134 * data we're writing). */
135 if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0)
136 || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) {
137 ReleaseReadLock(&avc->lock);
140 ReleaseReadLock(&avc->lock);
141 ObtainWriteLock(&avc->lock, 10);
143 if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0)
144 || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) {
145 ReleaseWriteLock(&avc->lock);
148 if (hiszero(avc->mapDV)) {
149 hset(avc->mapDV, avc->m.DataVersion);
150 ReleaseWriteLock(&avc->lock);
154 AFS_STATCNT(osi_FlushPages);
155 hset(origDV, avc->m.DataVersion);
156 afs_Trace3(afs_iclSetp, CM_TRACE_FLUSHPAGES, ICL_TYPE_POINTER, avc,
157 ICL_TYPE_INT32, origDV.low, ICL_TYPE_INT32, avc->m.Length);
159 ReleaseWriteLock(&avc->lock);
161 osi_VM_FlushPages(avc, credp);
163 ObtainWriteLock(&avc->lock, 88);
165 /* do this last, and to original version, since stores may occur
166 * while executing above PUTPAGE call */
167 hset(avc->mapDV, origDV);
168 ReleaseWriteLock(&avc->lock);
171 afs_lock_t afs_ftf; /* flush text lock */
175 /* This call is supposed to flush all caches that might be invalidated
176 * by either a local write operation or a write operation done on
177 * another client. This call may be called repeatedly on the same
178 * version of a file, even while a file is being written, so it
179 * shouldn't do anything that would discard newly written data before
180 * it is written to the file system. */
183 osi_FlushText_really(register struct vcache *vp)
185 afs_hyper_t fdv; /* version before which we'll flush */
187 AFS_STATCNT(osi_FlushText);
188 /* see if we've already flushed this data version */
189 if (hcmp(vp->m.DataVersion, vp->flushDV) <= 0)
194 void afs_gfs_FlushText();
195 afs_gfs_FlushText(vp);
200 MObtainWriteLock(&afs_ftf, 317);
201 hset(fdv, vp->m.DataVersion);
203 /* why this disgusting code below?
204 * xuntext, called by xrele, doesn't notice when it is called
205 * with a freed text object. Sun continually calls xrele or xuntext
206 * without any locking, as long as VTEXT is set on the
207 * corresponding vnode.
208 * But, if the text object is locked when you check the VTEXT
209 * flag, several processes can wait in xuntext, waiting for the
210 * text lock; when the second one finally enters xuntext's
211 * critical region, the text object is already free, but the check
212 * was already done by xuntext's caller.
213 * Even worse, it turns out that xalloc locks the text object
214 * before reading or stating a file via the vnode layer. Thus, we
215 * could end up in getdcache, being asked to bring in a new
216 * version of a file, but the corresponding text object could be
217 * locked. We can't flush the text object without causing
218 * deadlock, so now we just don't try to lock the text object
219 * unless it is guaranteed to work. And we try to flush the text
220 * when we need to a bit more often at the vnode layer. Sun
221 * really blew the vm-cache flushing interface.
224 #if defined (AFS_HPUX_ENV)
225 if (vp->v.v_flag & VTEXT) {
228 if (vp->v.v_flag & VTEXT) { /* still has a text object? */
229 MReleaseWriteLock(&afs_ftf);
235 /* next do the stuff that need not check for deadlock problems */
238 /* finally, record that we've done it */
239 hset(vp->flushDV, fdv);
240 MReleaseWriteLock(&afs_ftf);
242 #endif /* AFS_DEC_ENV */
246 /* I don't really like using xinval() here, because it kills processes
247 * a bit aggressively. Previous incarnations of this functionality
248 * used to use xrele() instead of xinval, and didn't invoke
249 * cacheinval(). But they would panic. So it might be worth looking
250 * into some middle ground...
253 afs_gfs_FlushText(register struct vcache *vp)
255 afs_hyper_t fdv; /* version before which we'll flush */
256 register struct text *xp;
259 MObtainWriteLock(&afs_ftf, 318);
260 hset(fdv, vp->m.DataVersion);
264 /* this happens frequently after cores are created. */
265 MReleaseWriteLock(&afs_ftf);
269 if (gp->g_flag & GTEXT) {
271 xp = (struct text *)gp->g_textp;
272 /* if text object is locked, give up */
273 if (xp && (xp->x_flag & XLOCK)) {
274 MReleaseWriteLock(&afs_ftf);
280 if (gp->g_flag & GTEXT) { /* still has a text object? */
285 /* next do the stuff that need not check for deadlock problems */
286 /* maybe xinval(gp); here instead of above */
289 /* finally, record that we've done it */
290 hset(vp->flushDV, fdv);
292 MReleaseWriteLock(&afs_ftf);
294 #endif /* AFS_DEC_ENV */
296 #endif /* AFS_TEXT_ENV */
298 /* mask signals in afsds */
300 afs_osi_MaskSignals(void)
302 #ifdef AFS_LINUX22_ENV
307 /* unmask signals in rxk listener */
309 afs_osi_UnmaskRxkSignals(void)
313 /* Two hacks to try and fix afsdb */
315 afs_osi_MaskUserLoop()
317 #ifdef AFS_DARWIN_ENV
319 afs_osi_fullSigMask();
321 afs_osi_MaskSignals();
326 afs_osi_UnmaskUserLoop()
328 #ifdef AFS_DARWIN_ENV
329 afs_osi_fullSigRestore();
333 /* register rxk listener proc info */
335 afs_osi_RxkRegister(void)
337 #ifdef AFS_LINUX22_ENV
342 /* procedure for making our processes as invisible as we can */
344 afs_osi_Invisible(void)
346 #ifdef AFS_LINUX22_ENV
347 afs_osi_MaskSignals();
348 #elif defined(AFS_DEC_ENV)
349 u.u_procp->p_type |= SSYS;
350 #elif defined(AFS_SUN5_ENV)
351 curproc->p_flag |= SSYS;
352 #elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV)
353 set_system_proc(u.u_procp);
354 #elif defined(AFS_DARWIN_ENV)
355 /* maybe call init_process instead? */
356 current_proc()->p_flag |= P_SYSTEM;
357 #elif defined(AFS_XBSD_ENV)
358 curproc->p_flag |= P_SYSTEM;
359 #elif defined(AFS_SGI_ENV)
363 AFS_STATCNT(osi_Invisible);
367 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
368 /* set the real time */
370 afs_osi_SetTime(osi_timeval_t * atv)
372 #if defined(AFS_AIX32_ENV)
373 struct timestruc_t t;
375 t.tv_sec = atv->tv_sec;
376 t.tv_nsec = atv->tv_usec * 1000;
377 ksettimer(&t); /* Was -> settimer(TIMEOFDAY, &t); */
378 #elif defined(AFS_SUN55_ENV)
380 #elif defined(AFS_SUN5_ENV)
382 * To get more than second resolution we can use adjtime. The problem
383 * is that the usecs from the server are wrong (by now) so it isn't
384 * worth complicating the following code.
390 sta.time = atv->tv_sec;
393 #elif defined(AFS_SGI_ENV)
399 sta.time = atv->tv_sec;
402 #elif defined(AFS_DARWIN_ENV)
407 /* stolen from kern_time.c */
409 boottime.tv_sec += atv->tv_sec - time.tv_sec;
413 #if !defined(AFS_HPUX1122_ENV)
414 /* drop the setting of the clock for now. spl7 is not
419 t.tv_sec = atv->tv_sec;
420 t.tv_usec = atv->tv_usec;
437 logtchg(atv->tv_sec);
439 #endif /* AFS_DARWIN_ENV */
440 AFS_STATCNT(osi_SetTime);
442 #endif /* AFS_LINUX20_ENV */
446 afs_osi_Alloc(size_t x)
448 register struct osimem *tm = NULL;
451 AFS_STATCNT(osi_Alloc);
452 /* 0-length allocs may return NULL ptr from AFS_KALLOC, so we special-case
453 * things so that NULL returned iff an error occurred */
457 AFS_STATS(afs_stats_cmperf.OutStandingAllocs++);
458 AFS_STATS(afs_stats_cmperf.OutStandingMemUsage += x);
459 #ifdef AFS_LINUX20_ENV
460 return osi_linux_alloc(x, 1);
461 #elif defined(AFS_FBSD_ENV)
462 return osi_fbsd_alloc(x, 1);
465 tm = (struct osimem *)AFS_KALLOC(size);
468 osi_Panic("osi_Alloc: Couldn't allocate %d bytes; out of memory!\n",
475 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV)
478 afs_osi_Alloc_NoSleep(size_t x)
480 register struct osimem *tm;
483 AFS_STATCNT(osi_Alloc);
484 /* 0-length allocs may return NULL ptr from AFS_KALLOC, so we special-case
485 * things so that NULL returned iff an error occurred */
490 AFS_STATS(afs_stats_cmperf.OutStandingAllocs++);
491 AFS_STATS(afs_stats_cmperf.OutStandingMemUsage += x);
492 tm = (struct osimem *)AFS_KALLOC_NOSLEEP(size);
496 #endif /* SUN || SGI */
499 afs_osi_Free(void *x, size_t asize)
501 AFS_STATCNT(osi_Free);
503 return; /* check for putting memZero back */
505 AFS_STATS(afs_stats_cmperf.OutStandingAllocs--);
506 AFS_STATS(afs_stats_cmperf.OutStandingMemUsage -= asize);
507 #if defined(AFS_LINUX20_ENV)
509 #elif defined(AFS_FBSD_ENV)
512 AFS_KFREE((struct osimem *)x, asize);
517 afs_osi_FreeStr(char *x)
519 afs_osi_Free(x, strlen(x) + 1);
522 /* ? is it moderately likely that there are dirty VM pages associated with
525 * Prereqs: avc must be write-locked
527 * System Dependencies: - *must* support each type of system for which
528 * memory mapped files are supported, even if all
529 * it does is return TRUE;
531 * NB: this routine should err on the side of caution for ProcessFS to work
532 * correctly (or at least, not to introduce worse bugs than already exist)
536 osi_VMDirty_p(struct vcache *avc)
540 if (avc->execsOrWriters <= 0)
541 return 0; /* can't be many dirty pages here, I guess */
543 #if defined (AFS_AIX32_ENV)
545 /* because of the level of hardware involvment with VM and all the
546 * warnings about "This routine must be called at VMM interrupt
547 * level", I thought it would be safest to disable interrupts while
548 * looking at the software page fault table. */
550 /* convert vm handle into index into array: I think that stoinio is
551 * always zero... Look into this XXX */
552 #define VMHASH(handle) ( \
553 ( ((handle) & ~vmker.stoinio) \
554 ^ ((((handle) & ~vmker.stoinio) & vmker.stoimask) << vmker.stoihash) \
558 unsigned int pagef, pri, index, next;
560 index = VMHASH(avc->segid);
561 if (scb_valid(index)) { /* could almost be an ASSERT */
563 pri = disable_ints();
564 for (pagef = scb_sidlist(index); pagef >= 0; pagef = next) {
565 next = pft_sidfwd(pagef);
566 if (pft_modbit(pagef)) { /* has page frame been modified? */
576 #endif /* AFS_AIX32_ENV */
578 #if defined (AFS_SUN_ENV)
579 if (avc->states & CMAPPED) {
581 for (pg = avc->v.v_s.v_Pages; pg; pg = pg->p_vpnext) {
594 * Solaris osi_ReleaseVM should not drop and re-obtain the vcache entry lock.
595 * This leads to bad races when osi_ReleaseVM() is called from
596 * afs_InvalidateAllSegments().
598 * We can do this because Solaris osi_VM_Truncate() doesn't care whether the
599 * vcache entry lock is held or not.
601 * For other platforms, in some cases osi_VM_Truncate() doesn't care, but
602 * there may be cases where it does care. If so, it would be good to fix
603 * them so they don't care. Until then, we assume the worst.
605 * Locking: the vcache entry lock is held. It is dropped and re-obtained.
608 osi_ReleaseVM(struct vcache *avc, struct AFS_UCRED *acred)
612 osi_VM_Truncate(avc, 0, acred);
615 ReleaseWriteLock(&avc->lock);
617 osi_VM_Truncate(avc, 0, acred);
619 ObtainWriteLock(&avc->lock, 80);
627 AFS_STATCNT(shutdown_osi);
628 if (afs_cold_shutdown) {
629 LOCK_INIT(&afs_ftf, "afs_ftf");
635 afs_osi_suser(void *credp)
637 #if defined(AFS_SUN5_ENV)
638 return afs_suser(credp);
640 return afs_suser(NULL);
647 /* afs_osi_TraverseProcTable() - Walk through the systems process
648 * table, calling afs_GCPAGs_perproc_func() for each process.
651 #if defined(AFS_SUN5_ENV)
653 afs_osi_TraverseProcTable(void)
656 for (prp = practive; prp != NULL; prp = prp->p_next) {
657 afs_GCPAGs_perproc_func(prp);
662 #if defined(AFS_HPUX_ENV)
665 * NOTE: h/proc_private.h gives the process table locking rules
666 * It indicates that access to p_cred must be protected by
668 * mp_mtproc_unlock(p);
670 * The code in sys/pm_prot.c uses pcred_lock() to protect access to
671 * the process creds, and uses mp_mtproc_lock() only for audit-related
672 * changes. To be safe, we use both.
676 afs_osi_TraverseProcTable(void)
681 MP_SPINLOCK(activeproc_lock);
682 MP_SPINLOCK(sched_lock);
686 * Instead of iterating through all of proc[], traverse only
687 * the list of active processes. As an example of this,
688 * see foreach_process() in sys/vm_sched.c.
690 * We hold the locks for the entire scan in order to get a
691 * consistent view of the current set of creds.
694 for (p = proc; endchain == 0; p = &proc[p->p_fandx]) {
695 if (p->p_fandx == 0) {
703 afs_GCPAGs_perproc_func(p);
708 MP_SPINUNLOCK(sched_lock);
709 MP_SPINUNLOCK(activeproc_lock);
713 #if defined(AFS_SGI_ENV)
716 /* TODO: Fix this later. */
718 SGI_ProcScanFunc(void *p, void *arg, int mode)
722 #else /* AFS_SGI65_ENV */
724 SGI_ProcScanFunc(proc_t * p, void *arg, int mode)
726 afs_int32(*perproc_func) (struct proc *) = arg;
728 /* we pass in the function pointer for arg,
729 * mode ==0 for startup call, ==1 for each valid proc,
730 * and ==2 for terminate call.
733 code = perproc_func(p);
737 #endif /* AFS_SGI65_ENV */
740 afs_osi_TraverseProcTable(void)
742 procscan(SGI_ProcScanFunc, afs_GCPAGs_perproc_func);
744 #endif /* AFS_SGI_ENV */
746 #if defined(AFS_AIX_ENV)
748 #define max_proc v.ve_proc
751 afs_osi_TraverseProcTable(void)
757 * For binary compatibility, on AIX we need to be careful to use the
758 * proper size of a struct proc, even if it is different from what
759 * we were compiled with.
761 if (!afs_gcpags_procsize)
764 #ifndef AFS_AIX51_ENV
765 simple_lock(&proc_tbl_lock);
767 for (p = (struct proc *)v.vb_proc, i = 0; p < max_proc;
768 p = (struct proc *)((char *)p + afs_gcpags_procsize), i++) {
771 if (p->p_pvprocp->pv_stat == SNONE)
773 if (p->p_pvprocp->pv_stat == SIDL)
775 if (p->p_pvprocp->pv_stat == SEXIT)
778 if (p->p_stat == SNONE)
780 if (p->p_stat == SIDL)
782 if (p->p_stat == SEXIT)
788 if (PROCMASK(p->p_pid) != i) {
789 afs_gcpags = AFS_GCPAGS_EPIDCHECK;
795 if ((p->p_nice < P_NICE_MIN) || (P_NICE_MAX < p->p_nice)) {
796 afs_gcpags = AFS_GCPAGS_ENICECHECK;
800 afs_GCPAGs_perproc_func(p);
802 #ifndef AFS_AIX51_ENV
803 simple_unlock(&proc_tbl_lock);
808 #if defined(AFS_OSF_ENV)
811 extern struct pid_entry *pidtab;
816 afs_osi_TraverseProcTable(void)
818 struct pid_entry *pe;
820 #define pidNPID (pidtab + npid)
825 for (pe = pidtab; pe < pidNPID; ++pe) {
826 if (pe->pe_proc != PROC_NULL)
827 afs_GCPAGs_perproc_func(pe->pe_proc);
833 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
835 afs_osi_TraverseProcTable(void)
838 LIST_FOREACH(p, &allproc, p_list) {
839 if (p->p_stat == SIDL)
841 if (p->p_stat == SZOMB)
843 if (p->p_flag & P_SYSTEM)
845 afs_GCPAGs_perproc_func(p);
850 #if defined(AFS_LINUX22_ENV)
852 afs_osi_TraverseProcTable()
854 struct task_struct *p;
856 #ifdef EXPORTED_TASKLIST_LOCK
857 read_lock(&tasklist_lock);
859 #ifdef DEFINED_FOR_EACH_PROCESS
860 for_each_process(p) if (p->pid) {
861 if (p->state & TASK_ZOMBIE)
863 afs_GCPAGs_perproc_func(p);
866 for_each_task(p) if (p->pid) {
867 if (p->state & TASK_ZOMBIE)
869 afs_GCPAGs_perproc_func(p);
872 #ifdef EXPORTED_TASKLIST_LOCK
873 read_unlock(&tasklist_lock);
878 /* return a pointer (sometimes a static copy ) to the cred for a
880 * subsequent calls may overwrite the previously returned value.
883 #if defined(AFS_SGI65_ENV)
884 const struct AFS_UCRED *
885 afs_osi_proc2cred(AFS_PROC * p)
889 #elif defined(AFS_HPUX_ENV)
890 const struct AFS_UCRED *
891 afs_osi_proc2cred(AFS_PROC * p)
897 * Cannot use afs_warnuser() here, as the code path
898 * eventually wants to grab sched_lock, which is
904 #elif defined(AFS_AIX_ENV)
906 /* GLOBAL DECLARATIONS */
909 * LOCKS: the caller must do
910 * simple_lock(&proc_tbl_lock);
911 * simple_unlock(&proc_tbl_lock);
912 * around calls to this function.
915 const struct AFS_UCRED *
916 afs_osi_proc2cred(AFS_PROC * pproc)
918 struct AFS_UCRED *pcred = 0;
921 * pointer to process user structure valid in *our*
924 * The user structure for a process is stored in the user
925 * address space (as distinct from the kernel address
926 * space), and so to refer to the user structure of a
927 * different process we must employ special measures.
929 * I followed the example used in the AIX getproc() system
930 * call in bos/kernel/proc/getproc.c
932 struct user *xmem_userp;
934 struct xmem dp; /* ptr to xmem descriptor */
935 int xm; /* xmem result */
942 * The process private segment in which the user
943 * area is located may disappear. We need to increment
944 * its use count. Therefore we
945 * - get the proc_tbl_lock to hold the segment.
946 * - get the p_lock to lockout vm_cleardata.
947 * - vm_att to load the segment register (no check)
948 * - xmattach to bump its use count.
949 * - release the p_lock.
950 * - release the proc_tbl_lock.
951 * - do whatever we need.
952 * - xmdetach to decrement the use count.
953 * - vm_det to free the segment register (no check)
958 /* simple_lock(&proc_tbl_lock); */
960 if (pproc->p_adspace != vm_handle(NULLSEGID, (int32long64_t) 0)) {
962 if (pproc->p_adspace != NULLSEGVAL) {
966 simple_lock(&pproc->p_pvprocp->pv_lock);
968 simple_lock(&pproc->p_lock);
971 if (pproc->p_threadcount &&
973 pproc->p_pvprocp->pv_threadlist) {
975 pproc->p_threadlist) {
979 * arbitrarily pick the first thread in pproc
981 struct thread *pproc_thread =
983 pproc->p_pvprocp->pv_threadlist;
989 * location of 'struct user' in pproc's
992 struct user *pproc_userp = pproc_thread->t_userp;
995 * create a pointer valid in my own address space
998 xmem_userp = (struct user *)vm_att(pproc->p_adspace, pproc_userp);
1000 dp.aspace_id = XMEM_INVAL;
1001 xm = xmattach(xmem_userp, sizeof(*xmem_userp), &dp, SYS_ADSPACE);
1004 #ifdef AFS_AIX51_ENV
1005 simple_unlock(&pproc->p_pvprocp->pv_lock);
1007 simple_unlock(&pproc->p_lock);
1010 /* simple_unlock(&proc_tbl_lock); */
1011 if (xm == XMEM_SUCC) {
1013 static struct AFS_UCRED cred;
1016 * What locking should we use to protect access to the user
1017 * area? If needed also change the code in AIX/osi_groups.c.
1020 /* copy cred to local address space */
1021 cred = *xmem_userp->U_cred;
1027 vm_det((void *)xmem_userp);
1033 #elif defined(AFS_OSF_ENV)
1034 const struct AFS_UCRED *
1035 afs_osi_proc2cred(AFS_PROC * pr)
1037 struct AFS_UCRED *rv = NULL;
1043 if ((pr->p_stat == SSLEEP) || (pr->p_stat == SRUN)
1044 || (pr->p_stat == SSTOP))
1049 #elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1050 const struct AFS_UCRED *
1051 afs_osi_proc2cred(AFS_PROC * pr)
1053 struct AFS_UCRED *rv = NULL;
1054 static struct AFS_UCRED cr;
1060 if ((pr->p_stat == SSLEEP) || (pr->p_stat == SRUN)
1061 || (pr->p_stat == SSTOP)) {
1064 cr.cr_uid = pr->p_cred->pc_ucred->cr_uid;
1065 cr.cr_ngroups = pr->p_cred->pc_ucred->cr_ngroups;
1066 memcpy(cr.cr_groups, pr->p_cred->pc_ucred->cr_groups,
1067 NGROUPS * sizeof(gid_t));
1074 #elif defined(AFS_LINUX22_ENV)
1075 const struct AFS_UCRED *
1076 afs_osi_proc2cred(AFS_PROC * pr)
1078 struct AFS_UCRED *rv = NULL;
1079 static struct AFS_UCRED cr;
1085 if ((pr->state == TASK_RUNNING) || (pr->state == TASK_INTERRUPTIBLE)
1086 || (pr->state == TASK_UNINTERRUPTIBLE)
1087 || (pr->state == TASK_STOPPED)) {
1089 cr.cr_uid = pr->uid;
1090 #if defined(AFS_LINUX26_ENV)
1091 get_group_info(pr->group_info);
1092 cr.cr_group_info = pr->group_info;
1094 cr.cr_ngroups = pr->ngroups;
1095 memcpy(cr.cr_groups, pr->groups, NGROUPS * sizeof(gid_t));
1103 const struct AFS_UCRED *
1104 afs_osi_proc2cred(AFS_PROC * pr)
1106 struct AFS_UCRED *rv = NULL;
1117 #endif /* AFS_GCPAGS */