]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/testsanitizers/msan4.go
all: make copyright headers consistent with one space after period
[gostls13.git] / misc / cgo / testsanitizers / msan4.go
1 // Copyright 2015 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 package main
6
7 // The memory profiler can call copy from a slice on the system stack,
8 // which msan used to think meant a reference to uninitialized memory.
9
10 /*
11 #include <time.h>
12 #include <unistd.h>
13
14 extern void Nop(char*);
15
16 // Use weak as a hack to permit defining a function even though we use export.
17 void poison() __attribute__ ((weak));
18
19 // Poison the stack.
20 void poison() {
21         char a[1024];
22         Nop(&a[0]);
23 }
24
25 */
26 import "C"
27
28 import (
29         "runtime"
30 )
31
32 func main() {
33         runtime.MemProfileRate = 1
34         start(100)
35 }
36
37 func start(i int) {
38         if i == 0 {
39                 return
40         }
41         C.poison()
42         // Tie up a thread.
43         // We won't actually wait for this sleep to complete.
44         go func() { C.sleep(1) }()
45         start(i - 1)
46 }
47
48 //export Nop
49 func Nop(*C.char) {
50 }