I am tring to write something like following in runtime package:

/usr/local/go/src/runtime/write_err_ios.go
```
// +build ios
// +build arm arm64

package runtime

import "unsafe"

var (
gWriteBuf [1024]byte
gWritePos int
)

//go:nosplit
func asmAslLogWrap(b unsafe.Pointer)

func writeErr(b []byte) {
// Write to stderr for command-line programs.
write(2, unsafe.Pointer(&b[0]), int32(len(b)))

for _, v := range b {
if v == 0 {
v = '0'
}
gWriteBuf[gWritePos] = v
gWritePos++
if v == '\n' || gWritePos == len(gWriteBuf)-1 {
gWriteBuf[gWritePos] = 0
asmAslLogWrap(unsafe.Pointer( &gWriteBuf[0] ))
gWritePos = 0
}
}
}

//go:cgo_import_static asl_log_wrap
```

/usr/local/go/src/runtime/write_err_ios_arm64.s
```
// +build ios,arm64

#include "funcdata.h"
#include "textflag.h"

TEXT runtime·asmAslLogWrap(SB),NOSPLIT,$0
    MOVD b+0(FP), R0
    B asl_log_wrap(SB)

```


```
// +build ios

package cgo

/*
#include <asl.h>
#include <stdlib.h>

void asl_log_wrap(const char *str) {
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "%s", str);
}
*/
import "C"
```

I can not write cgo in runtime package, The compiler failed with import 
cycle.
I can not write cgo in runtime/cgo package and register a function pointer 
in runtime package. It failed with a lot of runtime error "fatat error" msg 
when painc was called.I think something enter a loop in systemstack() stuff.

Then I tried to write asm to call the c function directly,then I got :
```
runtime: unexpected return pc for runtime.notetsleepg called from 
0xffffffffffffffff
fatal error: unknown caller pc

runtime stack:
runtime.throw(0x100d40317, 0x11)
/usr/local/go/src/runtime/panic.go:566 +0x80
runtime.gentraceback(0x1005a0704, 0x139523ef0, 0x0, 0x13957c9c0, 0x0, 0x0, 
0x7fffffff, 0x16e84adb0, 0x0, 0x0, ...)
/usr/local/go/src/runtime/traceback.go:317 +0x147c
runtime.scanstack(0x13957c9c0, 0x13951b228)
/usr/local/go/src/runtime/mgcmark.go:783 +0x3c4
runtime.scang(0x13957c9c0, 0x13951b228)
/usr/local/go/src/runtime/proc.go:828 +0xd0
runtime.markroot.func1()
/usr/local/go/src/runtime/mgcmark.go:242 +0xc0
runtime.systemstack(0x13951b500)
/usr/local/go/src/runtime/asm_arm64.s:237 +0x90
runtime.mstart()
/usr/local/go/src/runtime/proc.go:1079

goroutine 26 [running]:
runtime.systemstack_switch()
/usr/local/go/src/runtime/asm_arm64.s:186 +0x8 fp=0x139525660 sp=0x139525650
runtime.markroot(0x13951b228, 0x10000000b)
/usr/local/go/src/runtime/mgcmark.go:247 +0x440 fp=0x1395256f0 
sp=0x139525660
runtime.gcDrain(0x13951b228, 0x5)
/usr/local/go/src/runtime/mgcmark.go:969 +0x304 fp=0x139525740 
sp=0x1395256f0
runtime.gcBgMarkWorker(0x13951a000)
/usr/local/go/src/runtime/mgc.go:1460 +0x624 fp=0x1395257b0 sp=0x139525740
runtime.goexit()
/usr/local/go/src/runtime/asm_arm64.s:983 +0x4 fp=0x1395257b0 sp=0x1395257b0
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1349 +0x88
```
It looks like writeErr can be called successful a lot of times,but it will 
crash when golang is doing some gc stuff.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to