They are not used by the rest of the runtime and we only need a bare minimum of w32process and w32file in eventpipe (e.g. no file share/access logic).
Fix ep-test build and warnings, it was missing linking against libz and monoapi.
Fix host vs. target confusion in ep-rt-mono.c
Move initialization of num_main_args after setting main_args in object.c so we can use it as a cheap guard value (not totally thread-safe but good enough for our purposes).
Co-authored-by: Johan Lorensson <lateralusx.github@gmail.com>
/src/mono/mono/metadata/thread* @lateralusX @lambdageek
/src/mono/mono/metadata/w32* @lateralusX @lambdageek
+/src/mono/mono/eventpipe @lateralusX @lambdageek
+
/src/mono/mono/mini @vargaz @lambdageek @SamMonoRT
/src/mono/mono/mini/*cfgdump* @vargaz
/src/mono/mono/mini/*exceptions* @vargaz @BrzVlad
/* Host Platform is Darwin */
#cmakedefine HOST_DARWIN 1
+/* Host Platform is OSX or Mac Catalyst */
+#cmakedefine HOST_OSX 1
+
/* Host Platform is iOS */
#cmakedefine HOST_IOS 1
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#cmakedefine HAVE_SYS_SYSCTL_H 1
-/* Define to 1 if you have the <libproc.h> header file. */
-#cmakedefine HAVE_LIBPROC_H 1
-
/* Define to 1 if you have the <sys/prctl.h> header file. */
#cmakedefine HAVE_SYS_PRCTL_H 1
/* Define to 1 if you have the `getpwuid_r' function. */
#cmakedefine HAVE_GETPWUID_R 1
-/* Define to 1 if you have the `readlink' function. */
-#cmakedefine HAVE_READLINK 1
-
/* Define to 1 if you have the `chmod' function. */
#cmakedefine HAVE_CHMOD 1
/* The JIT/AOT targets Mac Catalyst */
#cmakedefine TARGET_MACCAT 1
-/* The JIT/AOT targets OSX */
+/* The JIT/AOT targets OSX or Mac Catalyst */
#cmakedefine TARGET_OSX 1
/* The JIT/AOT targets Apple platforms */
sys/types.h sys/stat.h sys/filio.h sys/sockio.h sys/utime.h sys/un.h sys/syscall.h sys/uio.h sys/param.h
sys/prctl.h sys/socket.h sys/utsname.h sys/select.h sys/poll.h sys/wait.h sts/auxv.h sys/resource.h
sys/ioctl.h sys/errno.h sys/sendfile.h sys/statvfs.h sys/statfs.h sys/mman.h sys/mount.h sys/time.h sys/random.h
- strings.h stdint.h unistd.h signal.h setjmp.h syslog.h netdb.h utime.h semaphore.h libproc.h alloca.h ucontext.h pwd.h elf.h
+ strings.h stdint.h unistd.h signal.h setjmp.h syslog.h netdb.h utime.h semaphore.h alloca.h ucontext.h pwd.h elf.h
gnu/lib-names.h netinet/tcp.h netinet/in.h link.h arpa/inet.h unwind.h poll.h wchar.h linux/magic.h
android/legacy_signal_inlines.h execinfo.h pthread.h pthread_np.h net/if.h dirent.h
CommonCrypto/CommonDigest.h dlfcn.h getopt.h pwd.h alloca.h
ac_check_funcs (
sigaction kill clock_nanosleep backtrace_symbols mkstemp mmap
getrusage dladdr sysconf getrlimit prctl nl_langinfo
- sched_getaffinity sched_setaffinity getpwuid_r readlink chmod lstat getdtablesize ftruncate msync
+ sched_getaffinity sched_setaffinity getpwuid_r chmod lstat getdtablesize ftruncate msync
getpeername utime utimes openlog closelog atexit popen strerror_r inet_pton inet_aton
shm_open poll getfsstat mremap posix_fadvise vsnprintf sendfile statfs statvfs setpgid system
fork execv execve waitpid localtime_r mkdtemp getrandom execvp strlcpy stpcpy strtok_r rewinddir
#include <mono/mini/mini-runtime.h>
#include <mono/sgen/sgen-conf.h>
#include <mono/sgen/sgen-tagged-pointer.h>
-#include "mono/utils/mono-logger-internals.h"
+#include <mono/utils/mono-logger-internals.h>
+#include <minipal/getexepath.h>
#include <runtime_version.h>
#include <clretwallmain.h>
uint8_t *buffer,
size_t buffer_size);
+ep_rt_file_handle_t
+ep_rt_mono_file_open_write(const ep_char8_t *path);
+
+bool
+ep_rt_mono_file_close (ep_rt_file_handle_t handle);
+
+bool
+ep_rt_mono_file_write (
+ ep_rt_file_handle_t handle,
+ const uint8_t *buffer,
+ uint32_t numbytes,
+ uint32_t *byteswritten);
+
EventPipeThread *
ep_rt_mono_thread_get_or_create (void);
return mono_rand_try_get_bytes (&_ep_rt_mono_rand_provider, (guchar *)buffer, (gssize)buffer_size, error);
}
+char *
+ep_rt_mono_get_managed_cmd_line ()
+{
+ return mono_runtime_get_managed_cmd_line ();
+}
+
+char *
+ep_rt_mono_get_os_cmd_line ()
+{
+ MONO_REQ_GC_NEUTRAL_MODE;
+
+ // we only return the native host here since getting the full commandline is complicated and
+ // it's not super important to have the correct value since it'll only be used during startup
+ // until we have the managed commandline
+ char *host_path = minipal_getexepath ();
+
+ // minipal_getexepath doesn't use Mono APIs to allocate strings so
+ // we can't use g_free (which the callers of this method expect to do)
+ // so create another copy and return that one
+ char *res = g_strdup (host_path);
+ free (host_path);
+ return res;
+}
+
+#ifdef HOST_WIN32
+
+ep_rt_file_handle_t
+ep_rt_mono_file_open_write (const ep_char8_t *path)
+{
+ if (!path)
+ return INVALID_HANDLE_VALUE;
+
+ ep_char16_t *path_utf16 = ep_rt_utf8_to_utf16_string (path, -1);
+
+ if (!path_utf16)
+ return INVALID_HANDLE_VALUE;
+
+ ep_rt_file_handle_t res;
+ MONO_ENTER_GC_SAFE;
+ res = (ep_rt_file_handle_t)CreateFileW (path_utf16, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ MONO_EXIT_GC_SAFE;
+ ep_rt_utf16_string_free (path_utf16);
+
+ return res;
+}
+
+bool
+ep_rt_mono_file_close (ep_rt_file_handle_t handle)
+{
+ bool res;
+ MONO_ENTER_GC_SAFE;
+ res = CloseHandle (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
+}
+
+static
+void
+win32_io_interrupt_handler (void *ignored)
+{
+}
+
+bool
+ep_rt_mono_file_write (
+ ep_rt_file_handle_t handle,
+ const uint8_t *buffer,
+ uint32_t numbytes,
+ uint32_t *byteswritten)
+{
+ MONO_REQ_GC_UNSAFE_MODE;
+
+ bool res;
+ MonoThreadInfo *info = mono_thread_info_current ();
+ gboolean alerted = FALSE;
+
+ if (info) {
+ mono_thread_info_install_interrupt (win32_io_interrupt_handler, NULL, &alerted);
+ if (alerted) {
+ return false;
+ }
+ mono_win32_enter_blocking_io_call (info, handle);
+ }
+
+ MONO_ENTER_GC_SAFE;
+ if (info && mono_thread_info_is_interrupt_state (info)) {
+ res = false;
+ } else {
+ res = WriteFile (handle, buffer, numbytes, (PDWORD)byteswritten, NULL) ? true : false;
+ }
+ MONO_EXIT_GC_SAFE;
+
+ if (info) {
+ mono_win32_leave_blocking_io_call (info, handle);
+ mono_thread_info_uninstall_interrupt (&alerted);
+ }
+
+ return res;
+}
+
+#else
+
+#include <fcntl.h>
+#include <unistd.h>
+
+ep_rt_file_handle_t
+ep_rt_mono_file_open_write (const ep_char8_t *path)
+{
+ int fd;
+ mode_t perms = 0666;
+
+ if (!path)
+ return INVALID_HANDLE_VALUE;
+
+ MONO_ENTER_GC_SAFE;
+ fd = creat (path, perms);
+ MONO_EXIT_GC_SAFE;
+
+ if (fd == -1)
+ return INVALID_HANDLE_VALUE;
+
+ return (ep_rt_file_handle_t)(ptrdiff_t)fd;
+}
+
+bool
+ep_rt_mono_file_close (ep_rt_file_handle_t handle)
+{
+ int fd = (int)(ptrdiff_t)handle;
+
+ MONO_ENTER_GC_SAFE;
+ close (fd);
+ MONO_EXIT_GC_SAFE;
+
+ return true;
+}
+
+bool
+ep_rt_mono_file_write (
+ ep_rt_file_handle_t handle,
+ const uint8_t *buffer,
+ uint32_t numbytes,
+ uint32_t *byteswritten)
+{
+ MONO_REQ_GC_UNSAFE_MODE;
+
+ int fd = (int)(ptrdiff_t)handle;
+ uint32_t ret;
+ MonoThreadInfo *info = mono_thread_info_current ();
+
+ if (byteswritten != NULL)
+ *byteswritten = 0;
+
+ do {
+ MONO_ENTER_GC_SAFE;
+ ret = write (fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
+ } while (ret == -1 && errno == EINTR &&
+ !mono_thread_info_is_interrupt_state (info));
+
+ if (ret == -1) {
+ if (errno == EINTR)
+ ret = 0;
+ else
+ return false;
+ }
+
+ if (byteswritten != NULL)
+ *byteswritten = ret;
+
+ return true;
+}
+
+#endif // HOST_WIN32
+
EventPipeThread *
ep_rt_mono_thread_get_or_create (void)
{
static const int64_t MSECS_TO_MIS = 1000;
/* clock_gettime () is found by configure on Apple builds, but its only present from ios 10, macos 10.12, tvos 10 and watchos 3 */
-#if defined (HAVE_CLOCK_MONOTONIC) && (defined(TARGET_IOS) || defined(TARGET_OSX) || defined(TARGET_WATCHOS) || defined(TARGET_TVOS))
+#if defined (HAVE_CLOCK_MONOTONIC) && (defined(HOST_IOS) || defined(HOST_OSX) || defined(HOST_WATCHOS) || defined(HOST_TVOS))
#undef HAVE_CLOCK_MONOTONIC
#endif
#ifndef HOST_WIN32
#if defined(__APPLE__)
-#if defined (TARGET_OSX)
+#if defined (HOST_OSX)
G_BEGIN_DECLS
gchar ***_NSGetEnviron(void);
G_END_DECLS
#else
static char *_ep_rt_mono_environ[1] = { NULL };
#define environ _ep_rt_mono_environ
-#endif /* defined (TARGET_OSX) */
+#endif /* defined (HOST_OSX) */
#else
G_BEGIN_DECLS
extern char **environ;
#include <mono/utils/mono-lazy-init.h>
#include <mono/utils/w32api.h>
#include <mono/metadata/assembly.h>
-#include <mono/metadata/w32file.h>
#include <mono/metadata/w32event.h>
-#include <mono/metadata/environment-internals.h>
#include <mono/metadata/metadata-internals.h>
#include <runtime_version.h>
#include <mono/metadata/profiler.h>
extern char *_ep_rt_mono_managed_cmd_line;
extern mono_lazy_init_t _ep_rt_mono_managed_cmd_line_init;
extern ep_rt_spin_lock_handle_t _ep_rt_mono_config_lock;
+extern char * ep_rt_mono_get_managed_cmd_line (void);
+extern char * ep_rt_mono_get_os_cmd_line (void);
+extern ep_rt_file_handle_t ep_rt_mono_file_open_write (const ep_char8_t *path);
+extern bool ep_rt_mono_file_close (ep_rt_file_handle_t handle);
+extern bool ep_rt_mono_file_write (ep_rt_file_handle_t handle, const uint8_t *buffer, uint32_t numbytes, uint32_t *byteswritten);
extern void * ep_rt_mono_thread_attach (bool background_thread);
extern void * ep_rt_mono_thread_attach_2 (bool background_thread, EventPipeThreadType thread_type);
extern void ep_rt_mono_thread_detach (void);
char *
os_command_line_get (void)
{
- return mono_get_os_cmd_line ();
+ return ep_rt_mono_get_os_cmd_line ();
}
static
char *
managed_command_line_get (void)
{
- return mono_runtime_get_managed_cmd_line ();
+ return ep_rt_mono_get_managed_cmd_line ();
}
static
static
inline
-gpointer
-ep_rt_mono_w32file_create (const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
-{
- //TODO, replace with low level PAL implementation.
- return mono_w32file_create (name, fileaccess, sharemode, createmode, attrs);
-}
-
-static
-inline
-gboolean
-ep_rt_mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten, gint32 *win32error)
-{
- //TODO, replace with low level PAL implementation.
- return mono_w32file_write (handle, buffer, numbytes, byteswritten, win32error);
-}
-
-static
-inline
-gboolean
-ep_rt_mono_w32file_close (gpointer handle)
-{
- //TODO, replace with low level PAL implementation.
- return mono_w32file_close (handle);
-}
-
-static
-inline
void
ep_rt_mono_thread_setup (bool background_thread)
{
ep_rt_file_handle_t
ep_rt_file_open_write (const ep_char8_t *path)
{
- ep_char16_t *path_utf16 = ep_rt_utf8_to_utf16_string (path, -1);
- ep_return_null_if_nok (path_utf16 != NULL);
-
- gpointer file_handle = ep_rt_mono_w32file_create ((gunichar2 *)path_utf16, GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FileAttributes_Normal);
- ep_rt_utf16_string_free (path_utf16);
+ ep_rt_file_handle_t res = ep_rt_mono_file_open_write (path);
- return file_handle;
+ return (res != INVALID_HANDLE_VALUE) ? res : NULL;
}
static
ep_rt_file_close (ep_rt_file_handle_t file_handle)
{
ep_return_false_if_nok (file_handle != NULL);
- return ep_rt_mono_w32file_close (file_handle);
+ return ep_rt_mono_file_close (file_handle);
}
static
ep_return_false_if_nok (file_handle != NULL);
EP_ASSERT (buffer != NULL);
- gint32 win32_error;
- bool result = ep_rt_mono_w32file_write (file_handle, buffer, bytes_to_write, bytes_written, &win32_error);
+ bool result = ep_rt_mono_file_write (file_handle, buffer, bytes_to_write, bytes_written);
if (result)
*bytes_written = bytes_to_write;
{
const ep_char8_t * cmd_line = ep_rt_managed_command_line_get ();
+ // if the managed command line isn't available yet (e.g. because we're during runtime startup) then fallback to the OS command line.
// Checkout https://github.com/dotnet/coreclr/pull/24433 for more information about this fall back.
if (cmd_line == NULL)
cmd_line = ep_rt_os_command_line_get ();
set(CMAKE_SKIP_RPATH 1)
add_executable(ep-test ${EVENTPIPE_TEST_SOURCES} ${EVENTPIPE_TEST_HEADERS})
target_sources(ep-test PRIVATE "${mono-components-objects}")
- target_link_libraries(ep-test monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS})
+ target_link_libraries(ep-test monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS} monoapi)
if(ICU_LDFLAGS)
set_target_properties(ep-test PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
endif()
event_data_len = ARRAY_SIZE (TEST_EVENT_DATA);
}
if (event_data) {
- ep_event_payload_init (&payload, (uint8_t *)event_data, event_data_len);
+ ep_event_payload_init (&payload, (uint8_t *)event_data, (uint32_t)event_data_len);
result = ep_buffer_write_event (buffer, ep_rt_thread_get_handle (), session, ep_event, &payload, NULL, NULL, NULL);
ep_event_payload_fini (&payload);
endif()
set(metadata_win32_sources
- w32file-win32.c
w32event-win32.c
w32error-win32.c)
set(metadata_unix_sources
w32event-unix.c
- w32process-unix-osx.c
- w32process-unix-bsd.c
- w32process-unix-haiku.c
- w32process-unix-default.c
- w32file-unix.c
w32error-unix.c)
if(HOST_WIN32)
environment.c
exception.c
exception-internals.h
- w32file.h
gc-internals.h
gc_wrapper.h
icall.c
opcodes.c
property-bag.h
property-bag.c
- w32process.h
profiler.c
profiler-private.h
runtime.c
sre.c
sre-encode.c
custom-attrs.c
- fdhandle.h
- fdhandle.c
callspec.h
callspec.c
assembly-load-context.c
#include <mono/metadata/marshal.h>
#include <mono/metadata/marshal-internals.h>
#include <mono/metadata/monitor.h>
-#include <mono/metadata/w32file.h>
#include <mono/metadata/lock-tracer.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/tokentype.h>
#include <mono/utils/atomic.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-threads.h>
-#include <mono/metadata/w32handle.h>
-#include <mono/metadata/w32error.h>
#include <mono/utils/w32api.h>
#include <mono/metadata/components.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/runtime.h>
#include <mono/metadata/w32event.h>
-#include <mono/metadata/w32file.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/coree.h>
#endif
mono_w32event_init ();
- mono_w32file_init ();
#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters_init ();
+++ /dev/null
-/**
- * \file
- *
- * Copyright 2020 Microsoft
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-#ifndef _MONO_METADATA_ENVIRONMENT_INTERNALS_H_
-#define _MONO_METADATA_ENVIRONMENT_INTERNALS_H_
-
-#include <mono/utils/mono-compiler.h>
-
-void
-mono_set_os_args (int argc, char **argv);
-
-MONO_COMPONENT_API char *
-mono_get_os_cmd_line (void);
-
-#endif /* _MONO_METADATA_ENVIRONMENT_INTERNALS_H_ */
#include <mono/metadata/appdomain.h>
#include <mono/metadata/environment.h>
-#include <mono/metadata/environment-internals.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/handle.h>
#include <mono/utils/mono-compiler.h>
{
exitcode=value;
}
-
-static int mini_argc = 0;
-static char **mini_argv = NULL;
-
-void
-mono_set_os_args (int argc, char **argv)
-{
- mini_argc = argc;
- mini_argv = argv;
-}
-
-char *
-mono_get_os_cmd_line (void)
-{
- return mono_runtime_get_cmd_line (mini_argc, mini_argv);
-}
+++ /dev/null
-
-#include "fdhandle.h"
-#include "utils/mono-lazy-init.h"
-#include "utils/mono-coop-mutex.h"
-
-static GHashTable *fds;
-static MonoCoopMutex fds_mutex;
-static MonoFDHandleCallback fds_callback[MONO_FDTYPE_COUNT];
-static mono_lazy_init_t fds_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
-
-#ifndef DISABLE_ASSERT_MESSAGES
-static const gchar *types_str[] = {
- "File",
- "Console",
- "Pipe",
- "Socket",
- NULL
-};
-#endif
-
-static void
-fds_remove (gpointer data)
-{
- MonoFDHandle* fdhandle;
-
- fdhandle = (MonoFDHandle*) data;
- g_assert (fdhandle);
-
- g_assert (fds_callback [fdhandle->type].close);
- fds_callback [fdhandle->type].close (fdhandle);
-
- mono_refcount_dec (fdhandle);
-}
-
-static void
-initialize (void)
-{
- fds = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, fds_remove);
- mono_coop_mutex_init (&fds_mutex);
-}
-
-void
-mono_fdhandle_register (MonoFDType type, MonoFDHandleCallback *callback)
-{
- mono_lazy_initialize (&fds_init, initialize);
- memcpy (&fds_callback [type], callback, sizeof (MonoFDHandleCallback));
-}
-
-static void
-fdhandle_destroy (gpointer data)
-{
- MonoFDHandle* fdhandle;
-
- fdhandle = (MonoFDHandle*) data;
- g_assert (fdhandle);
-
- g_assert (fds_callback [fdhandle->type].destroy);
- fds_callback [fdhandle->type].destroy (fdhandle);
-}
-
-void
-mono_fdhandle_init (MonoFDHandle *fdhandle, MonoFDType type, gint fd)
-{
- mono_refcount_init (fdhandle, fdhandle_destroy);
- fdhandle->type = type;
- fdhandle->fd = fd;
-}
-
-void
-mono_fdhandle_insert (MonoFDHandle *fdhandle)
-{
- mono_coop_mutex_lock (&fds_mutex);
-
- if (g_hash_table_lookup_extended (fds, GINT_TO_POINTER(fdhandle->fd), NULL, NULL))
- g_error("%s: duplicate %s fd %d", __func__, types_str [fdhandle->type], fdhandle->fd);
-
- g_hash_table_insert (fds, GINT_TO_POINTER(fdhandle->fd), fdhandle);
-
- mono_coop_mutex_unlock (&fds_mutex);
-}
-
-gboolean
-mono_fdhandle_try_insert (MonoFDHandle *fdhandle)
-{
- mono_coop_mutex_lock (&fds_mutex);
-
- if (g_hash_table_lookup_extended (fds, GINT_TO_POINTER(fdhandle->fd), NULL, NULL)) {
- /* we raced between 2 invocations of mono_fdhandle_try_insert */
- mono_coop_mutex_unlock (&fds_mutex);
-
- return FALSE;
- }
-
- g_hash_table_insert (fds, GINT_TO_POINTER(fdhandle->fd), fdhandle);
-
- mono_coop_mutex_unlock (&fds_mutex);
-
- return TRUE;
-}
-
-gboolean
-mono_fdhandle_lookup_and_ref (gint fd, MonoFDHandle **fdhandle)
-{
- mono_coop_mutex_lock (&fds_mutex);
-
- if (!g_hash_table_lookup_extended (fds, GINT_TO_POINTER(fd), NULL, (gpointer*) fdhandle)) {
- mono_coop_mutex_unlock (&fds_mutex);
- return FALSE;
- }
-
- mono_refcount_inc (*fdhandle);
-
- mono_coop_mutex_unlock (&fds_mutex);
-
- return TRUE;
-}
-
-void
-mono_fdhandle_unref (MonoFDHandle *fdhandle)
-{
- mono_refcount_dec (fdhandle);
-}
-
-gboolean
-mono_fdhandle_close (gint fd)
-{
- MonoFDHandle *fdhandle;
- gboolean removed;
-
- mono_coop_mutex_lock (&fds_mutex);
-
- if (!g_hash_table_lookup_extended (fds, GINT_TO_POINTER(fd), NULL, (gpointer*) &fdhandle)) {
- mono_coop_mutex_unlock (&fds_mutex);
-
- return FALSE;
- }
-
- removed = g_hash_table_remove (fds, GINT_TO_POINTER(fdhandle->fd));
- g_assert (removed);
-
- mono_coop_mutex_unlock (&fds_mutex);
-
- return TRUE;
-}
+++ /dev/null
-
-#ifndef __MONO_METADATA_FDHANDLE_H__
-#define __MONO_METADATA_FDHANDLE_H__
-
-#include <config.h>
-#include <glib.h>
-
-#include "utils/refcount.h"
-
-typedef enum {
- MONO_FDTYPE_FILE,
- MONO_FDTYPE_CONSOLE,
- MONO_FDTYPE_PIPE,
- MONO_FDTYPE_SOCKET,
- MONO_FDTYPE_COUNT
-} MonoFDType;
-
-typedef struct {
- MonoRefCount ref;
- MonoFDType type;
- gint fd;
-} MonoFDHandle;
-
-typedef struct {
- void (*close) (MonoFDHandle *fdhandle);
- void (*destroy) (MonoFDHandle *fdhandle);
-} MonoFDHandleCallback;
-
-void
-mono_fdhandle_register (MonoFDType type, MonoFDHandleCallback *callback);
-
-void
-mono_fdhandle_init (MonoFDHandle *fdhandle, MonoFDType type, gint fd);
-
-void
-mono_fdhandle_insert (MonoFDHandle *fdhandle);
-
-gboolean
-mono_fdhandle_try_insert (MonoFDHandle *fdhandle);
-
-gboolean
-mono_fdhandle_lookup_and_ref (gint fd, MonoFDHandle **fdhandle);
-
-void
-mono_fdhandle_unref (MonoFDHandle *fdhandle);
-
-gboolean
-mono_fdhandle_close (gint fd);
-
-#endif /* __MONO_METADATA_FDHANDLE_H__ */
#include "mono/utils/mono-digest.h"
#include "mono/utils/mono-forward-internal.h"
#include "w32event.h"
-#include "w32file.h"
#include "mono/utils/mono-proclib.h"
/* From MonoProperty.cs */
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/exception-internals.h>
-#include <mono/metadata/w32file.h>
#include <mono/metadata/mono-endian.h>
#include <mono/metadata/tokentype.h>
#include <mono/metadata/metadata-internals.h>
#include <mono/metadata/seq-points-data.h>
#include <mono/metadata/icall-table.h>
#include <mono/metadata/handle.h>
-#include <mono/metadata/w32event.h>
#include <mono/metadata/abi-details.h>
#include <mono/metadata/loader-internals.h>
#include <mono/utils/monobitset.h>
#include <mono/utils/bsearch.h>
#include <mono/utils/mono-os-mutex.h>
#include <mono/utils/mono-threads.h>
-#include <mono/metadata/w32error.h>
#include <mono/utils/w32api.h>
#include <mono/utils/mono-logger-internals.h>
#include <mono/utils/mono-math.h>
MONO_COMPONENT_API char *
mono_runtime_get_managed_cmd_line (void);
-char *
-mono_runtime_get_cmd_line (int argc, char **argv);
-
#ifdef HOST_WASM
int
mono_string_instance_is_interned (MonoString *str);
#include <mono/metadata/environment.h>
#include "mono/metadata/profiler-private.h"
#include <mono/metadata/reflection-internals.h>
-#include <mono/metadata/w32event.h>
-#include <mono/metadata/w32process.h>
#include <mono/metadata/custom-attrs-internals.h>
#include <mono/metadata/abi-details.h>
#include <mono/metadata/runtime.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/mono-threads-coop.h>
#include <mono/utils/mono-logger-internals.h>
+#include <minipal/getexepath.h>
#include "cominterop.h"
#include <mono/utils/w32api.h>
#include <mono/utils/unlocked.h>
quote_escape_and_append_string (char *src_str, GString *target_str);
static GString *
-format_cmd_line (int argc, char **argv, gboolean add_host);
+format_cmd_line (int argc, char **argv);
/**
* mono_runtime_object_init:
free_main_args ();
main_args = g_new0 (char*, argc);
- num_main_args = argc;
for (i = 0; i < argc; ++i) {
gchar *utf8_arg;
main_args [i] = utf8_arg;
}
+ num_main_args = argc;
+
MONO_EXTERNAL_ONLY (int, 0);
}
mono_thread_set_main (mono_thread_current ());
main_args = g_new0 (char*, argc);
- num_main_args = argc;
if (!g_path_is_absolute (argv [0])) {
gchar *basename = g_path_get_basename (argv [0]);
main_args [i] = utf8_arg;
}
+
+ num_main_args = argc;
+
argc--;
argv++;
}
static GString *
-format_cmd_line (int argc, char **argv, gboolean add_host)
+format_cmd_line (int argc, char **argv)
{
+ // managed cmdline -> native host + managed argv (which includes the entrypoint assembly)
size_t total_size = 0;
char *host_path = NULL;
GString *cmd_line = NULL;
- if (add_host) {
-#if !defined(HOST_WIN32) && defined(HAVE_GETPID)
- host_path = mono_w32process_get_path (getpid ());
-#elif defined(HOST_WIN32)
- gunichar2 *host_path_ucs2 = NULL;
- guint32 host_path_ucs2_len = 0;
- if (mono_get_module_filename (NULL, &host_path_ucs2, &host_path_ucs2_len)) {
- host_path = g_utf16_to_utf8 (host_path_ucs2, -1, NULL, NULL, NULL);
- g_free (host_path_ucs2);
- }
-#endif
- }
+ host_path = minipal_getexepath ();
if (host_path)
// quote + string + quote
}
}
- g_free (host_path);
+ // minipal_getexepath doesn't use Mono APIs to allocate strings so we can't use g_free
+ free (host_path);
return cmd_line;
}
char *
-mono_runtime_get_cmd_line (int argc, char **argv)
-{
- MONO_REQ_GC_NEUTRAL_MODE;
- GString *cmd_line = format_cmd_line (num_main_args, main_args, FALSE);
- return cmd_line ? g_string_free (cmd_line, FALSE) : NULL;
-}
-
-char *
mono_runtime_get_managed_cmd_line (void)
{
MONO_REQ_GC_NEUTRAL_MODE;
- GString *cmd_line = format_cmd_line (num_main_args, main_args, TRUE);
+
+ if (num_main_args == 0)
+ return NULL;
+
+ GString *cmd_line = format_cmd_line (num_main_args, main_args);
return cmd_line ? g_string_free (cmd_line, FALSE) : NULL;
}
#include "utils/mono-logger-internals.h"
#include "utils/mono-threads-coop.h"
#include "utils/mono-threads.h"
-#include "metadata/w32handle.h"
#include "icall-decl.h"
#define OPDEF(a,b,c,d,e,f,g,h,i,j) \
return FALSE;
}
-#define MANAGED_WAIT_FAILED 0x7fffffff
-
-static gint32
-map_native_wait_result_to_managed (MonoW32HandleWaitRet val, gsize numobjects)
-{
- if (val >= MONO_W32HANDLE_WAIT_RET_SUCCESS_0 && val < MONO_W32HANDLE_WAIT_RET_SUCCESS_0 + numobjects) {
- return WAIT_OBJECT_0 + (val - MONO_W32HANDLE_WAIT_RET_SUCCESS_0);
- } else if (val >= MONO_W32HANDLE_WAIT_RET_ABANDONED_0 && val < MONO_W32HANDLE_WAIT_RET_ABANDONED_0 + numobjects) {
- return WAIT_ABANDONED_0 + (val - MONO_W32HANDLE_WAIT_RET_ABANDONED_0);
- } else if (val == MONO_W32HANDLE_WAIT_RET_ALERTED) {
- return WAIT_IO_COMPLETION;
- } else if (val == MONO_W32HANDLE_WAIT_RET_TIMEOUT) {
- return WAIT_TIMEOUT;
- } else if (val == MONO_W32HANDLE_WAIT_RET_TOO_MANY_POSTS) {
- return WAIT_TOO_MANY_POSTS;
- } else if (val == MONO_W32HANDLE_WAIT_RET_NOT_OWNED_BY_CALLER) {
- return WAIT_NOT_OWNED_BY_CALLER;
- } else if (val == MONO_W32HANDLE_WAIT_RET_FAILED) {
- /* WAIT_FAILED in waithandle.cs is different from WAIT_FAILED in Win32 API */
- return MANAGED_WAIT_FAILED;
- } else {
- g_error ("%s: unknown val value %d", __func__, val);
- }
-}
-
gint32 ves_icall_System_Threading_Interlocked_Increment_Int (gint32 *location)
{
return mono_atomic_inc_i32 (location);
+++ /dev/null
-/**
- * \file
- */
-
-#include <config.h>
-#include <glib.h>
-
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/stat.h>
-#ifdef HAVE_SYS_STATVFS_H
-#include <sys/statvfs.h>
-#endif
-#if defined(HAVE_SYS_STATFS_H)
-#include <sys/statfs.h>
-#endif
-#if defined(HAVE_SYS_PARAM_H) && defined(HAVE_SYS_MOUNT_H)
-#include <sys/param.h>
-#include <sys/mount.h>
-#endif
-#include <sys/types.h>
-#include <stdio.h>
-#ifdef HAVE_UTIME_H
-#include <utime.h>
-#endif
-#ifdef __linux__
-#include <sys/ioctl.h>
-#include <linux/fs.h>
-#include <mono/utils/linux_magic.h>
-#endif
-#ifdef _AIX
-#include <sys/mntctl.h>
-#include <sys/vmount.h>
-#endif
-#include <sys/time.h>
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#endif
-#if HOST_DARWIN
-#include <dlfcn.h>
-#endif
-
-#include "w32file.h"
-#include "w32error.h"
-#include "fdhandle.h"
-#include "utils/mono-error-internals.h"
-#include "utils/mono-logger-internals.h"
-#include "utils/mono-os-mutex.h"
-#include "utils/mono-threads.h"
-#include "utils/mono-threads-api.h"
-#include "utils/strenc-internals.h"
-#include "utils/strenc.h"
-#include "utils/refcount.h"
-#include "icall-decl.h"
-#include "utils/mono-errno.h"
-
-#define INVALID_HANDLE_VALUE ((gpointer)-1)
-
-typedef struct {
- guint64 device;
- guint64 inode;
- guint32 sharemode;
- guint32 access;
- guint32 handle_refs;
- guint32 timestamp;
-} FileShare;
-
-/* Currently used for both FILE, CONSOLE and PIPE handle types.
- * This may have to change in future. */
-typedef struct {
- MonoFDHandle fdhandle;
- gchar *filename;
- FileShare *share_info; /* Pointer into shared mem */
- guint32 security_attributes;
- guint32 fileaccess;
- guint32 sharemode;
- guint32 attrs;
-} FileHandle;
-
-/*
- * If SHM is disabled, this will point to a hash of FileShare structures, otherwise
- * it will be NULL. We use this instead of _wapi_fileshare_layout to avoid allocating a
- * 4MB array.
- */
-static GHashTable *file_share_table;
-static MonoCoopMutex file_share_mutex;
-
-static FileHandle*
-file_data_create (MonoFDType type, gint fd)
-{
- FileHandle *filehandle;
-
- filehandle = g_new0 (FileHandle, 1);
- mono_fdhandle_init ((MonoFDHandle*) filehandle, type, fd);
-
- return filehandle;
-}
-
-static gint
-_wapi_unlink (const gchar *pathname);
-
-static void
-file_share_release (FileShare *share_info);
-
-static void
-file_data_close (MonoFDHandle *fdhandle)
-{
- FileHandle* filehandle;
-
- filehandle = (FileHandle*) fdhandle;
- g_assert (filehandle);
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: closing fd %d", __func__, ((MonoFDHandle*) filehandle)->fd);
-
- if (((MonoFDHandle*) filehandle)->type == MONO_FDTYPE_FILE && (filehandle->attrs & FILE_FLAG_DELETE_ON_CLOSE)) {
- _wapi_unlink (filehandle->filename);
- }
-
- if (((MonoFDHandle*) filehandle)->type != MONO_FDTYPE_CONSOLE || ((MonoFDHandle*) filehandle)->fd > 2) {
- if (filehandle->share_info) {
- file_share_release (filehandle->share_info);
- filehandle->share_info = NULL;
- }
-
- MONO_ENTER_GC_SAFE;
- close (((MonoFDHandle*) filehandle)->fd);
- MONO_EXIT_GC_SAFE;
- }
-}
-
-static void
-file_data_destroy (MonoFDHandle *fdhandle)
-{
- FileHandle *filehandle;
-
- filehandle = (FileHandle*) fdhandle;
- g_assert (filehandle);
-
- if (filehandle->filename)
- g_free (filehandle->filename);
-
- g_free (filehandle);
-}
-
-static void
-file_share_release (FileShare *share_info)
-{
- /* Prevent new entries racing with us */
- mono_coop_mutex_lock (&file_share_mutex);
-
- g_assert (share_info->handle_refs > 0);
- share_info->handle_refs -= 1;
-
- if (share_info->handle_refs == 0) {
- g_hash_table_remove (file_share_table, share_info);
- // g_free (share_info);
- }
-
- mono_coop_mutex_unlock (&file_share_mutex);
-}
-
-static gint
-file_share_equal (gconstpointer ka, gconstpointer kb)
-{
- const FileShare *s1 = (const FileShare *)ka;
- const FileShare *s2 = (const FileShare *)kb;
-
- return (s1->device == s2->device && s1->inode == s2->inode) ? 1 : 0;
-}
-
-static guint
-file_share_hash (gconstpointer data)
-{
- const FileShare *s = (const FileShare *)data;
-
- return s->inode;
-}
-
-static gboolean
-file_share_get (guint64 device, guint64 inode, guint32 new_sharemode, guint32 new_access,
- guint32 *old_sharemode, guint32 *old_access, FileShare **share_info)
-{
- FileShare *file_share;
- gboolean exists = FALSE;
-
- /* Prevent new entries racing with us */
- mono_coop_mutex_lock (&file_share_mutex);
-
- FileShare tmp;
-
- /*
- * Instead of allocating a 4MB array, we use a hash table to keep track of this
- * info. This is needed even if SHM is disabled, to track sharing inside
- * the current process.
- */
- if (!file_share_table)
- file_share_table = g_hash_table_new_full (file_share_hash, file_share_equal, NULL, g_free);
-
- tmp.device = device;
- tmp.inode = inode;
-
- file_share = (FileShare *)g_hash_table_lookup (file_share_table, &tmp);
- if (file_share) {
- *old_sharemode = file_share->sharemode;
- *old_access = file_share->access;
- *share_info = file_share;
-
- g_assert (file_share->handle_refs > 0);
- file_share->handle_refs += 1;
-
- exists = TRUE;
- } else {
- file_share = g_new0 (FileShare, 1);
-
- file_share->device = device;
- file_share->inode = inode;
- file_share->sharemode = new_sharemode;
- file_share->access = new_access;
- file_share->handle_refs = 1;
- *share_info = file_share;
-
- g_hash_table_insert (file_share_table, file_share, file_share);
- }
-
- mono_coop_mutex_unlock (&file_share_mutex);
-
- return(exists);
-}
-
-static gint
-_wapi_open (const gchar *pathname, gint flags, mode_t mode)
-{
- gint fd;
-
- MONO_ENTER_GC_SAFE;
- fd = open (pathname, flags, mode);
- MONO_EXIT_GC_SAFE;
-
- return(fd);
-}
-
-static gint
-_wapi_access (const gchar *pathname, gint mode)
-{
- gint ret;
-
- MONO_ENTER_GC_SAFE;
- ret = access (pathname, mode);
- MONO_EXIT_GC_SAFE;
-
- return ret;
-}
-
-static gint
-_wapi_unlink (const gchar *pathname)
-{
- gint ret;
-
- MONO_ENTER_GC_SAFE;
- ret = unlink (pathname);
- MONO_EXIT_GC_SAFE;
-
- return ret;
-}
-
-static gchar*
-_wapi_dirname (const gchar *filename)
-{
- gchar *new_filename = g_strdup (filename), *ret;
-
- ret = g_path_get_dirname (new_filename);
- g_free (new_filename);
-
- return ret;
-}
-
-static void
-_wapi_set_last_error_from_errno (void)
-{
- mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
-}
-
-static void _wapi_set_last_path_error_from_errno (const gchar *dir,
- const gchar *path)
-{
- if (errno == ENOENT) {
- /* Check the path - if it's a missing directory then
- * we need to set PATH_NOT_FOUND not FILE_NOT_FOUND
- */
- gchar *dirname;
-
-
- if (dir == NULL) {
- dirname = _wapi_dirname (path);
- } else {
- dirname = g_strdup (dir);
- }
-
- if (_wapi_access (dirname, F_OK) == 0) {
- mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
- } else {
- mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
- }
-
- g_free (dirname);
- } else {
- _wapi_set_last_error_from_errno ();
- }
-}
-
-static gboolean
-file_write (FileHandle *filehandle, gpointer buffer, guint32 numbytes, guint32 *byteswritten)
-{
- gint ret;
- MonoThreadInfo *info = mono_thread_info_current ();
-
- if(byteswritten!=NULL) {
- *byteswritten=0;
- }
-
- if(!(filehandle->fileaccess & GENERIC_WRITE) && !(filehandle->fileaccess & GENERIC_ALL)) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: fd %d doesn't have GENERIC_WRITE access: %u", __func__, ((MonoFDHandle*) filehandle)->fd, filehandle->fileaccess);
-
- mono_w32error_set_last (ERROR_ACCESS_DENIED);
- return(FALSE);
- }
-
- do {
- MONO_ENTER_GC_SAFE;
- ret = write (((MonoFDHandle*) filehandle)->fd, buffer, numbytes);
- MONO_EXIT_GC_SAFE;
- } while (ret == -1 && errno == EINTR &&
- !mono_thread_info_is_interrupt_state (info));
-
- if (ret == -1) {
- if (errno == EINTR) {
- ret = 0;
- } else {
- _wapi_set_last_error_from_errno ();
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: write of fd %d error: %s", __func__, ((MonoFDHandle*) filehandle)->fd, g_strerror(errno));
-
- return(FALSE);
- }
- }
- if (byteswritten != NULL) {
- *byteswritten = ret;
- }
- return(TRUE);
-}
-
-static gboolean
-console_write (FileHandle *filehandle, gpointer buffer, guint32 numbytes, guint32 *byteswritten)
-{
- gint ret;
- MonoThreadInfo *info = mono_thread_info_current ();
-
- if(byteswritten!=NULL) {
- *byteswritten=0;
- }
-
- if(!(filehandle->fileaccess & (GENERIC_WRITE | GENERIC_ALL))) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: fd %d doesn't have GENERIC_WRITE access: %u", __func__, ((MonoFDHandle*) filehandle)->fd, filehandle->fileaccess);
-
- mono_w32error_set_last (ERROR_ACCESS_DENIED);
- return(FALSE);
- }
-
- do {
- MONO_ENTER_GC_SAFE;
- ret = write(((MonoFDHandle*) filehandle)->fd, buffer, numbytes);
- MONO_EXIT_GC_SAFE;
- } while (ret == -1 && errno == EINTR &&
- !mono_thread_info_is_interrupt_state (info));
-
- if (ret == -1) {
- if (errno == EINTR) {
- ret = 0;
- } else {
- _wapi_set_last_error_from_errno ();
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: write of fd %d error: %s", __func__, ((MonoFDHandle*) filehandle)->fd, g_strerror(errno));
-
- return(FALSE);
- }
- }
- if(byteswritten!=NULL) {
- *byteswritten=ret;
- }
-
- return(TRUE);
-}
-
-static gboolean
-pipe_write (FileHandle *filehandle, gpointer buffer, guint32 numbytes, guint32 *byteswritten)
-{
- gint ret;
- MonoThreadInfo *info = mono_thread_info_current ();
-
- if(byteswritten!=NULL) {
- *byteswritten=0;
- }
-
- if(!(filehandle->fileaccess & (GENERIC_WRITE | GENERIC_ALL))) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: fd %d doesn't have GENERIC_WRITE access: %u", __func__, ((MonoFDHandle*) filehandle)->fd, filehandle->fileaccess);
-
- mono_w32error_set_last (ERROR_ACCESS_DENIED);
- return(FALSE);
- }
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: writing up to %" G_GUINT32_FORMAT " bytes to pipe %d", __func__, numbytes, ((MonoFDHandle*) filehandle)->fd);
-
- do {
- MONO_ENTER_GC_SAFE;
- ret = write (((MonoFDHandle*) filehandle)->fd, buffer, numbytes);
- MONO_EXIT_GC_SAFE;
- } while (ret == -1 && errno == EINTR &&
- !mono_thread_info_is_interrupt_state (info));
-
- if (ret == -1) {
- if (errno == EINTR) {
- ret = 0;
- } else {
- _wapi_set_last_error_from_errno ();
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: write of fd %d error: %s", __func__,((MonoFDHandle*) filehandle)->fd, g_strerror(errno));
-
- return(FALSE);
- }
- }
- if(byteswritten!=NULL) {
- *byteswritten=ret;
- }
-
- return(TRUE);
-}
-
-static gint convert_flags(guint32 fileaccess, guint32 createmode)
-{
- gint flags=0;
-
- switch(fileaccess) {
- case GENERIC_READ:
- flags=O_RDONLY;
- break;
- case GENERIC_WRITE:
- flags=O_WRONLY;
- break;
- case GENERIC_READ|GENERIC_WRITE:
- flags=O_RDWR;
- break;
- default:
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: Unknown access type 0x%" PRIx32, __func__,
- fileaccess);
- break;
- }
-
- switch(createmode) {
- case CREATE_NEW:
- flags|=O_CREAT|O_EXCL;
- break;
- case CREATE_ALWAYS:
- flags|=O_CREAT|O_TRUNC;
- break;
- case OPEN_EXISTING:
- break;
- case OPEN_ALWAYS:
- flags|=O_CREAT;
- break;
- case TRUNCATE_EXISTING:
- flags|=O_TRUNC;
- break;
- default:
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: Unknown create mode 0x%" PRIx32, __func__,
- createmode);
- break;
- }
-
- return(flags);
-}
-
-static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
- guint32 fileaccess,
- FileShare **share_info)
-{
- gboolean file_already_shared;
- guint32 file_existing_share, file_existing_access;
-
- file_already_shared = file_share_get (statbuf->st_dev, statbuf->st_ino, sharemode, fileaccess, &file_existing_share, &file_existing_access, share_info);
-
- if (file_already_shared) {
- /* The reference to this share info was incremented
- * when we looked it up, so be careful to put it back
- * if we conclude we can't use this file.
- */
- if ((file_existing_share == FILE_SHARE_NONE) || (sharemode == FILE_SHARE_NONE)) {
- /* Quick and easy, no possibility to share */
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: Share mode prevents open: requested access: 0x%" PRIx32 ", file has sharing = NONE", __func__, fileaccess);
-
- file_share_release (*share_info);
- *share_info = NULL;
-
- return(FALSE);
- }
-
- if (((file_existing_share == FILE_SHARE_READ) &&
- (fileaccess != GENERIC_READ)) ||
- ((file_existing_share == FILE_SHARE_WRITE) &&
- (fileaccess != GENERIC_WRITE))) {
- /* New access mode doesn't match up */
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: Share mode prevents open: requested access: 0x%" PRIx32 ", file has sharing: 0x%" PRIx32, __func__, fileaccess, file_existing_share);
-
- file_share_release (*share_info);
- *share_info = NULL;
-
- return(FALSE);
- }
- } else {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: New file!", __func__);
- }
-
- return(TRUE);
-}
-
-void
-mono_w32file_init (void)
-{
- MonoFDHandleCallback file_data_callbacks;
- memset (&file_data_callbacks, 0, sizeof (file_data_callbacks));
- file_data_callbacks.close = file_data_close;
- file_data_callbacks.destroy = file_data_destroy;
-
- mono_fdhandle_register (MONO_FDTYPE_FILE, &file_data_callbacks);
- mono_fdhandle_register (MONO_FDTYPE_CONSOLE, &file_data_callbacks);
- mono_fdhandle_register (MONO_FDTYPE_PIPE, &file_data_callbacks);
-
- mono_coop_mutex_init (&file_share_mutex);
-}
-
-gpointer
-mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
-{
- FileHandle *filehandle;
- MonoFDType type;
- gint flags=convert_flags(fileaccess, createmode);
- /*mode_t perms=convert_perms(sharemode);*/
- /* we don't use sharemode, because that relates to sharing of
- * the file when the file is open and is already handled by
- * other code, perms instead are the on-disk permissions and
- * this is a sane default.
- */
- mode_t perms=0666;
- gchar *filename;
- gint fd, ret;
- struct stat statbuf;
- ERROR_DECL (error);
-
- if (attrs & FILE_ATTRIBUTE_TEMPORARY)
- perms = 0600;
-
- if (attrs & FILE_ATTRIBUTE_ENCRYPTED){
- mono_w32error_set_last (ERROR_ENCRYPTION_FAILED);
- return INVALID_HANDLE_VALUE;
- }
-
- if (name == NULL) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: name is NULL", __func__);
-
- mono_w32error_set_last (ERROR_INVALID_NAME);
- return(INVALID_HANDLE_VALUE);
- }
-
- filename = mono_unicode_to_external_checked (name, error);
- if (filename == NULL) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: unicode conversion returned NULL; %s", __func__, mono_error_get_message (error));
-
- mono_error_cleanup (error);
- mono_w32error_set_last (ERROR_INVALID_NAME);
- return(INVALID_HANDLE_VALUE);
- }
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: Opening %s with share 0x%" PRIx32 " and access 0x%" PRIx32, __func__,
- filename, sharemode, fileaccess);
-
- fd = _wapi_open (filename, flags, perms);
-
- /* If we were trying to open a directory with write permissions
- * (e.g. O_WRONLY or O_RDWR), this call will fail with
- * EISDIR. However, this is a bit bogus because calls to
- * manipulate the directory (e.g. mono_w32file_set_times) will still work on
- * the directory because they use other API calls
- * (e.g. utime()). Hence, if we failed with the EISDIR error, try
- * to open the directory again without write permission.
- */
- if (fd == -1 && errno == EISDIR)
- {
- /* Try again but don't try to make it writable */
- fd = _wapi_open (filename, flags & ~(O_RDWR|O_WRONLY), perms);
- }
-
- if (fd == -1) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: Error opening file %s: %s", __func__, filename, g_strerror(errno));
- _wapi_set_last_path_error_from_errno (NULL, filename);
- g_free (filename);
-
- return(INVALID_HANDLE_VALUE);
- }
-
- MONO_ENTER_GC_SAFE;
- ret = fstat (fd, &statbuf);
- MONO_EXIT_GC_SAFE;
- if (ret == -1) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: fstat error of file %s: %s", __func__, filename, g_strerror (errno));
- _wapi_set_last_error_from_errno ();
- MONO_ENTER_GC_SAFE;
- close (fd);
- MONO_EXIT_GC_SAFE;
-
- return(INVALID_HANDLE_VALUE);
- }
-
-#ifndef S_ISFIFO
-#define S_ISFIFO(m) ((m & S_IFIFO) != 0)
-#endif
- if (S_ISFIFO (statbuf.st_mode)) {
- type = MONO_FDTYPE_PIPE;
- /* maintain invariant that pipes have no filename */
- g_free (filename);
- filename = NULL;
- } else if (S_ISCHR (statbuf.st_mode)) {
- type = MONO_FDTYPE_CONSOLE;
- } else {
- type = MONO_FDTYPE_FILE;
- }
-
- filehandle = file_data_create (type, fd);
- filehandle->filename = filename;
- filehandle->fileaccess = fileaccess;
- filehandle->sharemode = sharemode;
- filehandle->attrs = attrs;
-
- if (!share_allows_open (&statbuf, filehandle->sharemode, filehandle->fileaccess, &filehandle->share_info)) {
- mono_w32error_set_last (ERROR_SHARING_VIOLATION);
- MONO_ENTER_GC_SAFE;
- close (((MonoFDHandle*) filehandle)->fd);
- MONO_EXIT_GC_SAFE;
-
- mono_fdhandle_unref ((MonoFDHandle*) filehandle);
- return (INVALID_HANDLE_VALUE);
- }
- if (!filehandle->share_info) {
- /* No space, so no more files can be opened */
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: No space in the share table", __func__);
-
- mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
- MONO_ENTER_GC_SAFE;
- close (((MonoFDHandle*) filehandle)->fd);
- MONO_EXIT_GC_SAFE;
-
- mono_fdhandle_unref ((MonoFDHandle*) filehandle);
- return(INVALID_HANDLE_VALUE);
- }
-
-#ifdef HAVE_POSIX_FADVISE
- if (attrs & FILE_FLAG_SEQUENTIAL_SCAN) {
- MONO_ENTER_GC_SAFE;
- posix_fadvise (((MonoFDHandle*) filehandle)->fd, 0, 0, POSIX_FADV_SEQUENTIAL);
- MONO_EXIT_GC_SAFE;
- }
- if (attrs & FILE_FLAG_RANDOM_ACCESS) {
- MONO_ENTER_GC_SAFE;
- posix_fadvise (((MonoFDHandle*) filehandle)->fd, 0, 0, POSIX_FADV_RANDOM);
- MONO_EXIT_GC_SAFE;
- }
-#endif
-
-#ifdef F_RDAHEAD
- if (attrs & FILE_FLAG_SEQUENTIAL_SCAN) {
- MONO_ENTER_GC_SAFE;
- fcntl(((MonoFDHandle*) filehandle)->fd, F_RDAHEAD, 1);
- MONO_EXIT_GC_SAFE;
- }
-#endif
-
- mono_fdhandle_insert ((MonoFDHandle*) filehandle);
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_FILE, "%s: returning handle %p", __func__, GINT_TO_POINTER(((MonoFDHandle*) filehandle)->fd));
-
- return GINT_TO_POINTER(((MonoFDHandle*) filehandle)->fd);
-}
-
-
-gboolean
-mono_w32file_close (gpointer handle)
-{
- if (!mono_fdhandle_close (GPOINTER_TO_INT (handle))) {
- mono_w32error_set_last (ERROR_INVALID_HANDLE);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-mono_w32file_read_or_write (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread, gint32 *win32error)
-{
- MONO_REQ_GC_UNSAFE_MODE;
-
- FileHandle *filehandle;
- gboolean ret = FALSE;
-
- gboolean const ref = mono_fdhandle_lookup_and_ref(GPOINTER_TO_INT(handle), (MonoFDHandle**) &filehandle);
- if (!ref) {
- mono_w32error_set_last (ERROR_INVALID_HANDLE);
- goto exit;
- }
-
- switch (((MonoFDHandle*) filehandle)->type) {
- case MONO_FDTYPE_FILE:
- ret = (file_write) (filehandle, buffer, numbytes, bytesread);
- break;
- case MONO_FDTYPE_CONSOLE:
- ret = (console_write) (filehandle, buffer, numbytes, bytesread);
- break;
- case MONO_FDTYPE_PIPE:
- ret = (pipe_write) (filehandle, buffer, numbytes, bytesread);
- break;
- default:
- mono_w32error_set_last (ERROR_INVALID_HANDLE);
- break;
- }
-
-exit:
- if (ref)
- mono_fdhandle_unref ((MonoFDHandle*) filehandle);
- if (!ret)
- *win32error = mono_w32error_get_last ();
- return ret;
-}
-
-gboolean
-mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten, gint32 *win32error)
-{
- return mono_w32file_read_or_write (handle, (gpointer)buffer, numbytes, byteswritten, win32error);
-}
+++ /dev/null
-/**
- * \file
- * Windows File IO internal calls.
- *
- * Copyright 2016 Microsoft
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-#include <config.h>
-#include <glib.h>
-
-#include <winsock2.h>
-#include <windows.h>
-#include <mono/utils/w32subset.h>
-#include "icall-decl.h"
-
-void
-mono_w32file_init (void)
-{
-}
-
-gpointer
-mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
-{
- gpointer res;
- MONO_ENTER_GC_SAFE;
- res = CreateFileW (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
- MONO_EXIT_GC_SAFE;
- return res;
-}
-
-gboolean
-mono_w32file_close (gpointer handle)
-{
- gboolean res;
- MONO_ENTER_GC_SAFE;
- res = CloseHandle (handle);
- MONO_EXIT_GC_SAFE;
- return res;
-}
-
-static void
-win32_io_interrupt_handler (gpointer ignored)
-{
-}
-
-gboolean
-mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten, gint32 *win32error)
-{
- gboolean res;
- MonoThreadInfo *info = mono_thread_info_current ();
- gboolean alerted = FALSE;
-
- if (info) {
- mono_thread_info_install_interrupt (win32_io_interrupt_handler, NULL, &alerted);
- if (alerted) {
- SetLastError (ERROR_OPERATION_ABORTED);
- *win32error = ERROR_OPERATION_ABORTED;
- return FALSE;
- }
- mono_win32_enter_blocking_io_call (info, handle);
- }
-
- MONO_ENTER_GC_SAFE;
- if (info && mono_thread_info_is_interrupt_state (info)) {
- res = FALSE;
- SetLastError (ERROR_OPERATION_ABORTED);
- } else {
- res = WriteFile (handle, buffer, numbytes, (PDWORD)byteswritten, NULL);
- }
- if (!res)
- *win32error = GetLastError ();
- MONO_EXIT_GC_SAFE;
-
- if (info) {
- mono_win32_leave_blocking_io_call (info, handle);
- mono_thread_info_uninstall_interrupt (&alerted);
- }
-
- return res;
-}
+++ /dev/null
-/**
- * \file
- * File IO internal calls
- *
- * Authors:
- * Dick Porter (dick@ximian.com)
- * Dan Lewis (dihlewis@yahoo.co.uk)
- *
- * (C) 2001 Ximian, Inc.
- * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#ifndef _MONO_METADATA_W32FILE_H_
-#define _MONO_METADATA_W32FILE_H_
-
-#include <config.h>
-#include <glib.h>
-
-#include <mono/metadata/object-internals.h>
-#include <mono/utils/mono-compiler.h>
-#include <mono/metadata/icalls.h>
-
-/* This is a copy of System.IO.FileAttributes */
-typedef enum {
- FileAttributes_ReadOnly=0x00001,
- FileAttributes_Hidden=0x00002,
- FileAttributes_System=0x00004,
- FileAttributes_Directory=0x00010,
- FileAttributes_Archive=0x00020,
- FileAttributes_Device=0x00040,
- FileAttributes_Normal=0x00080,
- FileAttributes_Temporary=0x00100,
- FileAttributes_SparseFile=0x00200,
- FileAttributes_ReparsePoint=0x00400,
- FileAttributes_Compressed=0x00800,
- FileAttributes_Offline=0x01000,
- FileAttributes_NotContentIndexed=0x02000,
- FileAttributes_Encrypted=0x04000,
- FileAttributes_MonoExecutable= (int) 0x80000000
-} MonoFileAttributes;
-
-#if defined (TARGET_IOS) || defined (TARGET_ANDROID)
-
-extern gint64
-mono_filesize_from_fd (int fd);
-
-#endif
-
-#if !defined(HOST_WIN32)
-
-#define GENERIC_READ 0x80000000
-#define GENERIC_WRITE 0x40000000
-#define GENERIC_EXECUTE 0x20000000
-#define GENERIC_ALL 0x10000000
-
-#define FILE_SHARE_NONE 0x00000000
-#define FILE_SHARE_READ 0x00000001
-#define FILE_SHARE_WRITE 0x00000002
-#define FILE_SHARE_DELETE 0x00000004
-
-#define CREATE_NEW 1
-#define CREATE_ALWAYS 2
-#define OPEN_EXISTING 3
-#define OPEN_ALWAYS 4
-#define TRUNCATE_EXISTING 5
-
-#define FILE_ATTRIBUTE_READONLY 0x00000001
-#define FILE_ATTRIBUTE_HIDDEN 0x00000002
-#define FILE_ATTRIBUTE_SYSTEM 0x00000004
-#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
-#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
-#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
-#define FILE_ATTRIBUTE_NORMAL 0x00000080
-#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
-#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
-#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
-#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
-#define FILE_ATTRIBUTE_OFFLINE 0x00001000
-#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
-#define FILE_FLAG_OPEN_NO_RECALL 0x00100000
-#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000
-#define FILE_FLAG_POSIX_SEMANTICS 0x01000000
-#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000
-#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000
-#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000
-#define FILE_FLAG_RANDOM_ACCESS 0x10000000
-#define FILE_FLAG_NO_BUFFERING 0x20000000
-#define FILE_FLAG_OVERLAPPED 0x40000000
-#define FILE_FLAG_WRITE_THROUGH 0x80000000
-
-#define REPLACEFILE_WRITE_THROUGH 0x00000001
-#define REPLACEFILE_IGNORE_MERGE_ERRORS 0x00000002
-
-#define MAX_PATH 260
-
-#define INVALID_SET_FILE_POINTER ((guint32) 0xFFFFFFFF)
-#define INVALID_FILE_SIZE ((guint32) 0xFFFFFFFF)
-#define INVALID_FILE_ATTRIBUTES ((guint32) 0xFFFFFFFF)
-
-#define FILE_TYPE_UNKNOWN 0x0000
-#define FILE_TYPE_DISK 0x0001
-#define FILE_TYPE_CHAR 0x0002
-#define FILE_TYPE_PIPE 0x0003
-#define FILE_TYPE_REMOTE 0x8000
-
-#define FILE_BEGIN 0
-#define FILE_CURRENT 1
-#define FILE_END 2
-
-#define DRIVE_UNKNOWN 0
-#define DRIVE_NO_ROOT_DIR 1
-#define DRIVE_REMOVABLE 2
-#define DRIVE_FIXED 3
-#define DRIVE_REMOTE 4
-#define DRIVE_CDROM 5
-#define DRIVE_RAMDISK 6
-
-typedef struct {
- guint16 wYear;
- guint16 wMonth;
- guint16 wDayOfWeek;
- guint16 wDay;
- guint16 wHour;
- guint16 wMinute;
- guint16 wSecond;
- guint16 wMilliseconds;
-} SYSTEMTIME;
-
-typedef struct {
-#if G_BYTE_ORDER == G_BIG_ENDIAN
- guint32 dwHighDateTime;
- guint32 dwLowDateTime;
-#else
- guint32 dwLowDateTime;
- guint32 dwHighDateTime;
-#endif
-} FILETIME;
-
-#endif /* !defined(HOST_WIN32) */
-
-void
-mono_w32file_init (void);
-
-MONO_COMPONENT_API
-gpointer
-mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs);
-
-MONO_COMPONENT_API
-gboolean
-mono_w32file_close (gpointer handle);
-
-MONO_COMPONENT_API
-gboolean
-mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten, gint32 *win32error);
-
-#endif /* _MONO_METADATA_W32FILE_H_ */
+++ /dev/null
-/**
- * \file
- */
-
-#include "w32process.h"
-#include "w32process-unix-internals.h"
-
-#ifdef USE_BSD_BACKEND
-
-#include <errno.h>
-#include <signal.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#if !defined(__OpenBSD__)
-#include <sys/utsname.h>
-#endif
-#if defined(__FreeBSD__)
-#include <sys/user.h> /* struct kinfo_proc */
-#endif
-
-#include <link.h>
-#include "utils/mono-logger-internals.h"
-#include "icall-decl.h"
-
-gchar*
-mono_w32process_get_name (pid_t pid)
-{
- gint mib [6];
- gsize size;
- struct kinfo_proc *pi;
- gchar *ret = NULL;
-
-#if defined(__FreeBSD__)
- mib [0] = CTL_KERN;
- mib [1] = KERN_PROC;
- mib [2] = KERN_PROC_PID;
- mib [3] = pid;
- if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: sysctl() failed: %d", __func__, errno);
- return NULL;
- }
-
- if ((pi = g_malloc (size)) == NULL)
- return NULL;
-
- if (sysctl (mib, 4, pi, &size, NULL, 0) < 0) {
- if (errno == ENOMEM) {
- g_free (pi);
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Didn't allocate enough memory for kproc info", __func__);
- }
- return NULL;
- }
-
- ret = strlen (pi->ki_comm) > 0 ? g_strdup (pi->ki_comm) : NULL;
-
- g_free (pi);
-#elif defined(__OpenBSD__)
- mib [0] = CTL_KERN;
- mib [1] = KERN_PROC;
- mib [2] = KERN_PROC_PID;
- mib [3] = pid;
- mib [4] = sizeof(struct kinfo_proc);
- mib [5] = 0;
-
-retry:
- if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: sysctl() failed: %d", __func__, errno);
- return NULL;
- }
-
- if ((pi = g_malloc (size)) == NULL)
- return NULL;
-
- mib[5] = (int)(size / sizeof(struct kinfo_proc));
-
- if ((sysctl (mib, 6, pi, &size, NULL, 0) < 0) ||
- (size != sizeof (struct kinfo_proc))) {
- if (errno == ENOMEM) {
- g_free (pi);
- goto retry;
- }
- return NULL;
- }
-
- ret = strlen (pi->p_comm) > 0 ? g_strdup (pi->p_comm) : NULL;
-
- g_free (pi);
-#endif
-
- return ret;
-}
-
-gchar*
-mono_w32process_get_path (pid_t pid)
-{
-#if defined (__OpenBSD__)
- // No KERN_PROC_PATHNAME on OpenBSD
- return mono_w32process_get_name (pid);
-#else
- gsize path_len = PATH_MAX + 1;
- gchar path [PATH_MAX + 1];
- gint mib [4];
- mib [0] = CTL_KERN;
-#if defined (__NetBSD__)
- mib [1] = KERN_PROC_ARGS;
- mib [2] = pid;
- mib [3] = KERN_PROC_PATHNAME;
-#else // FreeBSD
- mib [1] = KERN_PROC;
- mib [2] = KERN_PROC_PATHNAME;
- mib [3] = pid;
-#endif
- if (sysctl (mib, 4, path, &path_len, NULL, 0) < 0) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: sysctl() failed: %d", __func__, errno);
- return NULL;
- } else {
- return g_strdup (path);
- }
-#endif
-}
-
-#else
-
-MONO_EMPTY_SOURCE_FILE (w32process_unix_bsd);
-
-#endif
+++ /dev/null
-/**
- * \file
- */
-
-#include "w32process.h"
-#include "w32process-unix-internals.h"
-
-#ifdef USE_DEFAULT_BACKEND
-
-#include <unistd.h>
-
-#ifdef HOST_SOLARIS
-/* procfs.h cannot be included if this define is set, but it seems to work fine if it is undefined */
-#if _FILE_OFFSET_BITS == 64
-#undef _FILE_OFFSET_BITS
-#include <procfs.h>
-#define _FILE_OFFSET_BITS 64
-#else
-#include <procfs.h>
-#endif
-#endif
-
-#ifdef _AIX
-/* like solaris, just different */
-#include <sys/procfs.h>
-/* fallback for procfs-less i */
-#include <procinfo.h>
-#include <sys/types.h>
-#endif
-
-#include "utils/mono-logger-internals.h"
-#include "icall-decl.h"
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 242
-#endif
-
-/* XXX: why don't we just use proclib? */
-gchar*
-mono_w32process_get_name (pid_t pid)
-{
- FILE *fp;
- gchar *filename;
- gchar *ret = NULL;
-
-#if defined(HOST_SOLARIS) || (defined(_AIX) && !defined(__PASE__))
- filename = g_strdup_printf ("/proc/%d/psinfo", pid);
- if ((fp = fopen (filename, "r")) != NULL) {
- struct psinfo info;
- int nread;
-
- nread = fread (&info, sizeof (info), 1, fp);
- if (nread == 1) {
- ret = g_strdup (info.pr_fname);
- }
-
- fclose (fp);
- }
- g_free (filename);
-#elif defined(__PASE__)
- /* AIX has a procfs, but it's not available on i */
- struct procentry64 proc;
- pid_t newpid;
-
- newpid = pid;
- if (getprocs64(&proc, sizeof (proc), NULL, NULL, &newpid, 1) == 1) {
- ret = g_strdup (proc.pi_comm);
- }
-#else
- gchar buf[256];
- memset (buf, '\0', sizeof(buf));
- filename = g_strdup_printf ("/proc/%d/exe", pid);
-#if defined(HAVE_READLINK)
- if (readlink (filename, buf, 255) > 0) {
- ret = g_strdup (buf);
- }
-#endif
- g_free (filename);
-
- if (ret != NULL) {
- return(ret);
- }
-
- filename = g_strdup_printf ("/proc/%d/cmdline", pid);
- if ((fp = fopen (filename, "r")) != NULL) {
- if (fgets (buf, 256, fp) != NULL) {
- ret = g_strdup (buf);
- }
-
- fclose (fp);
- }
- g_free (filename);
-
- if (ret != NULL) {
- return(ret);
- }
-
- filename = g_strdup_printf ("/proc/%d/stat", pid);
- if ((fp = fopen (filename, "r")) != NULL) {
- if (fgets (buf, 256, fp) != NULL) {
- char *start, *end;
-
- start = strchr (buf, '(');
- if (start != NULL) {
- end = strchr (start + 1, ')');
-
- if (end != NULL) {
- ret = g_strndup (start + 1,
- end - start - 1);
- }
- }
- }
-
- fclose (fp);
- }
- g_free (filename);
-#endif
-
- return ret;
-}
-
-gchar*
-mono_w32process_get_path (pid_t pid)
-{
- return mono_w32process_get_name (pid);
-}
-
-#else
-
-MONO_EMPTY_SOURCE_FILE (w32process_unix_default);
-
-#endif
+++ /dev/null
-/**
- * \file
- */
-
-#include "w32process.h"
-#include "w32process-unix-internals.h"
-
-#ifdef USE_HAIKU_BACKEND
-
-/* KernelKit.h doesn't include the right headers? */
-#include <os/kernel/image.h>
-
-gchar*
-mono_w32process_get_name (pid_t pid)
-{
- image_info imageInfo;
- int32 cookie = 0;
-
- if (get_next_image_info ((team_id) pid, &cookie, &imageInfo) != B_OK)
- return NULL;
-
- return g_strdup (imageInfo.name);
-}
-
-gchar*
-mono_w32process_get_path (pid_t pid)
-{
- return mono_w32process_get_name (pid);
-}
-
-
-#else
-
-MONO_EMPTY_SOURCE_FILE (w32process_unix_haiku);
-
-#endif
+++ /dev/null
-/**
- * \file
- */
-
-#ifndef _MONO_METADATA_W32PROCESS_UNIX_INTERNALS_H_
-#define _MONO_METADATA_W32PROCESS_UNIX_INTERNALS_H_
-
-#include <config.h>
-#include <glib.h>
-
-/*
- * FOR EXCLUSIVE USE BY w32process-unix.c
- */
-
-#if defined(HOST_DARWIN)
-#define USE_OSX_BACKEND
-#elif (defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(HAVE_LINK_H)
-#define USE_BSD_BACKEND
-#elif defined(__HAIKU__)
-#define USE_HAIKU_BACKEND
-/* Define header for team_info */
-#include <os/kernel/OS.h>
-#else
-#define USE_DEFAULT_BACKEND
-#endif
-
-gchar*
-mono_w32process_get_name (pid_t pid);
-
-#endif /* _MONO_METADATA_W32PROCESS_UNIX_INTERNALS_H_ */
+++ /dev/null
-/**
- * \file
- */
-
-#include "w32process.h"
-#include "w32process-unix-internals.h"
-
-#ifdef USE_OSX_BACKEND
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-#include <sys/utsname.h>
-#include <mach-o/dyld.h>
-#include <mach-o/getsect.h>
-#include <dlfcn.h>
-
-/* sys/resource.h (for rusage) is required when using osx 10.3 (but not 10.4) */
-#ifdef __APPLE__
-#include <TargetConditionals.h>
-#include <sys/resource.h>
-#ifdef HAVE_LIBPROC_H
-/* proc_name */
-#include <libproc.h>
-#endif
-#endif
-
-#include "utils/mono-logger-internals.h"
-#include "icall-decl.h"
-
-gchar*
-mono_w32process_get_name (pid_t pid)
-{
- gchar *ret = NULL;
-
-#if defined (__mono_ppc__) || !defined (TARGET_OSX)
- size_t size;
- struct kinfo_proc *pi;
- gint mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
-
- if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0)
- return(ret);
-
- if ((pi = g_malloc (size)) == NULL)
- return(ret);
-
- if (sysctl (mib, 4, pi, &size, NULL, 0) < 0) {
- if (errno == ENOMEM) {
- g_free (pi);
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Didn't allocate enough memory for kproc info", __func__);
- }
- return(ret);
- }
-
- if (strlen (pi->kp_proc.p_comm) > 0)
- ret = g_strdup (pi->kp_proc.p_comm);
-
- g_free (pi);
-#else
- gchar buf[256];
- gint res;
-
- /* No proc name on OSX < 10.5 nor ppc nor iOS */
- memset (buf, '\0', sizeof(buf));
- res = proc_name (pid, buf, sizeof(buf));
- if (res == 0) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: proc_name failed, error (%d) \"%s\"", __func__, errno, g_strerror (errno));
- return NULL;
- }
-
- // Fixes proc_name triming values to 15 characters #32539
- if (strlen (buf) >= MAXCOMLEN - 1) {
- gchar path_buf [PROC_PIDPATHINFO_MAXSIZE];
- gchar *name_buf;
- gint path_len;
-
- memset (path_buf, '\0', sizeof(path_buf));
- path_len = proc_pidpath (pid, path_buf, sizeof(path_buf));
-
- if (path_len > 0 && path_len < sizeof(path_buf)) {
- name_buf = path_buf + path_len;
- for(;name_buf > path_buf; name_buf--) {
- if (name_buf [0] == '/') {
- name_buf++;
- break;
- }
- }
-
- if (memcmp (buf, name_buf, MAXCOMLEN - 1) == 0)
- ret = g_strdup (name_buf);
- }
- }
-
- if (ret == NULL && strlen (buf) > 0)
- ret = g_strdup (buf);
-#endif
-
- return ret;
-}
-
-gchar*
-mono_w32process_get_path (pid_t pid)
-{
-#if defined(__mono_ppc__) || !defined(TARGET_OSX)
- return mono_w32process_get_name (pid);
-#else
- gchar buf [PROC_PIDPATHINFO_MAXSIZE];
- gint res;
-
- res = proc_pidpath (pid, buf, sizeof (buf));
- if (res <= 0)
- return NULL;
- if (buf [0] == '\0')
- return NULL;
- return g_strdup (buf);
-#endif
-}
-
-#else
-
-MONO_EMPTY_SOURCE_FILE (w32process_unix_osx);
-
-#endif
+++ /dev/null
-/**
- * \file
- * System.Diagnostics.Process support
- *
- * Author:
- * Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- */
-
-#ifndef _MONO_METADATA_W32PROCESS_H_
-#define _MONO_METADATA_W32PROCESS_H_
-
-#include <config.h>
-#include <glib.h>
-
-#include <mono/utils/mono-compiler.h>
-
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifndef HOST_WIN32
-
-gchar*
-mono_w32process_get_path (pid_t pid);
-
-#endif
-#endif /* _MONO_METADATA_W32PROCESS_H_ */
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/environment.h>
-#include <mono/metadata/environment-internals.h>
#include <mono/metadata/verify.h>
#include <mono/metadata/mono-debug.h>
#include <mono/metadata/gc-internals.h>
#include <mono/metadata/coree.h>
-#include <mono/metadata/w32process.h>
#include "mono/utils/mono-counters.h"
#include "mono/utils/mono-hwcap.h"
#include "mono/utils/mono-logger-internals.h"
#endif
mono_set_defaults (mini_verbose_level, opt);
- mono_set_os_args (argc, argv);
domain = mini_init (argv [i], forced_version);
#ifndef _MONO_UTILS_FORWARD_INTERNAL_
#define _MONO_UTILS_FORWARD_INTERNAL_
-#include "mono/utils/mono-forward.h"
+#include <mono/utils/mono-forward.h>
typedef struct MonoAotModule MonoAotModule;
typedef struct MonoHandleStack MonoHandleStack;
void
mono_thread_info_clear_self_interrupt (void);
-gboolean
+MONO_COMPONENT_API gboolean
mono_thread_info_is_interrupt_state (THREAD_INFO_TYPE *info);
void