1 // Copyright 2018 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.
5 // This test source is used by both TestBigStackCallbackCgo (linked
6 // directly into the Go binary) and TestBigStackCallbackSyscall
7 // (compiled into a DLL).
12 #ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
13 #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
16 typedef void callback(char*);
18 // Allocate a stack that's much larger than the default.
19 static const int STACK_SIZE
= 16<<20;
21 static callback
*bigStackCallback
;
23 static void useStack(int bytes
) {
24 // Windows doesn't like huge frames, so we grow the stack 64k at a time.
26 if (bytes
< sizeof x
) {
29 useStack(bytes
- sizeof x
);
33 static DWORD WINAPI
threadEntry(LPVOID lpParam
) {
34 useStack(STACK_SIZE
- (128<<10));
38 void bigStack(callback
*cb
) {
39 bigStackCallback
= cb
;
40 HANDLE hThread
= CreateThread(NULL
, STACK_SIZE
, threadEntry
, NULL
, STACK_SIZE_PARAM_IS_A_RESERVATION
, NULL
);
41 if (hThread
== NULL
) {
42 fprintf(stderr
, "CreateThread failed\n");
45 WaitForSingleObject(hThread
, INFINITE
);