Beispiel #1
0
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
{
    pthread_attr_t attr;
    size_t size;

    setg_gcc = setg;
    pthread_attr_init(&attr);
    pthread_attr_getstacksize(&attr, &size);
    g->stacklo = (uintptr)&attr - size + 4096;
    pthread_attr_destroy(&attr);

    if (x_cgo_inittls) {
        x_cgo_inittls(tlsg, tlsbase);
    }
}
Beispiel #2
0
void
x_cgo_init(G* g, void (*setg)(void*))
{
	pthread_attr_t *attr;
	size_t size;

	/* The memory sanitizer distributed with versions of clang
	   before 3.8 has a bug: if you call mmap before malloc, mmap
	   may return an address that is later overwritten by the msan
	   library.  Avoid this problem by forcing a call to malloc
	   here, before we ever call malloc.

	   This is only required for the memory sanitizer, so it's
	   unfortunate that we always run it.  It should be possible
	   to remove this when we no longer care about versions of
	   clang before 3.8.  The test for this is
	   misc/cgo/testsanitizers.

	   GCC works hard to eliminate a seemingly unnecessary call to
	   malloc, so we actually use the memory we allocate.  */

	setg_gcc = setg;
	attr = (pthread_attr_t*)malloc(sizeof *attr);
	if (attr == NULL) {
		fatalf("malloc failed: %s", strerror(errno));
	}
	pthread_attr_init(attr);
	pthread_attr_getstacksize(attr, &size);
	g->stacklo = (uintptr)&size - size + 4096;
	pthread_attr_destroy(attr);
	free(attr);

	if (x_cgo_inittls) {
		x_cgo_inittls();
	}
}