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 genasm() { 21 var buf bytes.Buffer 22 23 buf.WriteString(`// generated by wincallback.go; run go generate 24 25 // runtimecallbackasm is called by external code to 26 // execute Go implemented callback function. It is not 27 // called from the start, instead runtimecompilecallback 28 // always returns address into runtimecallbackasm offset 29 // appropriately so different callbacks start with different 30 // CALL instruction in runtimecallbackasm. This determines 31 // which Go callback function is executed later on. 32 TEXT runtimecallbackasm(SB),7,$0 33 `) 34 for i := 0; i < maxCallback; i++ { 35 buf.WriteString("\tCALL\truntimecallbackasm1(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 } 44 45 func gengo() { 46 var buf bytes.Buffer 47 48 buf.WriteString(fmt.Sprintf(`// generated by wincallback.go; run go generate 49 50 package runtime 51 52 const cb_max = %d // maximum number of windows callbacks allowed 53 `, maxCallback)) 54 err := ioutil.WriteFile("zcallback_windows.go", buf.Bytes(), 0666) 55 if err != nil { 56 fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) 57 os.Exit(2) 58 } 59 } 60 61 func main() { 62 genasm() 63 gengo() 64 } 65