#endif
#endif
-#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__)
+#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__)
#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
#endif
#ifdef PLATFORM_SOLARIS
static void process_close (gpointer handle, gpointer data);
static gboolean is_pid_valid (pid_t pid);
-#if !(defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__))
+#if !(defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__HAIKU__))
static FILE *
open_process_map (int pid, const char *mode);
#endif
{
gboolean result = FALSE;
-#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__)
+#if defined(HOST_WATCHOS)
+ result = TRUE; // TODO: Rewrite using sysctl
+#elif defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__)
if (((kill(pid, 0) == 0) || (errno == EPERM)) && pid != 0)
result = TRUE;
#elif defined(__HAIKU__)
WapiStartupInfo *startup,
WapiProcessInformation *process_info)
{
+#if defined (HAVE_FORK) && defined (HAVE_EXECVE)
char *cmd = NULL, *prog = NULL, *full_prog = NULL, *args = NULL, *args_after_prog = NULL;
char *dir = NULL, **env_strings = NULL, **argv = NULL;
guint32 i, env_count = 0;
if (newapp != NULL) {
if (appname != NULL) {
- newcmd = utf16_concat (newapp, utf16_space,
+ newcmd = utf16_concat (utf16_quote, newapp, utf16_quote, utf16_space,
appname, utf16_space,
cmdline, NULL);
} else {
- newcmd = utf16_concat (newapp, utf16_space,
+ newcmd = utf16_concat (utf16_quote, newapp, utf16_quote, utf16_space,
cmdline, NULL);
}
} else {
if (!is_executable (prog)) {
DEBUG ("%s: Executable permisson not set on %s", __func__, prog);
- g_free (prog);
SetLastError (ERROR_ACCESS_DENIED);
goto free_strings;
}
mono_processes_cleanup ();
return ret;
+#else
+ SetLastError (ERROR_NOT_SUPPORTED);
+ return FALSE;
+#endif // defined (HAVE_FORK) && defined (HAVE_EXECVE)
}
static void
return(ret);
}
-#elif defined(__OpenBSD__)
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
#include <link.h>
static int load_modules_callback (struct dl_phdr_info *info, size_t size, void *ptr)
{
if (procname == NULL || modulename == NULL)
return (FALSE);
+ DEBUG ("%s: procname=\"%s\", modulename=\"%s\"", __func__, procname, modulename);
pname = mono_path_resolve_symlinks (procname);
mname = mono_path_resolve_symlinks (modulename);
g_free (pname);
g_free (mname);
+ DEBUG ("%s: result is %d", __func__, result);
return result;
}
-#if !(defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__))
+#if !(defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__HAIKU__))
static FILE *
open_process_map (int pid, const char *mode)
{
}
#endif
+static char *get_process_name_from_proc (pid_t pid);
+
gboolean EnumProcessModules (gpointer process, gpointer *modules,
guint32 size, guint32 *needed)
{
WapiHandle_process *process_handle;
-#if !defined(__OpenBSD__) && !defined(PLATFORM_MACOSX)
+#if !defined(__OpenBSD__) && !defined(PLATFORM_MACOSX) && !defined(__FreeBSD__)
FILE *fp;
#endif
GSList *mods = NULL;
if (WAPI_IS_PSEUDO_PROCESS_HANDLE (process)) {
pid = WAPI_HANDLE_TO_PID (process);
+ proc_name = get_process_name_from_proc (pid);
} else {
process_handle = lookup_process_handle (process);
if (!process_handle) {
proc_name = process_handle->proc_name;
}
-#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__)
+#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__HAIKU__)
mods = load_modules ();
if (!proc_name) {
modules[0] = NULL;
static char *
get_process_name_from_proc (pid_t pid)
{
-#if defined(__OpenBSD__)
+#if defined(__OpenBSD__) || defined(__FreeBSD__)
int mib [6];
size_t size;
struct kinfo_proc *pi;
/* No proc name on OSX < 10.5 nor ppc nor iOS */
memset (buf, '\0', sizeof(buf));
proc_name (pid, buf, sizeof(buf));
- if (strlen (buf) > 0)
+
+ // Fixes proc_name triming values to 15 characters #32539
+ if (strlen (buf) >= MAXCOMLEN - 1) {
+ char path_buf [PROC_PIDPATHINFO_MAXSIZE];
+ char *name_buf;
+ int 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);
#else
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0)
free(pi);
#endif
+#elif 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) {
+ DEBUG ("%s: sysctl() failed: %d", __func__, errno);
+ return(ret);
+ }
+
+ if ((pi = malloc(size)) == NULL)
+ return(ret);
+
+ if (sysctl (mib, 4, pi, &size, NULL, 0) < 0) {
+ if (errno == ENOMEM) {
+ free(pi);
+ DEBUG ("%s: Didn't allocate enough memory for kproc info", __func__);
+ }
+ return(ret);
+ }
+
+ if (strlen (pi->ki_comm) > 0)
+ ret = g_strdup (pi->ki_comm);
+ free(pi);
#elif defined(__OpenBSD__)
mib [0] = CTL_KERN;
mib [1] = KERN_PROC;
mib [5] = 0;
retry:
- if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0)
+ if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) {
+ DEBUG ("%s: sysctl() failed: %d", __func__, errno);
return(ret);
+ }
if ((pi = malloc(size)) == NULL)
return(ret);
return(ret);
}
+#if defined(__OpenBSD__)
if (strlen (pi->p_comm) > 0)
ret = g_strdup (pi->p_comm);
+#elif defined(__FreeBSD__)
+ if (strlen (pi->ki_comm) > 0)
+ ret = g_strdup (pi->ki_comm);
+#endif
free(pi);
#elif defined(__HAIKU__)
char *procname_ext = NULL;
glong len;
gsize bytes;
-#if !defined(__OpenBSD__) && !defined(PLATFORM_MACOSX)
+#if !defined(__OpenBSD__) && !defined(PLATFORM_MACOSX) && !defined(__FreeBSD__)
FILE *fp;
#endif
GSList *mods = NULL;
}
/* Look up the address in /proc/<pid>/maps */
-#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__)
+#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__HAIKU__)
mods = load_modules ();
#else
fp = open_process_map (pid, "r");
return 0;
}
+static guint32
+get_module_filename (gpointer process, gpointer module,
+ gunichar2 *basename, guint32 size)
+{
+ int pid, len;
+ gsize bytes;
+ char *path;
+ gunichar2 *proc_path;
+
+ pid = GetProcessId (process);
+
+ path = wapi_process_get_path (pid);
+ if (path == NULL)
+ return 0;
+
+ proc_path = mono_unicode_from_external (path, &bytes);
+ if (proc_path == NULL)
+ return 0;
+
+ len = (bytes / 2);
+
+ /* Add the terminator */
+ bytes += 2;
+
+ if (size < bytes) {
+ DEBUG ("%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
+
+ memcpy (basename, proc_path, size);
+ } else {
+ DEBUG ("%s: Size %d larger than needed (%ld)",
+ __func__, size, bytes);
+
+ memcpy (basename, proc_path, bytes);
+ }
+
+ return len;
+}
+
guint32
GetModuleBaseName (gpointer process, gpointer module,
gunichar2 *basename, guint32 size)
GetModuleFileNameEx (gpointer process, gpointer module,
gunichar2 *filename, guint32 size)
{
- return get_module_name (process, module, filename, size, FALSE);
+ return get_module_filename (process, module, filename, size);
}
gboolean
{
WapiHandle_process *process_handle;
pid_t pid;
-#if !defined(__OpenBSD__) && !defined(PLATFORM_MACOSX)
+#if !defined(__OpenBSD__) && !defined(PLATFORM_MACOSX) && !defined(__FreeBSD__)
FILE *fp;
#endif
GSList *mods = NULL;
proc_name = g_strdup (process_handle->proc_name);
}
-#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__)
+#if defined(PLATFORM_MACOSX) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__)
mods = load_modules ();
#else
/* Look up the address in /proc/<pid>/maps */
gboolean
TerminateProcess (gpointer process, gint32 exitCode)
{
+#if defined(HAVE_KILL)
WapiHandle_process *process_handle;
int signo;
int ret;
}
return (ret == 0);
+#else
+ g_error ("kill() is not supported by this platform");
+ return FALSE;
+#endif
}
guint32