github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/runtime/cgo/gcc_windows_386.c (about)

     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  #define WIN32_LEAN_AND_MEAN
     6  #include <windows.h>
     7  #include <process.h>
     8  #include <stdlib.h>
     9  #include <stdio.h>
    10  #include <errno.h>
    11  #include "libcgo.h"
    12  #include "libcgo_windows.h"
    13  
    14  static void threadentry(void*);
    15  static DWORD *tls_g;
    16  
    17  void
    18  x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
    19  {
    20  	tls_g = (DWORD *)tlsg;
    21  }
    22  
    23  
    24  void
    25  _cgo_sys_thread_start(ThreadStart *ts)
    26  {
    27  	_cgo_beginthread(threadentry, ts);
    28  }
    29  
    30  static void
    31  threadentry(void *v)
    32  {
    33  	ThreadStart ts;
    34  
    35  	ts = *(ThreadStart*)v;
    36  	free(v);
    37  
    38  	// minit queries stack bounds from the OS.
    39  
    40  	/*
    41  	 * Set specific keys in thread local storage.
    42  	 */
    43  	asm volatile (
    44  		"movl %0, %%fs:0(%1)\n"	// MOVL tls0, 0(tls_g)(FS)
    45  		"movl %%fs:0(%1), %%eax\n"	// MOVL 0(tls_g)(FS), tmp
    46  		"movl %2, 0(%%eax)\n"	// MOVL g, 0(AX)
    47  		:: "r"(ts.tls), "r"(*tls_g), "r"(ts.g) : "%eax"
    48  	);
    49  
    50  	crosscall_386(ts.fn);
    51  }