v0.8.0 ed3ae3d

go_linux_amd64.go RawHistoryFolder

1// Copyright 2011 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//go:build !cgo
6
7package fakecgo
8
9import "unsafe"
10
11//go:nosplit
12func _cgo_sys_thread_start(ts *ThreadStart) {
13	var attr pthread_attr_t
14	var ign, oset sigset_t
15	var p pthread_t
16	var size size_t
17	var err int
18
19	//fprintf(stderr, "runtime/cgo: _cgo_sys_thread_start: fn=%p, g=%p\n", ts->fn, ts->g); // debug
20	sigfillset(&ign)
21	pthread_sigmask(SIG_SETMASK, &ign, &oset)
22
23	pthread_attr_init(&attr)
24	pthread_attr_getstacksize(&attr, &size)
25	// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
26	ts.g.stackhi = uintptr(size)
27
28	err = _cgo_try_pthread_create(&p, &attr, unsafe.Pointer(threadentry_trampolineABI0), ts)
29
30	pthread_sigmask(SIG_SETMASK, &oset, nil)
31
32	if err != 0 {
33		print("fakecgo: pthread_create failed: ")
34		println(err)
35		abort()
36	}
37}
38
39// threadentry_trampolineABI0 maps the C ABI to Go ABI then calls the Go function
40//
41//go:linkname x_threadentry_trampoline threadentry_trampoline
42var x_threadentry_trampoline byte
43var threadentry_trampolineABI0 = &x_threadentry_trampoline
44
45//go:nosplit
46func threadentry(v unsafe.Pointer) unsafe.Pointer {
47	ts := *(*ThreadStart)(v)
48	free(v)
49
50	setg_trampoline(setg_func, uintptr(unsafe.Pointer(ts.g)))
51
52	// faking funcs in go is a bit a... involved - but the following works :)
53	fn := uintptr(unsafe.Pointer(&ts.fn))
54	(*(*func())(unsafe.Pointer(&fn)))()
55
56	return nil
57}
58
59// here we will store a pointer to the provided setg func
60var setg_func uintptr
61
62//go:nosplit
63func x_cgo_init(g *G, setg uintptr) {
64	var size size_t
65	var attr *pthread_attr_t
66
67	/* The memory sanitizer distributed with versions of clang
68	   before 3.8 has a bug: if you call mmap before malloc, mmap
69	   may return an address that is later overwritten by the msan
70	   library.  Avoid this problem by forcing a call to malloc
71	   here, before we ever call malloc.
72
73	   This is only required for the memory sanitizer, so it's
74	   unfortunate that we always run it.  It should be possible
75	   to remove this when we no longer care about versions of
76	   clang before 3.8.  The test for this is
77	   misc/cgo/testsanitizers.
78
79	   GCC works hard to eliminate a seemingly unnecessary call to
80	   malloc, so we actually use the memory we allocate.  */
81
82	setg_func = setg
83	attr = (*pthread_attr_t)(malloc(unsafe.Sizeof(*attr)))
84	if attr == nil {
85		println("fakecgo: malloc failed")
86		abort()
87	}
88	pthread_attr_init(attr)
89	pthread_attr_getstacksize(attr, &size)
90	// runtime/cgo uses __builtin_frame_address(0) instead of `uintptr(unsafe.Pointer(&size))`
91	// but this should be OK since we are taking the address of the first variable in this function.
92	g.stacklo = uintptr(unsafe.Pointer(&size)) - uintptr(size) + 4096
93	pthread_attr_destroy(attr)
94	free(unsafe.Pointer(attr))
95}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close