58 #include <stdlib.h>
59
60 #include <sys/procfs.h>
61 #include <sys/debug.h>
62
63 /*
64 * Currently these are only defined in thr_uberdata.h. Rather than trying and
65 * fight with libc headers, just explicitly define them here.
66 */
67 #define PTHREAD_CREATE_DAEMON_NP 0x100 /* = THR_DAEMON */
68 #define PTHREAD_CREATE_NONDAEMON_NP 0
69 extern int pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
70 extern int pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
71
72 #define PGN_TEST_PRI 23
73
74 static pthread_attr_t pgn_attr;
75 static pthread_attr_t pgn_thr_attr;
76 static pthread_barrier_t pgn_barrier;
77
78 #ifdef __sparc
79 #define gregs __gregs
80 #endif
81
82 /*
83 * Verify that the stack pointer of a context is consistent with where the
84 * attributes indicate.
85 */
86 static void
87 pgn_verif_thr_stack(pthread_attr_t *attr)
88 {
89 size_t stksz;
90 void *stk;
91 ucontext_t ctx;
92 uint32_t sp;
93
94 VERIFY0(getcontext(&ctx));
95 VERIFY0(pthread_attr_getstack(attr, &stk, &stksz));
96 VERIFY3P(stk, !=, NULL);
97 VERIFY3S(stksz, !=, 0);
98 sp = ctx.uc_mcontext.gregs[R_SP];
99 VERIFY3U(sp, >, (uintptr_t)stk);
100 VERIFY3U(sp, <, (uintptr_t)stk + stksz);
101 }
102
103 #ifdef __sparc
104 #undef gregs
105 #endif
106
107 static void
108 pgn_test_fini(void)
109 {
110 int ret;
111
112 ret = pthread_barrier_wait(&pgn_barrier);
113 VERIFY(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD);
114 VERIFY0(pthread_attr_destroy(&pgn_attr));
115 VERIFY0(pthread_attr_destroy(&pgn_thr_attr));
116 VERIFY0(pthread_barrier_destroy(&pgn_barrier));
117 }
118
119 static void
120 pgn_test_init(void)
121 {
122 VERIFY0(pthread_attr_init(&pgn_attr));
123 VERIFY0(pthread_attr_init(&pgn_thr_attr));
124 VERIFY0(pthread_barrier_init(&pgn_barrier, NULL, 2));
125 }
|
58 #include <stdlib.h>
59
60 #include <sys/procfs.h>
61 #include <sys/debug.h>
62
63 /*
64 * Currently these are only defined in thr_uberdata.h. Rather than trying and
65 * fight with libc headers, just explicitly define them here.
66 */
67 #define PTHREAD_CREATE_DAEMON_NP 0x100 /* = THR_DAEMON */
68 #define PTHREAD_CREATE_NONDAEMON_NP 0
69 extern int pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
70 extern int pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
71
72 #define PGN_TEST_PRI 23
73
74 static pthread_attr_t pgn_attr;
75 static pthread_attr_t pgn_thr_attr;
76 static pthread_barrier_t pgn_barrier;
77
78
79 /*
80 * Verify that the stack pointer of a context is consistent with where the
81 * attributes indicate.
82 */
83 static void
84 pgn_verif_thr_stack(pthread_attr_t *attr)
85 {
86 size_t stksz;
87 void *stk;
88 ucontext_t ctx;
89 uint32_t sp;
90
91 VERIFY0(getcontext(&ctx));
92 VERIFY0(pthread_attr_getstack(attr, &stk, &stksz));
93 VERIFY3P(stk, !=, NULL);
94 VERIFY3S(stksz, !=, 0);
95 sp = ctx.uc_mcontext.gregs[R_SP];
96 VERIFY3U(sp, >, (uintptr_t)stk);
97 VERIFY3U(sp, <, (uintptr_t)stk + stksz);
98 }
99
100
101 static void
102 pgn_test_fini(void)
103 {
104 int ret;
105
106 ret = pthread_barrier_wait(&pgn_barrier);
107 VERIFY(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD);
108 VERIFY0(pthread_attr_destroy(&pgn_attr));
109 VERIFY0(pthread_attr_destroy(&pgn_thr_attr));
110 VERIFY0(pthread_barrier_destroy(&pgn_barrier));
111 }
112
113 static void
114 pgn_test_init(void)
115 {
116 VERIFY0(pthread_attr_init(&pgn_attr));
117 VERIFY0(pthread_attr_init(&pgn_thr_attr));
118 VERIFY0(pthread_barrier_init(&pgn_barrier, NULL, 2));
119 }
|