equal
deleted
inserted
replaced
1 // Copyright 2009 The Go Authors. All rights reserved. |
1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style |
2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. |
3 // license that can be found in the LICENSE file. |
4 |
4 |
|
5 //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris |
5 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris |
6 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris |
6 |
7 |
7 package unix |
8 package unix |
8 |
9 |
9 import ( |
10 import ( |
10 "bytes" |
11 "bytes" |
11 "sort" |
12 "sort" |
12 "sync" |
13 "sync" |
13 "syscall" |
14 "syscall" |
14 "unsafe" |
15 "unsafe" |
|
16 |
|
17 "golang.org/x/sys/internal/unsafeheader" |
15 ) |
18 ) |
16 |
19 |
17 var ( |
20 var ( |
18 Stdin = 0 |
21 Stdin = 0 |
19 Stdout = 1 |
22 Stdout = 1 |
74 // SignalNum returns the syscall.Signal for signal named s, |
77 // SignalNum returns the syscall.Signal for signal named s, |
75 // or 0 if a signal with such name is not found. |
78 // or 0 if a signal with such name is not found. |
76 // The signal name should start with "SIG". |
79 // The signal name should start with "SIG". |
77 func SignalNum(s string) syscall.Signal { |
80 func SignalNum(s string) syscall.Signal { |
78 signalNameMapOnce.Do(func() { |
81 signalNameMapOnce.Do(func() { |
79 signalNameMap = make(map[string]syscall.Signal) |
82 signalNameMap = make(map[string]syscall.Signal, len(signalList)) |
80 for _, signal := range signalList { |
83 for _, signal := range signalList { |
81 signalNameMap[signal.name] = signal.num |
84 signalNameMap[signal.name] = signal.num |
82 } |
85 } |
83 }) |
86 }) |
84 return signalNameMap[s] |
87 return signalNameMap[s] |
111 addr, errno := m.mmap(0, uintptr(length), prot, flags, fd, offset) |
114 addr, errno := m.mmap(0, uintptr(length), prot, flags, fd, offset) |
112 if errno != nil { |
115 if errno != nil { |
113 return nil, errno |
116 return nil, errno |
114 } |
117 } |
115 |
118 |
116 // Slice memory layout |
119 // Use unsafe to convert addr into a []byte. |
117 var sl = struct { |
120 var b []byte |
118 addr uintptr |
121 hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b)) |
119 len int |
122 hdr.Data = unsafe.Pointer(addr) |
120 cap int |
123 hdr.Cap = length |
121 }{addr, length, length} |
124 hdr.Len = length |
122 |
|
123 // Use unsafe to turn sl into a []byte. |
|
124 b := *(*[]byte)(unsafe.Pointer(&sl)) |
|
125 |
125 |
126 // Register mapping in m and return it. |
126 // Register mapping in m and return it. |
127 p := &b[cap(b)-1] |
127 p := &b[cap(b)-1] |
128 m.Lock() |
128 m.Lock() |
129 defer m.Unlock() |
129 defer m.Unlock() |