-/*
+/**
+ * \file
* Copyright 2008-2011 Novell Inc
* Copyright 2011 Xamarin Inc
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
#endif
#if defined(_POSIX_VERSION)
+#ifdef HAVE_SYS_ERRNO_H
#include <sys/errno.h>
+#endif
#include <sys/param.h>
#include <errno.h>
#ifdef HAVE_SYS_TYPES_H
#endif
#include <sys/resource.h>
#endif
+#if defined(__HAIKU__)
+#include <os/kernel/OS.h>
+#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/proc.h>
#if defined(__APPLE__)
#define USE_SYSCTL 1
#endif
+#ifdef HAVE_SCHED_GETAFFINITY
+# ifndef GLIBC_HAS_CPU_COUNT
+static int
+CPU_COUNT(cpu_set_t *set)
+{
+ int i, count = 0;
+
+ for (int i = 0; i < CPU_SETSIZE; i++)
+ if (CPU_ISSET(i, set))
+ count++;
+ return count;
+}
+# endif
+#endif
+
/**
* mono_process_list:
- * @size: a pointer to a location where the size of the returned array is stored
- *
- * Return an array of pid values for the processes currently running on the system.
- * The size of the array is stored in @size.
+ * \param size a pointer to a location where the size of the returned array is stored
+ * \returns an array of pid values for the processes currently running on the system.
+ * The size of the array is stored in \p size.
*/
gpointer*
mono_process_list (int *size)
*size = res;
return buf;
#elif defined(__HAIKU__)
- /* FIXME: Add back the code from 9185fcc305e43428d0f40f3ee37c8a405d41c9ae */
- g_assert_not_reached ();
- return NULL;
+ int32 cookie = 0;
+ int32 i = 0;
+ team_info ti;
+ system_info si;
+
+ get_system_info(&si);
+ void **buf = g_calloc(si.used_teams, sizeof(void*));
+
+ while (get_next_team_info(&cookie, &ti) == B_OK && i < si.used_teams) {
+ buf[i++] = GINT_TO_POINTER (ti.team);
+ }
+ *size = i;
+
+ return buf;
#else
const char *name;
void **buf = NULL;
while (g_ascii_isspace (*s)) s++;
fclose (f);
len = strlen (s);
- strncpy (rbuf, s, MIN (len, blen));
+ memcpy (rbuf, s, MIN (len, blen));
rbuf [MIN (len, blen) - 1] = 0;
if (error)
*error = MONO_PROCESS_ERROR_NONE;
/**
* mono_process_get_name:
- * @pid: pid of the process
- * @buf: byte buffer where to store the name of the prcoess
- * @len: size of the buffer @buf
- *
- * Return the name of the process identified by @pid, storing it
- * inside @buf for a maximum of len bytes (including the terminating 0).
+ * \param pid pid of the process
+ * \param buf byte buffer where to store the name of the prcoess
+ * \param len size of the buffer \p buf
+ * \returns the name of the process identified by \p pid, storing it
+ * inside \p buf for a maximum of len bytes (including the terminating 0).
*/
char*
mono_process_get_name (gpointer pid, char *buf, int len)
memset (buf, 0, len);
if (sysctl_kinfo_proc (pid, &processi))
- strncpy (buf, processi.kinfo_name_member, len - 1);
+ memcpy (buf, processi.kinfo_name_member, len - 1);
return buf;
#else
/**
* mono_process_get_data:
- * @pid: pid of the process
- * @data: description of data to return
- *
- * Return a data item of a process like user time, memory use etc,
- * according to the @data argumet.
+ * \param pid pid of the process
+ * \param data description of data to return
+ * \returns a data item of a process like user time, memory use etc,
+ * according to the \p data argumet.
*/
gint64
mono_process_get_data_with_error (gpointer pid, MonoProcessData data, MonoProcessError *error)
/**
* mono_cpu_count:
- *
- * Return the number of processors on the system.
+ * \returns the number of processors on the system.
*/
#ifndef HOST_WIN32
int
/**
* mono_cpu_get_data:
- * @cpu_id: processor number or -1 to get a summary of all the processors
- * @data: type of data to retrieve
- *
+ * \param cpu_id processor number or -1 to get a summary of all the processors
+ * \param data type of data to retrieve
* Get data about a processor on the system, like time spent in user space or idle time.
*/
gint64