github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/runtime/wincallback.go (about) 1 // Copyright 2014 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 // +build ignore 6 7 // Generate Windows callback assembly file. 8 9 package main 10 11 import ( 12 "bytes" 13 "fmt" 14 "io/ioutil" 15 "os" 16 ) 17 18 const maxCallback = 2000 19 20 func main() { 21 var buf bytes.Buffer 22 23 buf.WriteString(`// generated by wincallback.go; run go generate 24 25 // runtime·callbackasm is called by external code to 26 // execute Go implemented callback function. It is not 27 // called from the start, instead runtime·compilecallback 28 // always returns address into runtime·callbackasm offset 29 // appropriately so different callbacks start with different 30 // CALL instruction in runtime·callbackasm. This determines 31 // which Go callback function is executed later on. 32 TEXT runtime·callbackasm(SB),7,$0 33 `) 34 for i := 0; i < maxCallback; i++ { 35 buf.WriteString("\tCALL\truntime·callbackasm1(SB)\n") 36 } 37 38 err := ioutil.WriteFile("zcallback_windows.s", buf.Bytes(), 0666) 39 if err != nil { 40 fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) 41 os.Exit(2) 42 } 43 }