...

Text file src/runtime/cgo/gcc_unix.c

Documentation: runtime/cgo

     1// Copyright 2009 The Go Authors. All rights reserved.
     2// Use of this source code is governed by a BSD-style
     3// license that can be found in the LICENSE file.
     4
     5//go:build unix
     6
     7#include "libcgo.h"
     8#include "libcgo_unix.h"
     9
    10// Platform-specific hooks.
    11void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((weak));
    12void (*x_cgo_threadentry_platform)(void) __attribute__((weak));
    13
    14static void (*setg_gcc)(void*);
    15
    16// _cgo_set_stacklo sets g->stacklo based on the stack size.
    17// This is common code called from x_cgo_init, which is itself
    18// called by rt0_go in the runtime package.
    19static void
    20_cgo_set_stacklo(G *g)
    21{
    22	uintptr bounds[2];
    23
    24	x_cgo_getstackbound(bounds);
    25
    26	g->stacklo = bounds[0];
    27
    28	// Sanity check the results now, rather than getting a
    29	// morestack on g0 crash.
    30	if (g->stacklo >= g->stackhi) {
    31		fprintf(stderr, "runtime/cgo: bad stack bounds: lo=%p hi=%p\n", (void*)(g->stacklo), (void*)(g->stackhi));
    32		abort();
    33	}
    34}
    35
    36void
    37x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
    38{
    39	setg_gcc = setg;
    40	_cgo_set_stacklo(g);
    41
    42	if (x_cgo_inittls) {
    43		x_cgo_inittls(tlsg, tlsbase);
    44	}
    45}
    46
    47void*
    48threadentry(void *v)
    49{
    50	ThreadStart ts;
    51
    52	ts = *(ThreadStart*)v;
    53	_cgo_tsan_acquire();
    54	free(v);
    55	_cgo_tsan_release();
    56
    57	if (x_cgo_threadentry_platform != NULL) {
    58		x_cgo_threadentry_platform();
    59	}
    60
    61	crosscall1(ts.fn, setg_gcc, ts.g);
    62	return NULL;
    63}

View as plain text