Text file src/runtime/cgo/gcc_ppc64x.c

     1  // Copyright 2014 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 ppc64 || ppc64le
     6  
     7  #include <pthread.h>
     8  #include <string.h>
     9  #include <signal.h>
    10  #include "libcgo.h"
    11  #include "libcgo_unix.h"
    12  
    13  static void *threadentry(void*);
    14  
    15  void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
    16  static void (*setg_gcc)(void*);
    17  
    18  void
    19  x_cgo_init(G *g, void (*setg)(void*), void **tlsbase)
    20  {
    21  	setg_gcc = setg;
    22  	_cgo_set_stacklo(g, NULL);
    23  }
    24  
    25  void
    26  _cgo_sys_thread_start(ThreadStart *ts)
    27  {
    28  	pthread_attr_t attr;
    29  	sigset_t ign, oset;
    30  	pthread_t p;
    31  	size_t size;
    32  	int err;
    33  
    34  	sigfillset(&ign);
    35  	pthread_sigmask(SIG_SETMASK, &ign, &oset);
    36  
    37  	pthread_attr_init(&attr);
    38  	pthread_attr_getstacksize(&attr, &size);
    39  	// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
    40  	ts->g->stackhi = size;
    41  	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
    42  
    43  	pthread_sigmask(SIG_SETMASK, &oset, nil);
    44  
    45  	if (err != 0) {
    46  		fatalf("pthread_create failed: %s", strerror(err));
    47  	}
    48  }
    49  
    50  extern void crosscall_ppc64(void (*fn)(void), void *g);
    51  
    52  static void*
    53  threadentry(void *v)
    54  {
    55  	ThreadStart ts;
    56  
    57  	ts = *(ThreadStart*)v;
    58  	_cgo_tsan_acquire();
    59  	free(v);
    60  	_cgo_tsan_release();
    61  
    62  	// Save g for this thread in C TLS
    63  	setg_gcc((void*)ts.g);
    64  
    65  	crosscall_ppc64(ts.fn, (void*)ts.g);
    66  	return nil;
    67  }
    68  

View as plain text