7 #if defined(HOST_ANDROID)
13 #include <mono/utils/mono-threads.h>
14 #include <sys/syscall.h>
17 slow_get_thread_bounds (guint8
*current
, guint8
**staddr
, size_t *stsize
)
20 FILE *f
= fopen ("/proc/self/maps", "r");
22 g_error ("Could not determine thread bounds, failed to open /proc/self/maps");
24 while (fgets (buff
, sizeof (buff
), f
)) {
28 //each line starts with the range we want: f7648000-f7709000
29 low
= strtoimax (ptr
, &end
, 16);
31 ptr
= end
+ 1; //skip the dash to make sure we don't get a negative number
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
);
42 g_error ("Could not determine thread bounds, failed to find current stack pointer in /proc/self/maps");
46 mono_threads_platform_get_stack_bounds (guint8
**staddr
, size_t *stsize
)
49 guint8
*current
= (guint8
*)&attr
;
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
);
63 mono_native_thread_os_id_get (void)
65 return (guint64
)syscall (SYS_gettid
);