Allow runtime to be built with C++ on AIX (#17672)
[mono-project.git] / mono / utils / mono-threads-aix.c
blob28cae9b44abec000691f76821271d7ab6ffff4a0
1 /**
2 * \file
3 */
5 #include <config.h>
7 #if defined(_AIX)
9 #include <mono/utils/mono-threads.h>
10 #include <pthread.h>
12 void
13 mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
15 /* see GC_push_all_stacks in libgc/aix_irix_threads.c
16 for why we do this; pthread_getattr_np exists only
17 on some versions of AIX and not on PASE, so use a
18 legacy way to get the stack information */
19 struct __pthrdsinfo pi;
20 pthread_t pt;
21 int res, rbv, ps;
22 char rb[255];
24 pt = pthread_self();
25 ps = sizeof(pi);
26 rbv = sizeof(rb);
28 *staddr = NULL;
29 *stsize = (size_t)-1;
31 res = pthread_getthrds_np(&pt, PTHRDSINFO_QUERY_ALL, &pi, ps, rb, &rbv);
32 /* FIXME: are these the right values? */
33 *staddr = (guint8*)pi.__pi_stackaddr;
35 * ruby doesn't use stacksize; see:
36 * github.com/ruby/ruby/commit/a2594be783c727c6034308f5294333752c3845bb
38 *stsize = pi.__pi_stackend - pi.__pi_stackaddr;
41 gboolean
42 mono_threads_platform_is_main_thread (void)
44 /* returns 1 on main thread, even if the kernel tid is diff */
45 return pthread_self () == 1;
48 guint64
49 mono_native_thread_os_id_get (void)
51 pthread_t t = pthread_self ();
52 struct __pthrdsinfo ti;
53 int err, size = 0;
54 err = pthread_getthrds_np (&t, PTHRDSINFO_QUERY_TID, &ti, sizeof (struct __pthrdsinfo), NULL, &size);
55 return (guint64)ti.__pi_tid;
58 #else
60 #include <mono/utils/mono-compiler.h>
62 MONO_EMPTY_SOURCE_FILE (mono_threads_aix);
64 #endif