void
x_cgo_init(G *g, void (*setg)(void*))
{
- pthread_attr_t *attr;
+ uintptr *pbounds;
// Deal with memory sanitizer/clang interaction.
// See gcc_linux_amd64.c for details.
setg_gcc = setg;
- attr = (pthread_attr_t*)malloc(sizeof *attr);
- if (attr == NULL) {
+ pbounds = (uintptr*)malloc(2 * sizeof(uintptr));
+ if (pbounds == NULL) {
fatalf("malloc failed: %s", strerror(errno));
}
- _cgo_set_stacklo(g, attr);
- free(attr);
+ _cgo_set_stacklo(g, pbounds);
+ free(pbounds);
}
void
// _cgo_set_stacklo sets g->stacklo based on the stack size.
// This is common code called from x_cgo_init, which is itself
// called by rt0_go in the runtime package.
-void _cgo_set_stacklo(G *g, pthread_attr_t *pattr)
+void _cgo_set_stacklo(G *g, uintptr *pbounds)
{
- pthread_attr_t attr;
- size_t size;
+ uintptr bounds[2];
- // pattr can be passed in by the caller; see gcc_linux_amd64.c.
- if (pattr == NULL) {
- pattr = &attr;
+ // pbounds can be passed in by the caller; see gcc_linux_amd64.c.
+ if (pbounds == NULL) {
+ pbounds = &bounds[0];
}
- pthread_attr_init(pattr);
- pthread_attr_getstacksize(pattr, &size);
+ x_cgo_getstackbound(pbounds);
- g->stacklo = (uintptr)(__builtin_frame_address(0)) - size + 4096;
+ g->stacklo = *pbounds;
// Sanity check the results now, rather than getting a
// morestack on g0 crash.
fprintf(stderr, "runtime/cgo: bad stack bounds: lo=%p hi=%p\n", (void*)(g->stacklo), (void*)(g->stackhi));
abort();
}
-
- pthread_attr_destroy(pattr);
}
// Store the g into a thread-specific value associated with the pthread key pthread_g.
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
{
- pthread_attr_t *attr;
+ uintptr *pbounds;
/* The memory sanitizer distributed with versions of clang
before 3.8 has a bug: if you call mmap before malloc, mmap
malloc, so we actually use the memory we allocate. */
setg_gcc = setg;
- attr = (pthread_attr_t*)malloc(sizeof *attr);
- if (attr == NULL) {
+ pbounds = (uintptr*)malloc(2 * sizeof(uintptr));
+ if (pbounds == NULL) {
fatalf("malloc failed: %s", strerror(errno));
}
- _cgo_set_stacklo(g, attr);
- free(attr);
+ _cgo_set_stacklo(g, pbounds);
+ free(pbounds);
if (x_cgo_inittls) {
x_cgo_inittls(tlsg, tlsbase);
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
{
- pthread_attr_t *attr;
+ uintptr *pbounds;
/* The memory sanitizer distributed with versions of clang
before 3.8 has a bug: if you call mmap before malloc, mmap
malloc, so we actually use the memory we allocate. */
setg_gcc = setg;
- attr = (pthread_attr_t*)malloc(sizeof *attr);
- if (attr == NULL) {
+ pbounds = (uintptr*)malloc(2 * sizeof(uintptr));
+ if (pbounds == NULL) {
fatalf("malloc failed: %s", strerror(errno));
}
- _cgo_set_stacklo(g, attr);
- free(attr);
+ _cgo_set_stacklo(g, pbounds);
+ free(pbounds);
if (x_cgo_inittls) {
x_cgo_inittls(tlsg, tlsbase);
*/
uintptr_t _cgo_wait_runtime_init_done(void);
+/*
+ * Get the low and high boundaries of the stack.
+ */
+void x_cgo_getstackbound(uintptr bounds[2]);
+
/*
* Prints error then calls abort. For linux and android.
*/
/*
* Initialize g->stacklo.
*/
-extern void _cgo_set_stacklo(G *, pthread_attr_t*);
+extern void _cgo_set_stacklo(G *, uintptr *);
/*
* Call pthread_create, retrying on EAGAIN.