[interp] Remove unconditional branches to next instruction (#15939)
[mono-project.git] / mono / utils / mono-threads-android.c
blobf01e6702957923a07a4263d7e23c6125a97924a4
1 /**
2 * \file
3 */
5 #include <config.h>
7 #if defined(HOST_ANDROID)
9 #include <pthread.h>
10 #include <stdio.h>
11 #include <inttypes.h>
12 #include "glib.h"
13 #include <mono/utils/mono-threads.h>
14 #include <sys/syscall.h>
16 static void
17 slow_get_thread_bounds (guint8 *current, guint8 **staddr, size_t *stsize)
19 char buff [1024];
20 FILE *f = fopen ("/proc/self/maps", "r");
21 if (!f)
22 g_error ("Could not determine thread bounds, failed to open /proc/self/maps");
24 while (fgets (buff, sizeof (buff), f)) {
25 intmax_t low, high;
26 char *ptr = buff;
27 char *end = NULL;
28 //each line starts with the range we want: f7648000-f7709000
29 low = strtoimax (ptr, &end, 16);
30 if (end) {
31 ptr = end + 1; //skip the dash to make sure we don't get a negative number
32 end = NULL;
33 high = strtoimax (ptr, &end, 16);
35 if (end && low <= (intmax_t)(size_t)current && high > (intmax_t)(size_t)current) {
36 *staddr = (guint8 *)(size_t)low;
37 *stsize = (size_t)(high - low);
38 fclose (f);
39 return;
42 g_error ("Could not determine thread bounds, failed to find current stack pointer in /proc/self/maps");
45 void
46 mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
48 pthread_attr_t attr;
49 guint8 *current = (guint8*)&attr;
51 *staddr = NULL;
52 *stsize = (size_t)-1;
54 pthread_getattr_np (pthread_self (), &attr);
55 pthread_attr_getstack (&attr, (void**)staddr, stsize);
56 pthread_attr_destroy (&attr);
58 if (*staddr && ((current <= *staddr) || (current > *staddr + *stsize)))
59 slow_get_thread_bounds (current, staddr, stsize);
62 guint64
63 mono_native_thread_os_id_get (void)
65 return (guint64)syscall (SYS_gettid);
68 #endif