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"
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 */
17 #include <sys/adspace.h> /* for vm_att(), vm_det() */
21 /* afs_osi_TraverseProcTable() - Walk through the systems process
22 * table, calling afs_GCPAGs_perproc_func() for each process.
26 #define max_proc v.ve_proc
29 afs_osi_TraverseProcTable(void)
35 * For binary compatibility, on AIX we need to be careful to use the
36 * proper size of a struct proc, even if it is different from what
37 * we were compiled with.
39 if (!afs_gcpags_procsize
)
43 simple_lock(&proc_tbl_lock
);
45 for (p
= (afs_proc_t
*)v
.vb_proc
, i
= 0; p
< max_proc
;
46 p
= (afs_proc_t
*)((char *)p
+ afs_gcpags_procsize
), i
++) {
49 if (p
->p_pvprocp
->pv_stat
== SNONE
)
51 if (p
->p_pvprocp
->pv_stat
== SIDL
)
53 if (p
->p_pvprocp
->pv_stat
== SEXIT
)
56 if (p
->p_stat
== SNONE
)
58 if (p
->p_stat
== SIDL
)
60 if (p
->p_stat
== SEXIT
)
66 if (PROCMASK(p
->p_pid
) != i
) {
67 afs_gcpags
= AFS_GCPAGS_EPIDCHECK
;
73 if ((p
->p_nice
< P_NICE_MIN
) || (P_NICE_MAX
< p
->p_nice
)) {
74 afs_gcpags
= AFS_GCPAGS_ENICECHECK
;
78 afs_GCPAGs_perproc_func(p
);
81 simple_unlock(&proc_tbl_lock
);
85 /* return a pointer (sometimes a static copy ) to the cred for a
87 * subsequent calls may overwrite the previously returned value.
90 /* GLOBAL DECLARATIONS */
93 * LOCKS: the caller must do
94 * simple_lock(&proc_tbl_lock);
95 * simple_unlock(&proc_tbl_lock);
96 * around calls to this function.
100 afs_osi_proc2cred(afs_proc_t
* pproc
)
102 afs_ucred_t
*pcred
= 0;
105 * pointer to process user structure valid in *our*
108 * The user structure for a process is stored in the user
109 * address space (as distinct from the kernel address
110 * space), and so to refer to the user structure of a
111 * different process we must employ special measures.
113 * I followed the example used in the AIX getproc() system
114 * call in bos/kernel/proc/getproc.c
116 struct user
*xmem_userp
;
118 struct xmem dp
; /* ptr to xmem descriptor */
119 int xm
; /* xmem result */
126 * The process private segment in which the user
127 * area is located may disappear. We need to increment
128 * its use count. Therefore we
129 * - get the proc_tbl_lock to hold the segment.
130 * - get the p_lock to lockout vm_cleardata.
131 * - vm_att to load the segment register (no check)
132 * - xmattach to bump its use count.
133 * - release the p_lock.
134 * - release the proc_tbl_lock.
135 * - do whatever we need.
136 * - xmdetach to decrement the use count.
137 * - vm_det to free the segment register (no check)
142 /* simple_lock(&proc_tbl_lock); */
144 if (pproc
->p_adspace
!= vm_handle(NULLSEGID
, (int32long64_t
) 0)) {
146 if (pproc
->p_adspace
!= NULLSEGVAL
) {
150 simple_lock(&pproc
->p_pvprocp
->pv_lock
);
152 simple_lock(&pproc
->p_lock
);
155 if (pproc
->p_threadcount
&&
157 pproc
->p_pvprocp
->pv_threadlist
) {
159 pproc
->p_threadlist
) {
163 * arbitrarily pick the first thread in pproc
165 struct thread
*pproc_thread
=
167 pproc
->p_pvprocp
->pv_threadlist
;
173 * location of 'struct user' in pproc's
176 struct user
*pproc_userp
= pproc_thread
->t_userp
;
179 * create a pointer valid in my own address space
182 xmem_userp
= (struct user
*)vm_att(pproc
->p_adspace
, pproc_userp
);
184 dp
.aspace_id
= XMEM_INVAL
;
185 xm
= xmattach(xmem_userp
, sizeof(*xmem_userp
), &dp
, SYS_ADSPACE
);
189 simple_unlock(&pproc
->p_pvprocp
->pv_lock
);
191 simple_unlock(&pproc
->p_lock
);
194 /* simple_unlock(&proc_tbl_lock); */
195 if (xm
== XMEM_SUCC
) {
197 static afs_ucred_t cred
;
200 * What locking should we use to protect access to the user
201 * area? If needed also change the code in AIX/osi_groups.c.
204 /* copy cred to local address space */
205 cred
= *xmem_userp
->U_cred
;
211 vm_det((void *)xmem_userp
);
218 #endif /* AFS_GCPAGS */