]> Cypherpunks.ru repositories - gostls13.git/blob - src/runtime/cgo/gcc_stack_unix.c
3826322661772186d7a77882f3aae7368c0b953c
[gostls13.git] / src / runtime / cgo / gcc_stack_unix.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 //go:build unix && !darwin
6
7 #ifndef _GNU_SOURCE // pthread_getattr_np
8 #define _GNU_SOURCE
9 #endif
10
11 #include <pthread.h>
12 #include "libcgo.h"
13
14 void
15 x_cgo_getstackbound(G *g)
16 {
17         pthread_attr_t attr;
18         void *addr;
19         size_t size;
20
21         pthread_attr_init(&attr);
22 #if defined(__GLIBC__) || defined(__sun)
23         pthread_getattr_np(pthread_self(), &attr);  // GNU extension
24         pthread_attr_getstack(&attr, &addr, &size); // low address
25 #else
26         pthread_attr_getstacksize(&attr, &size);
27         addr = __builtin_frame_address(0) + 4096 - size;
28 #endif
29         g->stacklo = (uintptr)addr;
30         // NOTE: don't change g->stackhi. We are called from asmcgocall
31         // which saves the stack depth based on g->stackhi.
32 }