mirror of
https://github.com/golang/go
synced 2024-11-23 05:20:11 -07:00
runtime/cgo: get getstackbound for set_stacklo
Change-Id: Ia63a4604449b5e460e6f54c962fb7d6db2bc6a43 Reviewed-on: https://go-review.googlesource.com/c/go/+/519457 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
21293b6b87
commit
52e17c2e4d
@ -17,17 +17,17 @@ static void (*setg_gcc)(void*);
|
||||
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
|
||||
|
@ -85,20 +85,18 @@ _cgo_wait_runtime_init_done(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.
|
||||
@ -106,8 +104,6 @@ void _cgo_set_stacklo(G *g, pthread_attr_t *pattr)
|
||||
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.
|
||||
|
@ -19,7 +19,7 @@ void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
|
||||
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
|
||||
@ -37,12 +37,12 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
||||
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);
|
||||
|
@ -56,7 +56,7 @@ threadentry(void *v)
|
||||
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
|
||||
@ -74,12 +74,12 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
||||
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);
|
||||
|
@ -68,6 +68,11 @@ void _cgo_sys_thread_start(ThreadStart *ts);
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
/*
|
||||
* 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.
|
||||
|
Loading…
Reference in New Issue
Block a user