6 #if defined(HOST_WIN32) || !defined(HAVE_SYS_IPC_H) || !defined(HAVE_SYS_SEM_H)
8 int mini_wapi_hps (int argc
, char **argv
)
13 int mini_wapi_semdel (int argc
, char **argv
)
18 int mini_wapi_seminfo (int argc
, char **argv
)
26 #include <sys/types.h>
29 #include <mono/io-layer/io-layer.h>
31 /* We're digging into handle internals here... */
32 #include <mono/io-layer/handles-private.h>
33 #include <mono/io-layer/wapi-private.h>
34 #include <mono/io-layer/shared.h>
35 #include <mono/io-layer/collection.h>
37 static const gchar
*unused_details (struct _WapiHandleShared
*handle
);
38 static const gchar
*unshared_details (struct _WapiHandleShared
*handle
);
40 static const gchar
*thread_details (struct _WapiHandleShared
*handle
);
42 static const gchar
*namedmutex_details (struct _WapiHandleShared
*handle
);
43 static const gchar
*namedsem_details (struct _WapiHandleShared
*handle
);
44 static const gchar
*namedevent_details (struct _WapiHandleShared
*handle
);
45 static const gchar
*process_details (struct _WapiHandleShared
*handle
);
47 /* This depends on the ordering of the enum WapiHandleType in
48 * io-layer/wapi-private.h
50 static const gchar
* (*details
[])(struct _WapiHandleShared
*)=
53 unshared_details
, /* file */
54 unshared_details
, /* console */
55 unshared_details
, /* thread */
56 unshared_details
, /* sem */
57 unshared_details
, /* mutex */
58 unshared_details
, /* event */
59 unshared_details
, /* socket */
60 unshared_details
, /* find */
62 unshared_details
, /* pipe */
69 int mini_wapi_hps (int argc
, char **argv
)
74 _wapi_shared_layout
= _wapi_shm_attach(WAPI_SHM_DATA
);
75 if (_wapi_shared_layout
== NULL
) {
76 g_error ("Failed to attach shared memory!");
80 _wapi_fileshare_layout
= _wapi_shm_attach(WAPI_SHM_FILESHARE
);
81 if (_wapi_fileshare_layout
== NULL
) {
82 g_error ("Failed to attach fileshare shared memory!");
87 _wapi_shm_semaphores_init ();
88 _wapi_collection_init ();
89 _wapi_handle_collect ();
92 g_print ("collection: %d sem: 0x%x\n",
93 _wapi_shared_layout
->collection_count
,
94 _wapi_shared_layout
->sem_key
);
96 now
= (guint32
)(time(NULL
) & 0xFFFFFFFF);
97 for (i
= 0; i
< _WAPI_HANDLE_INITIAL_COUNT
; i
++) {
98 struct _WapiHandleShared
*shared
;
100 shared
= &_wapi_shared_layout
->handles
[i
];
101 if (shared
->type
!= WAPI_HANDLE_UNUSED
) {
102 g_print ("%3x (%3d) [%7s] %4u %s (%s)\n",
103 i
, shared
->handle_refs
,
104 _wapi_handle_typename
[shared
->type
],
105 now
- shared
->timestamp
,
106 shared
->signalled
?"Sg":"Un",
107 details
[shared
->type
](shared
));
111 g_print ("Fileshare hwm: %d\n", _wapi_fileshare_layout
->hwm
);
113 for (i
= 0; i
<= _wapi_fileshare_layout
->hwm
; i
++) {
114 struct _WapiFileShare
*file_share
;
116 file_share
= &_wapi_fileshare_layout
->share_info
[i
];
117 if (file_share
->handle_refs
> 0) {
118 g_print ("dev: 0x%llx ino: %lld open pid: %d share: 0x%x access: 0x%x refs: %d\n", (long long int)file_share
->device
, (long long int)file_share
->inode
, file_share
->opened_by_pid
, file_share
->sharemode
, file_share
->access
, file_share
->handle_refs
);
125 static const gchar
*unused_details (struct _WapiHandleShared
*handle
)
127 return("unused details");
130 static const gchar
*unshared_details (struct _WapiHandleShared
*handle
)
132 return("unshared details");
136 static const gchar
*thread_details (struct _WapiHandleShared
*handle
)
138 static gchar buf
[80];
139 struct _WapiHandle_thread
*thr
=&handle
->u
.thread
;
141 g_snprintf (buf
, sizeof(buf
),
142 "proc: %d, tid: %ld, state: %d, exit: %u, join: %d",
143 thr
->owner_pid
, thr
->id
, thr
->state
, thr
->exitstatus
,
150 static const gchar
*namedmutex_details (struct _WapiHandleShared
*handle
)
152 static gchar buf
[80];
154 struct _WapiHandle_namedmutex
*mut
=&handle
->u
.namedmutex
;
156 name
= mut
->sharedns
.name
;
158 g_snprintf (buf
, sizeof(buf
), "[%15s] own: %5d:%5ld, count: %5u",
159 name
==NULL
?(gchar
*)"":name
, mut
->pid
, mut
->tid
,
165 static const gchar
*namedsem_details (struct _WapiHandleShared
*handle
)
167 static gchar buf
[80];
169 struct _WapiHandle_namedsem
*sem
= &handle
->u
.namedsem
;
171 name
= sem
->sharedns
.name
;
173 g_snprintf (buf
, sizeof(buf
), "[%15s] val: %5u, max: %5d",
174 name
== NULL
?(gchar
*)"":name
, sem
->val
, sem
->max
);
179 static const gchar
*namedevent_details (struct _WapiHandleShared
*handle
)
181 static gchar buf
[80];
183 struct _WapiHandle_namedevent
*event
= &handle
->u
.namedevent
;
185 name
= event
->sharedns
.name
;
187 g_snprintf (buf
, sizeof(buf
), "[%15s] %s count: %5u",
188 name
== NULL
?(gchar
*)"":name
,
189 event
->manual
?"Manual":"Auto", event
->set_count
);
194 static const gchar
*process_details (struct _WapiHandleShared
*handle
)
196 static gchar buf
[80];
198 struct _WapiHandle_process
*proc
=&handle
->u
.process
;
200 name
= proc
->proc_name
;
202 g_snprintf (buf
, sizeof(buf
), "[%25.25s] pid: %5u exit: %u",
203 name
==NULL
?(gchar
*)"":name
, proc
->id
, proc
->exitstatus
);
208 /* The old handles/semdel.c */
209 int mini_wapi_semdel (int argc
, char **argv
)
213 _wapi_shared_layout
= _wapi_shm_attach(WAPI_SHM_DATA
);
214 if (_wapi_shared_layout
== FALSE
||
215 _wapi_shared_layout
->sem_key
== 0) {
219 sem_id
= semget (_wapi_shared_layout
->sem_key
, _WAPI_SHARED_SEM_COUNT
, 0600);
221 ret
= semctl (sem_id
, 0, IPC_RMID
);
223 g_message ("Error deleting semaphore: %s",
231 static void sem_explain (int sem_id
, ushort
*vals
, int which
)
235 g_print ("%d ", vals
[which
]);
236 if (vals
[which
] >= 1) {
237 g_print ("(Unlocked)");
239 pid
= semctl (sem_id
, which
, GETPID
);
241 g_print ("(Locked by %d)", pid
);
246 int mini_wapi_seminfo (int argc
, char **argv
)
252 struct semid_ds
*buf
;
255 ushort vals
[_WAPI_SHARED_SEM_COUNT
];
257 _wapi_shared_layout
= _wapi_shm_attach (WAPI_SHM_DATA
);
258 if (_wapi_shared_layout
== FALSE
||
259 _wapi_shared_layout
->sem_key
== 0) {
263 sem_id
= semget (_wapi_shared_layout
->sem_key
, _WAPI_SHARED_SEM_COUNT
, 0600);
265 g_print ("Getting values for sem: 0x%x\n",
266 _wapi_shared_layout
->sem_key
);
268 ret
= semctl (sem_id
, 0, GETALL
, arg
);
270 g_print ("Namespace: ");
271 sem_explain (sem_id
, vals
, _WAPI_SHARED_SEM_NAMESPACE
);
272 g_print ("Fileshare: ");
273 sem_explain (sem_id
, vals
, _WAPI_SHARED_SEM_FILESHARE
);
274 g_print ("Handles: ");
275 sem_explain (sem_id
, vals
,
276 _WAPI_SHARED_SEM_SHARED_HANDLES
);
277 g_print ("Count lock: ");
278 sem_explain (sem_id
, vals
,
279 _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK
);
280 g_print ("Count: %d\n",
281 vals
[_WAPI_SHARED_SEM_PROCESS_COUNT
]);