static void event_signal(gpointer handle);
static gboolean event_own (gpointer handle);
static void event_details (gpointer data);
+static const gchar* event_typename (void);
+static gsize event_typesize (void);
static void namedevent_signal (gpointer handle);
static gboolean namedevent_own (gpointer handle);
static void namedevent_details (gpointer data);
+static const gchar* namedevent_typename (void);
+static gsize namedevent_typesize (void);
struct _WapiHandleOps _wapi_event_ops = {
NULL, /* close */
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- event_details /* details */
+ event_details, /* details */
+ event_typename, /* typename */
+ event_typesize, /* typesize */
};
struct _WapiHandleOps _wapi_namedevent_ops = {
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- namedevent_details /* details */
+ namedevent_details, /* details */
+ namedevent_typename, /* typename */
+ namedevent_typesize, /* typesize */
};
static mono_once_t event_ops_once=MONO_ONCE_INIT;
namedevent->e.manual ? "TRUE" : "FALSE", namedevent->e.set_count, namedevent->sharedns.name);
}
+static const gchar* event_typename (void)
+{
+ return "Event";
+}
+
+static gsize event_typesize (void)
+{
+ return sizeof (struct _WapiHandle_event);
+}
+
+static const gchar* namedevent_typename (void)
+{
+ return "N.Event";
+}
+
+static gsize namedevent_typesize (void)
+{
+ return sizeof (struct _WapiHandle_namedevent);
+}
+
static gpointer event_handle_create (struct _WapiHandle_event *event_handle, WapiHandleType type, gboolean manual, gboolean initial)
{
gpointer handle;
gboolean alertable);
extern void _wapi_handle_ops_prewait (gpointer handle);
extern void _wapi_handle_ops_details (WapiHandleType type, gpointer data);
+extern const gchar* _wapi_handle_ops_typename (WapiHandleType type);
+extern gsize _wapi_handle_ops_typesize (WapiHandleType type);
extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles,
gpointer *handles,
&_wapi_namedevent_ops,
};
-const char *_wapi_handle_typename[] = {
- "Unused",
- "File",
- "Console",
- "Thread",
- "Sem",
- "Mutex",
- "Event",
- "Socket",
- "Find",
- "Process",
- "Pipe",
- "N.Mutex",
- "N.Sem",
- "N.Event",
- "Error!!"
-};
-
/*
* We can hold _WAPI_PRIVATE_MAX_SLOTS * _WAPI_HANDLE_INITIAL_COUNT handles.
* If 4M handles are not enough... Oh, well... we will crash.
g_free (_wapi_private_handles [i]);
}
-static size_t _wapi_handle_struct_size (WapiHandleType type)
-{
- size_t type_size;
-
- switch (type) {
- case WAPI_HANDLE_FILE: case WAPI_HANDLE_CONSOLE: case WAPI_HANDLE_PIPE:
- type_size = sizeof (struct _WapiHandle_file);
- break;
- case WAPI_HANDLE_THREAD:
- type_size = sizeof (struct _WapiHandle_thread);
- break;
- case WAPI_HANDLE_SEM:
- type_size = sizeof (struct _WapiHandle_sem);
- break;
- case WAPI_HANDLE_MUTEX:
- type_size = sizeof (struct _WapiHandle_mutex);
- break;
- case WAPI_HANDLE_EVENT:
- type_size = sizeof (struct _WapiHandle_event);
- break;
- case WAPI_HANDLE_SOCKET:
- type_size = sizeof (struct _WapiHandle_socket);
- break;
- case WAPI_HANDLE_FIND:
- type_size = sizeof (struct _WapiHandle_find);
- break;
- case WAPI_HANDLE_PROCESS:
- type_size = sizeof (struct _WapiHandle_process);
- break;
- case WAPI_HANDLE_NAMEDMUTEX:
- type_size = sizeof (struct _WapiHandle_namedmutex);
- break;
- case WAPI_HANDLE_NAMEDSEM:
- type_size = sizeof (struct _WapiHandle_namedsem);
- break;
- case WAPI_HANDLE_NAMEDEVENT:
- type_size = sizeof (struct _WapiHandle_namedevent);
- break;
-
- default:
- g_error ("Unknown WapiHandleType: %d\n", type);
- }
-
- return type_size;
-}
-
static void _wapi_handle_init_handle (WapiHandleBase *handle,
WapiHandleType type, gpointer handle_specific)
{
int thr_ret;
- int type_size;
g_assert (_wapi_has_shut_down == FALSE);
g_assert (thr_ret == 0);
if (handle_specific != NULL) {
- type_size = _wapi_handle_struct_size (type);
memcpy (&((struct _WapiHandleUnshared*) handle)->u, handle_specific,
- type_size);
+ _wapi_handle_ops_typesize (type));
}
}
g_assert (_wapi_has_shut_down == FALSE);
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating new handle of type %s", __func__,
- _wapi_handle_typename[type]);
+ _wapi_handle_ops_typename (type));
g_assert(!_WAPI_FD_HANDLE(type));
g_assert (_wapi_has_shut_down == FALSE);
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating new handle of type %s", __func__,
- _wapi_handle_typename[type]);
+ _wapi_handle_ops_typename (type));
g_assert(_WAPI_FD_HANDLE(type));
g_assert(_WAPI_SHARED_NAMESPACE(type));
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Lookup for handle named [%s] type %s", __func__,
- utf8_name, _wapi_handle_typename[type]);
+ utf8_name, _wapi_handle_ops_typename (type));
thr_ret = mono_os_mutex_lock (&scan_mutex);
g_assert (thr_ret == 0);
continue;
}
- MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: found a shared namespace handle at 0x%x (type %s)", __func__, i, _wapi_handle_typename[handle_data->type]);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: found a shared namespace handle at 0x%x (type %s)", __func__, i, _wapi_handle_ops_typename (handle_data->type));
switch (handle_data->type) {
case WAPI_HANDLE_NAMEDMUTEX: sharedns = &((struct _WapiHandleUnshared*) handle_data)->u.namedmutex.sharedns; break;
if (strcmp (sharedns->name, utf8_name) == 0) {
if (handle_data->type != type) {
/* Its the wrong type, so fail now */
- MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle 0x%x matches name but is wrong type: %s", __func__, i, _wapi_handle_typename[handle_data->type]);
+ MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle 0x%x matches name but is wrong type: %s", __func__, i, _wapi_handle_ops_typename (handle_data->type));
ret = _WAPI_HANDLE_INVALID;
goto done;
} else {
#ifdef DEBUG_REFS
g_message ("%s: %s handle %p ref now %d",
- __func__, _wapi_handle_typename[handle_data->type], handle, handle_data->ref);
+ __func__, _wapi_handle_ops_typename (handle_data->type), handle, handle_data->ref);
#endif
}
#ifdef DEBUG_REFS
g_message ("%s: %s handle %p ref now %d (destroy %s)",
- __func__, _wapi_handle_typename[handle_data->type], handle, handle_data->ref, destroy?"TRUE":"FALSE");
+ __func__, _wapi_handle_ops_typename (handle_data->type), handle, handle_data->ref, destroy?"TRUE":"FALSE");
#endif
if(destroy==TRUE) {
sizeof (struct _WapiHandleUnshared));
memset (&((struct _WapiHandleUnshared*) handle_data)->u, '\0',
- sizeof(((struct _WapiHandleUnshared*) handle_data)->u));
+ _wapi_handle_ops_typesize (type));
handle_data->type = WAPI_HANDLE_UNUSED;
}
}
+const gchar* _wapi_handle_ops_typename (WapiHandleType type)
+{
+ g_assert (handle_ops [type]);
+ g_assert (handle_ops [type]->typename);
+ return handle_ops [type]->typename ();
+}
+
+gsize _wapi_handle_ops_typesize (WapiHandleType type)
+{
+ g_assert (handle_ops [type]);
+ g_assert (handle_ops [type]->typesize);
+ return handle_ops [type]->typesize ();
+}
+
void _wapi_handle_ops_signal (gpointer handle)
{
guint32 idx = GPOINTER_TO_UINT(handle);
mono_mutex_t *mutex;
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: waiting for %p (type %s)", __func__, handle,
- _wapi_handle_typename[_wapi_handle_type (handle)]);
+ _wapi_handle_ops_typename (_wapi_handle_type (handle)));
if (alerted)
*alerted = FALSE;
g_print ("%3x [%7s] %s %d ",
i * _WAPI_HANDLE_INITIAL_COUNT + k,
- _wapi_handle_typename[handle_data->type],
+ _wapi_handle_ops_typename (handle_data->type),
handle_data->signalled?"Sg":"Un",
handle_data->ref);
_wapi_handle_ops_details (handle_data->type, &((struct _WapiHandleUnshared*)handle_data)->u);
static void file_close (gpointer handle, gpointer data);
static void file_details (gpointer data);
+static const gchar* file_typename (void);
+static gsize file_typesize (void);
static WapiFileType file_getfiletype(void);
static gboolean file_read(gpointer handle, gpointer buffer,
guint32 numbytes, guint32 *bytesread,
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- file_details /* details */
+ file_details, /* details */
+ file_typename, /* typename */
+ file_typesize, /* typesize */
};
static void console_close (gpointer handle, gpointer data);
static void console_details (gpointer data);
+static const gchar* console_typename (void);
+static gsize console_typesize (void);
static WapiFileType console_getfiletype(void);
static gboolean console_read(gpointer handle, gpointer buffer,
guint32 numbytes, guint32 *bytesread,
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- console_details /* details */
+ console_details, /* details */
+ console_typename, /* typename */
+ console_typesize, /* typesize */
};
-/* Find handle has no ops.
- */
+static const gchar* find_typename (void);
+static gsize find_typesize (void);
+
struct _WapiHandleOps _wapi_find_ops = {
NULL, /* close */
NULL, /* signal */
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- NULL /* details */
+ NULL, /* details */
+ find_typename, /* typename */
+ find_typesize, /* typesize */
};
static void pipe_close (gpointer handle, gpointer data);
static void pipe_details (gpointer data);
+static const gchar* pipe_typename (void);
+static gsize pipe_typesize (void);
static WapiFileType pipe_getfiletype (void);
static gboolean pipe_read (gpointer handle, gpointer buffer, guint32 numbytes,
guint32 *bytesread, WapiOverlapped *overlapped);
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- pipe_details /* details */
+ pipe_details, /* details */
+ pipe_typename, /* typename */
+ pipe_typesize, /* typesize */
};
static const struct {
file->attrs);
}
+static const gchar* file_typename (void)
+{
+ return "File";
+}
+
+static gsize file_typesize (void)
+{
+ return sizeof (struct _WapiHandle_file);
+}
+
static WapiFileType file_getfiletype(void)
{
return(FILE_TYPE_DISK);
file_details (data);
}
+static const gchar* console_typename (void)
+{
+ return "Console";
+}
+
+static gsize console_typesize (void)
+{
+ return sizeof (struct _WapiHandle_file);
+}
+
static WapiFileType console_getfiletype(void)
{
return(FILE_TYPE_CHAR);
return(TRUE);
}
+static const gchar* find_typename (void)
+{
+ return "Find";
+}
+
+static gsize find_typesize (void)
+{
+ return sizeof (struct _WapiHandle_find);
+}
+
static void pipe_close (gpointer handle, gpointer data)
{
struct _WapiHandle_file *pipe_handle = (struct _WapiHandle_file*)data;
file_details (data);
}
+static const gchar* pipe_typename (void)
+{
+ return "Pipe";
+}
+
+static gsize pipe_typesize (void)
+{
+ return sizeof (struct _WapiHandle_file);
+}
+
static WapiFileType pipe_getfiletype(void)
{
return(FILE_TYPE_PIPE);
static gboolean mutex_is_owned (gpointer handle);
static void mutex_prewait (gpointer handle);
static void mutex_details (gpointer data);
+static const gchar* mutex_typename (void);
+static gsize mutex_typesize (void);
static void namedmutex_signal (gpointer handle);
static gboolean namedmutex_own (gpointer handle);
static gboolean namedmutex_is_owned (gpointer handle);
static void namedmutex_prewait (gpointer handle);
static void namedmutex_details (gpointer data);
+static const gchar* namedmutex_typename (void);
+static gsize namedmutex_typesize (void);
struct _WapiHandleOps _wapi_mutex_ops = {
NULL, /* close */
mutex_is_owned, /* is_owned */
NULL, /* special_wait */
mutex_prewait, /* prewait */
- mutex_details /* details */
+ mutex_details, /* details */
+ mutex_typename, /* typename */
+ mutex_typesize, /* typesize */
};
struct _WapiHandleOps _wapi_namedmutex_ops = {
namedmutex_is_owned, /* is_owned */
NULL, /* special_wait */
namedmutex_prewait, /* prewait */
- namedmutex_details /* details */
+ namedmutex_details, /* details */
+ namedmutex_typename, /* typename */
+ namedmutex_typesize, /* typesize */
};
static mono_once_t mutex_ops_once=MONO_ONCE_INIT;
#endif
}
+static const gchar* mutex_typename (void)
+{
+ return "Mutex";
+}
+
+static gsize mutex_typesize (void)
+{
+ return sizeof (struct _WapiHandle_mutex);
+}
+
+static const gchar* namedmutex_typename (void)
+{
+ return "N.Mutex";
+}
+
+static gsize namedmutex_typesize (void)
+{
+ return sizeof (struct _WapiHandle_namedmutex);
+}
+
/* When a thread exits, any mutexes it still holds need to be signalled. */
void _wapi_mutex_abandon (gpointer handle, pid_t pid, pthread_t tid)
{
static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertable);
static void process_close (gpointer handle, gpointer data);
static void process_details (gpointer data);
+static const gchar* process_typename (void);
+static gsize process_typesize (void);
static gboolean is_pid_valid (pid_t pid);
#if !(defined(USE_OSX_LOADER) || defined(USE_BSD_LOADER) || defined(USE_HAIKU_LOADER))
NULL, /* is_owned */
process_wait, /* special_wait */
NULL, /* prewait */
- process_details /* details */
+ process_details, /* details */
+ process_typename, /* typename */
+ process_typesize, /* typesize */
};
#if HAVE_SIGACTION
process_handle->id, process_handle->exited ? "true" : "false", process_handle->exitstatus);
}
+static const gchar* process_typename (void)
+{
+ return "Process";
+}
+
+static gsize process_typesize (void)
+{
+ return sizeof (WapiHandle_process);
+}
+
#if HAVE_SIGACTION
MONO_SIGNAL_HANDLER_FUNC (static, mono_sigchld_signal_handler, (int _dummy, siginfo_t *info, void *context))
{
static void sema_signal(gpointer handle);
static gboolean sema_own (gpointer handle);
static void sema_details (gpointer data);
+static const gchar* sema_typename (void);
+static gsize sema_typesize (void);
static void namedsema_signal (gpointer handle);
static gboolean namedsema_own (gpointer handle);
static void namedsema_details (gpointer data);
+static const gchar* namedsema_typename (void);
+static gsize namedsema_typesize (void);
struct _WapiHandleOps _wapi_sem_ops = {
NULL, /* close */
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- sema_details /* details */
+ sema_details, /* details */
+ sema_typename, /* typename */
+ sema_typesize, /* typesize */
};
struct _WapiHandleOps _wapi_namedsem_ops = {
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- namedsema_details /* details */
+ namedsema_details, /* details */
+ namedsema_typename, /* typename */
+ namedsema_typesize, /* typesize */
};
static mono_once_t sem_ops_once=MONO_ONCE_INIT;
g_print ("val: %5u, max: %5d, name: \"%s\"", namedsem->s.val, namedsem->s.max, namedsem->sharedns.name);
}
+static const gchar* sema_typename (void)
+{
+ return "Semaphore";
+}
+
+static gsize sema_typesize (void)
+{
+ return sizeof (struct _WapiHandle_sem);
+}
+
+static const gchar* namedsema_typename (void)
+{
+ return "N.Semaphore";
+}
+
+static gsize namedsema_typesize (void)
+{
+ return sizeof (struct _WapiHandle_namedsem);
+}
+
static gpointer sem_handle_create (struct _WapiHandle_sem *sem_handle, WapiHandleType type, gint32 initial, gint32 max)
{
gpointer handle;
static void socket_close (gpointer handle, gpointer data);
static void socket_details (gpointer data);
+static const gchar* socket_typename (void);
+static gsize socket_typesize (void);
struct _WapiHandleOps _wapi_socket_ops = {
socket_close, /* close */
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- socket_details /* details */
+ socket_details, /* details */
+ socket_typename, /* typename */
+ socket_typesize, /* typesize */
};
static mono_once_t socket_ops_once=MONO_ONCE_INIT;
/* FIXME: do something */
}
+static const gchar* socket_typename (void)
+{
+ return "Socket";
+}
+
+static gsize socket_typesize (void)
+{
+ return sizeof (struct _WapiHandle_socket);
+}
+
static gboolean
cleanup_close (gpointer handle, gpointer data)
{
/* Called when dumping the handles */
void (*details)(gpointer data);
+
+ /* Called to get the name of the handle type */
+ const gchar* (*typename) (void);
+
+ /* Called to get the size of the handle type */
+ gsize (*typesize) (void);
};
#include <mono/io-layer/event-private.h>
#endif
static void thread_details (gpointer data);
+static const gchar* thread_typename (void);
+static gsize thread_typesize (void);
struct _WapiHandleOps _wapi_thread_ops = {
NULL, /* close */
NULL, /* is_owned */
NULL, /* special_wait */
NULL, /* prewait */
- thread_details /* details */
+ thread_details, /* details */
+ thread_typename, /* typename */
+ thread_typesize, /* typesize */
};
static mono_once_t thread_ops_once = MONO_ONCE_INIT;
thread->id, thread->owned_mutexes->len, thread->priority);
}
+static const gchar* thread_typename (void)
+{
+ return "Thread";
+}
+
+static gsize thread_typesize (void)
+{
+ return sizeof (WapiHandle_thread);
+}
+
void
_wapi_thread_cleanup (void)
{