2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / handles / hps.c
index fa1f5032ffca4a653ca0ffa4a83d3ffc8beb9522..4b704ade0feb46321485bd230d7e233fdc780c6d 100644 (file)
@@ -17,6 +17,7 @@ static const guchar *event_details (struct _WapiHandleShared *handle);
 static const guchar *socket_details (struct _WapiHandleShared *handle);
 static const guchar *find_details (struct _WapiHandleShared *handle);
 static const guchar *process_details (struct _WapiHandleShared *handle);
+static const guchar *pipe_details (struct _WapiHandleShared *handle);
 
 /* This depends on the ordering of the enum WapiHandleType in
  * io-layer/wapi-private.h
@@ -32,6 +33,7 @@ static const char *typename[]={
        "Socket",
        "Find",
        "Process",
+       "Pipe",
        "Error!!"
 };
 
@@ -48,21 +50,38 @@ static const guchar * (*details[])(struct _WapiHandleShared *)=
        socket_details,
        find_details,
        process_details,
+       pipe_details,
        unused_details,
 };
 
 int main (int argc, char **argv)
 {
-       guint32 idx;
+       guint32 handle_idx;
+       gboolean success;
        
-       _wapi_shared_data=_wapi_shm_attach (FALSE);
+       _wapi_shared_data=g_new0 (struct _WapiHandleShared_list *, 1);
+       _wapi_shared_scratch=g_new0 (struct _WapiHandleScratch, 1);
+       
+       success=_wapi_shm_attach (&_wapi_shared_data[0],
+                                 &_wapi_shared_scratch);
+       if(success==FALSE) {
+               g_error ("Failed to attach shared memory!");
+               exit (-1);
+       }
        
        /* Make sure index 0 is actually unused */
-       for(idx=0; idx<_WAPI_MAX_HANDLES; idx++) {
-               struct _WapiHandleShared *shared=&_wapi_shared_data->handles[idx];
+       for(handle_idx=0; handle_idx<_wapi_shared_data[0]->num_segments * _WAPI_HANDLES_PER_SEGMENT; handle_idx++) {
+               guint32 segment, idx;
+               struct _WapiHandleShared *shared;
+
+               _wapi_handle_segment (GUINT_TO_POINTER (handle_idx), &segment,
+                                     &idx);
+               _wapi_handle_ensure_mapped (segment);
+               
+               shared=&_wapi_shared_data[segment]->handles[idx];
                
                if(shared->type!=WAPI_HANDLE_UNUSED) {
-                       g_print ("%4x [%7s] %4u %s (%s)\n", idx,
+                       g_print ("%6x [%7s] %4u %s (%s)\n", handle_idx,
                                 typename[shared->type], shared->ref,
                                 shared->signalled?"Sg":"Un",
                                 details[shared->type](shared));
@@ -83,7 +102,7 @@ static const guchar *file_details (struct _WapiHandleShared *handle)
        guchar *name;
        struct _WapiHandle_file *file=&handle->u.file;
        
-       name=_wapi_handle_scratch_lookup_as_string (file->filename);
+       name=_wapi_handle_scratch_lookup (file->filename);
        
        g_snprintf (buf, sizeof(buf),
                    "[%20s] acc: %c%c%c, shr: %c%c%c, attrs: %5u",
@@ -114,9 +133,8 @@ static const guchar *thread_details (struct _WapiHandleShared *handle)
        struct _WapiHandle_thread *thr=&handle->u.thread;
 
        g_snprintf (buf, sizeof(buf),
-                   "proc: %p, state: %d, exit: %u, join: %s",
-                   thr->process_handle, thr->state, thr->exitstatus,
-                   thr->joined?"TRUE":"FALSE");
+                   "proc: %p, state: %d, exit: %u",
+                   thr->process_handle, thr->state, thr->exitstatus);
        
        return(buf);
 }
@@ -138,7 +156,7 @@ static const guchar *mutex_details (struct _WapiHandleShared *handle)
        guchar *name;
        struct _WapiHandle_mutex *mut=&handle->u.mutex;
        
-       name=_wapi_handle_scratch_lookup_as_string (mut->name);
+       name=_wapi_handle_scratch_lookup (mut->sharedns.name);
        
        g_snprintf (buf, sizeof(buf), "[%20s] own: %5d:%5ld, count: %5u",
                    name==NULL?(guchar *)"":name, mut->pid, mut->tid,
@@ -170,22 +188,29 @@ static const guchar *socket_details (struct _WapiHandleShared *handle)
 
 static const guchar *find_details (struct _WapiHandleShared *handle)
 {
-       static guchar buf[80];
-       struct _WapiHandle_find *find=&handle->u.find;
-       
-       g_snprintf (buf, sizeof(buf), "count: %5d",
-                   find->count);
-       
-       return(buf);
+       /* Nothing to see here either */
+       return("");
 }
 
 static const guchar *process_details (struct _WapiHandleShared *handle)
 {
        static guchar buf[80];
+       guchar *name;
        struct _WapiHandle_process *proc=&handle->u.process;
        
-       g_snprintf (buf, sizeof(buf), "pid: %5u",
-                   proc->id);
+       name=_wapi_handle_scratch_lookup (proc->proc_name);
+       
+       g_snprintf (buf, sizeof(buf), "[%20s] pid: %5u",
+                   name==NULL?(guchar *)"":name, proc->id);
+
+       if(name!=NULL) {
+               g_free (name);
+       }
        
        return(buf);
 }
+
+static const guchar *pipe_details (struct _WapiHandleShared *handle)
+{
+       return(file_details (handle));
+}