title: How to set SA_ONSTACK flag
body: <p>My Go application connect to IBM MQ.</p>
  
  <p>When my application throws segmentation violation error (signal SIGSEGV), signal handlers registered by IBM MQ make my application throw "non-Go code set up signal handler without SA_ONSTACK flag".</p>
  
  <p>So how can I set that flag?</p>
  
  <h2>My code</h2>
  
  <pre><code>package main
  
  import (
      "fmt"
      "github.com/ibm-messaging/mq-golang/ibmmq"
  )
  
  type A struct {
      Str string
  }
  
  type B struct {
      Apointer *A
  }
  
  func main() {
      connectIBMMQ()
  
      b := B{}
      fmt.Println(b.Apointer.Str)
  }
  
  const (
      QMgrName       = `QMgrName`
      ChannelName    = `ChannelName`
      ConnectionName = `0.0.0.0(1416)`
      Username       = `username`
      Password       = `password`
  )
  
  func connectIBMMQ() {
      mqcd := ibmmq.NewMQCD()
      mqcd.ChannelName = ChannelName
      mqcd.ConnectionName = ConnectionName
  
      csp := ibmmq.NewMQCSP()
      csp.AuthenticationType = ibmmq.MQCSP_AUTH_USER_ID_AND_PWD
      csp.UserId = Username
      csp.Password = Password
  
      cno := ibmmq.NewMQCNO()
      cno.ClientConn = mqcd
      cno.Options = ibmmq.MQCNO_CLIENT_BINDING + ibmmq.MQCNO_RECONNECT + ibmmq.MQCNO_HANDLE_SHARE_BLOCK
      cno.SecurityParms = csp
  
      ibmmq.Connx(QMgrName, cno)
  }
  
  </code></pre>
  
  <h2>Ref</h2>
  
  <p><a href="https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.1.0/com.ibm.mq.dev.doc/q025880_.htm" rel="nofollow noreferrer">https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.1.0/com.ibm.mq.dev.doc/q025880_.htm</a>
  <a href="https://golang.org/pkg/os/signal/#hdr-Go_programs_that_use_cgo_or_SWIG" rel="nofollow noreferrer">https://golang.org/pkg/os/signal/#hdr-Go_programs_that_use_cgo_or_SWIG</a></p>
  
  <h2>Full error</h2>
  
  <pre><code>signal 11 received but handler not on signal stack
  fatal error: non-Go code set up signal handler without SA_ONSTACK flag
  
  runtime stack:
  runtime: unexpected return pc for runtime.sigtramp called from 0x7f60f6e9a517
  stack: frame={sp:0xc000046628, fp:0xc000046680} stack=[0xc00003e578,0xc000046978)
  000000c000046528:  000000c000046530  00000000004549a0 &lt;runtime.throw.func1+0&gt; 
  000000c000046538:  00000000004e2c3b  0000000000000039 
  000000c000046548:  000000c000046568  00000000004415df &lt;runtime.sigNotOnStack+127&gt; 
  000000c000046558:  00000000004e2c3b  0000000000000039 
  000000c000046568:  000000c000046618  0000000000440c6d &lt;runtime.sigtrampgo+749&gt; 
  000000c000046578:  000000000000000b  000000c000046600 
  000000c000046588:  000000c000046880  0000000000000000 
  000000c000046598:  0000000000000000  000000c000046628 
  000000c0000465a8:  0000000000000000  0000000000000000 
  000000c0000465b8:  0000000000000000  0000000000000000 
  000000c0000465c8:  0000000000000000  000000c000000180 
  000000c0000465d8:  0000000000000000  ffffffffffffffff 
  000000c0000465e8:  0000000000000000  0000000000000000 
  000000c0000465f8:  0000000000000000  000000c000002000 
  000000c000046608:  0000000000000000  0000000000008000 
  000000c000046618:  000000c000046670  0000000000459a33 &lt;runtime.sigtramp+67&gt; 
  000000c000046628: &lt;000000000000000b  000000c0000469b0 
  000000c000046638:  000000c000046880  000000c000046880 
  000000c000046648:  000000c0000469b0  0000000000000000 
  000000c000046658:  000000000000000b  000000c000046670 
  000000c000046668:  00007f60f78213c0  000000000262e400 
  000000c000046678: !00007f60f6e9a517 &gt;000000c000046690 
  000000c000046688:  8e26f8f48c919100  0000000000000000 
  000000c000046698:  0000000000000000  0000000000000008 
  000000c0000466a8:  0000000000000000  000000c000000180 
  000000c0000466b8:  0000000000000000  0000000000000000 
  000000c0000466c8:  0000000000000000  0000000000000000 
  000000c0000466d8:  0000000000000000  0000000000000000 
  000000c0000466e8:  0000000000000000  0000000000000000 
  000000c0000466f8:  0000000000000000  0000000000000000 
  000000c000046708:  0000000000000000  0000000000000000 
  000000c000046718:  0000000000000000  000000c000046f88 
  000000c000046728:  0000000000000004  0000000000000012 
  000000c000046738:  00000000004f21e1  0000000000000000 
  000000c000046748:  00007f60f6e9b45a  0000000000000000 
  000000c000046758:  0000000000000000  0000000000000000 
  000000c000046768:  0000000000000000  0000000000000000 
  000000c000046778:  0000000000000000 
  runtime.throw(0x4e2c3b, 0x39)
      /usr/local/go/src/runtime/panic.go:617 +0x72
  runtime.sigNotOnStack(0xb)
      /usr/local/go/src/runtime/signal_unix.go:576 +0x7f
  runtime.sigtrampgo(0xb, 0xc0000469b0, 0xc000046880)
      /usr/local/go/src/runtime/signal_unix.go:334 +0x2ed
  runtime: unexpected return pc for runtime.sigtramp called from 0x7f60f6e9a517
  stack: frame={sp:0xc000046628, fp:0xc000046680} stack=[0xc00003e578,0xc000046978)
  000000c000046528:  000000c000046530  00000000004549a0 &lt;runtime.throw.func1+0&gt; 
  000000c000046538:  00000000004e2c3b  0000000000000039 
  000000c000046548:  000000c000046568  00000000004415df &lt;runtime.sigNotOnStack+127&gt; 
  000000c000046558:  00000000004e2c3b  0000000000000039 
  000000c000046568:  000000c000046618  0000000000440c6d &lt;runtime.sigtrampgo+749&gt; 
  000000c000046578:  000000000000000b  000000c000046600 
  000000c000046588:  000000c000046880  0000000000000000 
  000000c000046598:  0000000000000000  000000c000046628 
  000000c0000465a8:  0000000000000000  0000000000000000 
  000000c0000465b8:  0000000000000000  0000000000000000 
  000000c0000465c8:  0000000000000000  000000c000000180 
  000000c0000465d8:  0000000000000000  ffffffffffffffff 
  000000c0000465e8:  0000000000000000  0000000000000000 
  000000c0000465f8:  0000000000000000  000000c000002000 
  000000c000046608:  0000000000000000  0000000000008000 
  000000c000046618:  000000c000046670  0000000000459a33 &lt;runtime.sigtramp+67&gt; 
  000000c000046628: &lt;000000000000000b  000000c0000469b0 
  000000c000046638:  000000c000046880  000000c000046880 
  000000c000046648:  000000c0000469b0  0000000000000000 
  000000c000046658:  000000000000000b  000000c000046670 
  000000c000046668:  00007f60f78213c0  000000000262e400 
  000000c000046678: !00007f60f6e9a517 &gt;000000c000046690 
  000000c000046688:  8e26f8f48c919100  0000000000000000 
  000000c000046698:  0000000000000000  0000000000000008 
  000000c0000466a8:  0000000000000000  000000c000000180 
  000000c0000466b8:  0000000000000000  0000000000000000 
  000000c0000466c8:  0000000000000000  0000000000000000 
  000000c0000466d8:  0000000000000000  0000000000000000 
  000000c0000466e8:  0000000000000000  0000000000000000 
  000000c0000466f8:  0000000000000000  0000000000000000 
  000000c000046708:  0000000000000000  0000000000000000 
  000000c000046718:  0000000000000000  000000c000046f88 
  000000c000046728:  0000000000000004  0000000000000012 
  000000c000046738:  00000000004f21e1  0000000000000000 
  000000c000046748:  00007f60f6e9b45a  0000000000000000 
  000000c000046758:  0000000000000000  0000000000000000 
  000000c000046768:  0000000000000000  0000000000000000 
  000000c000046778:  0000000000000000 
  runtime.sigtramp(0xc000046690, 0x8e26f8f48c919100, 0x0, 0x0, 0x8, 0x0, 0xc000000180, 0x0, 0x0, 0x0, ...)
      /usr/local/go/src/runtime/sys_linux_amd64.s:357 +0x43
  
  goroutine 17 [syscall, locked to thread]:
  runtime.goexit()
      /usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc00004afe8 sp=0xc00004afe0 pc=0x457e41
  
  goroutine 1 [running]:
      goroutine running on other thread; stack unavailable
  </code></pre>