github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/race.go (about)

     1  // Copyright 2012 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 race
     6  
     7  // Public race detection API, present iff build with -race.
     8  
     9  package runtime
    10  
    11  import (
    12  	"unsafe"
    13  )
    14  
    15  func racefini()
    16  
    17  // RaceDisable disables handling of race events in the current goroutine.
    18  func RaceDisable()
    19  
    20  // RaceEnable re-enables handling of race events in the current goroutine.
    21  func RaceEnable()
    22  
    23  func RaceAcquire(addr unsafe.Pointer)
    24  func RaceRelease(addr unsafe.Pointer)
    25  func RaceReleaseMerge(addr unsafe.Pointer)
    26  
    27  func RaceRead(addr unsafe.Pointer)
    28  func RaceWrite(addr unsafe.Pointer)
    29  func RaceReadRange(addr unsafe.Pointer, len int)
    30  func RaceWriteRange(addr unsafe.Pointer, len int)
    31  
    32  func RaceSemacquire(s *uint32)
    33  func RaceSemrelease(s *uint32)
    34  
    35  // private interface for the runtime
    36  const raceenabled = true
    37  
    38  func raceReadObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
    39  	kind := t.kind & kindMask
    40  	if kind == kindArray || kind == kindStruct {
    41  		// for composite objects we have to read every address
    42  		// because a write might happen to any subobject.
    43  		racereadrangepc(addr, t.size, callerpc, pc)
    44  	} else {
    45  		// for non-composite objects we can read just the start
    46  		// address, as any write must write the first byte.
    47  		racereadpc(addr, callerpc, pc)
    48  	}
    49  }
    50  
    51  func raceWriteObjectPC(t *_type, addr unsafe.Pointer, callerpc, pc uintptr) {
    52  	kind := t.kind & kindMask
    53  	if kind == kindArray || kind == kindStruct {
    54  		// for composite objects we have to write every address
    55  		// because a write might happen to any subobject.
    56  		racewriterangepc(addr, t.size, callerpc, pc)
    57  	} else {
    58  		// for non-composite objects we can write just the start
    59  		// address, as any write must write the first byte.
    60  		racewritepc(addr, callerpc, pc)
    61  	}
    62  }
    63  
    64  //go:noescape
    65  func racereadpc(addr unsafe.Pointer, callpc, pc uintptr)
    66  
    67  //go:noescape
    68  func racewritepc(addr unsafe.Pointer, callpc, pc uintptr)
    69  
    70  //go:noescape
    71  func racereadrangepc(addr unsafe.Pointer, len uintptr, callpc, pc uintptr)
    72  
    73  //go:noescape
    74  func racewriterangepc(addr unsafe.Pointer, len uintptr, callpc, pc uintptr)
    75  
    76  //go:noescape
    77  func raceacquire(addr unsafe.Pointer)
    78  
    79  //go:noescape
    80  func racerelease(addr unsafe.Pointer)
    81  
    82  //go:noescape
    83  func raceacquireg(gp *g, addr unsafe.Pointer)
    84  
    85  //go:noescape
    86  func racereleaseg(gp *g, addr unsafe.Pointer)
    87  
    88  func racefingo()
    89  
    90  //go:noescape
    91  func racemalloc(p unsafe.Pointer, size uintptr)
    92  
    93  //go:noescape
    94  func racereleasemerge(addr unsafe.Pointer)
    95  
    96  type symbolizeContext struct {
    97  	pc   uintptr
    98  	fn   *byte
    99  	file *byte
   100  	line uintptr
   101  	off  uintptr
   102  	res  uintptr
   103  }
   104  
   105  var qq = [...]byte{'?', '?', 0}
   106  var dash = [...]byte{'-', 0}
   107  
   108  // Callback from C into Go, runs on g0.
   109  func racesymbolize(ctx *symbolizeContext) {
   110  	f := findfunc(ctx.pc)
   111  	if f == nil {
   112  		ctx.fn = &qq[0]
   113  		ctx.file = &dash[0]
   114  		ctx.line = 0
   115  		ctx.off = ctx.pc
   116  		ctx.res = 1
   117  		return
   118  	}
   119  
   120  	ctx.fn = funcname(f)
   121  	var file string
   122  	ctx.line = uintptr(funcline(f, ctx.pc, &file))
   123  	ctx.file = &bytes(file)[0] // assume NUL-terminated
   124  	ctx.off = ctx.pc - f.entry
   125  	ctx.res = 1
   126  	return
   127  }