#include "wapi.h"
-#include "handles-private.h"
-#include "process-private.h"
-#include "thread-private.h"
+#include "io-trace.h"
+#include "io.h"
+
+#include "mono/utils/mono-lazy-init.h"
+#include "mono/metadata/w32handle.h"
gboolean _wapi_has_shut_down = FALSE;
void
wapi_init (void)
{
- _wapi_handle_init ();
- _wapi_shm_semaphores_init ();
_wapi_io_init ();
- wapi_processes_init ();
}
void
_wapi_has_shut_down = TRUE;
_wapi_error_cleanup ();
- _wapi_thread_cleanup ();
- wapi_processes_cleanup ();
_wapi_io_cleanup ();
- _wapi_handle_cleanup ();
-}
\ No newline at end of file
+}
+
+/* Use this instead of getpid(), to cope with linuxthreads. It's a
+ * function rather than a variable lookup because we need to get at
+ * this before share_init() might have been called. */
+static mono_lazy_init_t _wapi_pid_init_lazy = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
+static pid_t _wapi_pid;
+
+static void
+_wapi_pid_init (void)
+{
+ _wapi_pid = getpid ();
+}
+
+pid_t
+wapi_getpid (void)
+{
+ mono_lazy_initialize (&_wapi_pid_init_lazy, _wapi_pid_init);
+ return _wapi_pid;
+}
+
+/**
+ * CloseHandle:
+ * @handle: The handle to release
+ *
+ * Closes and invalidates @handle, releasing any resources it
+ * consumes. When the last handle to a temporary or non-persistent
+ * object is closed, that object can be deleted. Closing the same
+ * handle twice is an error.
+ *
+ * Return value: %TRUE on success, %FALSE otherwise.
+ */
+gboolean CloseHandle(gpointer handle)
+{
+ if (handle == INVALID_HANDLE_VALUE){
+ SetLastError (ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+ if (handle == (gpointer)0 && mono_w32handle_get_type (handle) != MONO_W32HANDLE_CONSOLE) {
+ /* Problem: because we map file descriptors to the
+ * same-numbered handle we can't tell the difference
+ * between a bogus handle and the handle to stdin.
+ * Assume that it's the console handle if that handle
+ * exists...
+ */
+ SetLastError (ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ mono_w32handle_unref (handle);
+ return TRUE;
+}