Text file src/runtime/cgo/gcc_linux_s390x.c

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

View as plain text