Text file src/runtime/testdata/testwintls/main.c

     1  // Copyright 2023 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 <windows.h>
     6  
     7  int main(int argc, char **argv) {
     8      if (argc < 3) {
     9          return 1;
    10      }
    11      // Allocate more than 64 TLS indices
    12      // so the Go runtime doesn't find
    13      // enough space in the TEB TLS slots.
    14      for (int i = 0; i < 65; i++) {
    15          TlsAlloc();
    16      }
    17      HMODULE hlib = LoadLibrary(argv[1]);
    18      if (hlib == NULL) {
    19          return 2;
    20      }
    21      FARPROC proc = GetProcAddress(hlib, argv[2]);
    22      if (proc == NULL) {
    23          return 3;
    24      }
    25      if (proc() != 42) {
    26          return 4;
    27      }
    28      return 0;
    29  }

View as plain text