github.com/eframework-cn/EP.GO.UTIL@v1.0.0/xos/goid_getg.go (about)

     1  //-----------------------------------------------------------------------//
     2  //                     GNU GENERAL PUBLIC LICENSE                        //
     3  //                        Version 2, June 1991                           //
     4  //                                                                       //
     5  // Copyright (C) EFramework, https://eframework.cn, All rights reserved. //
     6  // Everyone is permitted to copy and distribute verbatim copies          //
     7  // of this license document, but changing it is not allowed.             //
     8  //                   SEE LICENSE.md FOR MORE DETAILS.                    //
     9  //-----------------------------------------------------------------------//
    10  
    11  package xos
    12  
    13  import (
    14  	"fmt"
    15  	"unsafe"
    16  )
    17  
    18  const (
    19  	GOID_OFFSET uintptr = 152
    20  )
    21  
    22  func init() {
    23  	fmt.Println("GOID_OFFSET: ", GOID_OFFSET)
    24  }
    25  
    26  func goid_getg() int64 {
    27  	g := getg()
    28  	if g == 0 {
    29  		return 0
    30  	} else {
    31  		p := (*int64)(unsafe.Pointer(g + GOID_OFFSET))
    32  		return *p
    33  	}
    34  }
    35  
    36  func getg() uintptr