Skip to content

Commit 5c45fe1

Browse files
committed
internal/runtime/syscall: rename to internal/runtime/syscall/linux
All code in internal/runtime/syscall is Linux-specific, so better move it to a new linux sub-directory. This way it will be easier to factor out runtime syscall code from other platforms, e.g. Windows. Updates #51087. Change-Id: Idd2a52444b33bf3ad576b47fd232e990cdc8ae75 Reviewed-on: https://go-review.googlesource.com/c/go/+/689155 Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 592c2db commit 5c45fe1

33 files changed

+70
-71
lines changed

src/cmd/internal/objabi/pkgspecial.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var runtimePkgs = []string{
5656
"internal/runtime/math",
5757
"internal/runtime/strconv",
5858
"internal/runtime/sys",
59-
"internal/runtime/syscall",
59+
"internal/runtime/syscall/linux",
6060

6161
"internal/abi",
6262
"internal/bytealg",
@@ -94,7 +94,7 @@ var allowAsmABIPkgs = []string{
9494
"syscall",
9595
"internal/bytealg",
9696
"internal/chacha8rand",
97-
"internal/runtime/syscall",
97+
"internal/runtime/syscall/linux",
9898
"internal/runtime/startlinetest",
9999
}
100100

src/go/build/deps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var depsRules = `
9191
< internal/msan
9292
< internal/asan
9393
< internal/runtime/sys
94-
< internal/runtime/syscall
94+
< internal/runtime/syscall/linux
9595
< internal/runtime/atomic
9696
< internal/runtime/exithook
9797
< internal/runtime/gc

src/internal/coverage/pkid.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ package coverage
3131
// slot: 6 path='internal/runtime/math' hard-coded id: 6
3232
// slot: 7 path='internal/bytealg' hard-coded id: 7
3333
// slot: 8 path='internal/goexperiment'
34-
// slot: 9 path='internal/runtime/syscall' hard-coded id: 8
34+
// slot: 9 path='internal/runtime/syscall/linux' hard-coded id: 8
3535
// slot: 10 path='runtime' hard-coded id: 9
3636
// fatal error: runtime.addCovMeta
3737
//
@@ -66,7 +66,7 @@ var rtPkgs = [...]string{
6666
"internal/runtime/strconv",
6767
"internal/runtime/sys",
6868
"internal/runtime/maps",
69-
"internal/runtime/syscall",
69+
"internal/runtime/syscall/linux",
7070
"internal/runtime/cgroup",
7171
"internal/stringslite",
7272
"runtime",

src/internal/runtime/cgroup/cgroup_linux.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package cgroup
77
import (
88
"internal/bytealg"
99
"internal/runtime/strconv"
10-
"internal/runtime/syscall"
10+
"internal/runtime/syscall/linux"
1111
)
1212

1313
var (
@@ -77,10 +77,10 @@ type CPU struct {
7777
func (c CPU) Close() {
7878
switch c.version {
7979
case V1:
80-
syscall.Close(c.quotaFD)
81-
syscall.Close(c.periodFD)
80+
linux.Close(c.quotaFD)
81+
linux.Close(c.periodFD)
8282
case V2:
83-
syscall.Close(c.quotaFD)
83+
linux.Close(c.quotaFD)
8484
default:
8585
throw("impossible cgroup version")
8686
}
@@ -112,7 +112,7 @@ func OpenCPU(scratch []byte) (CPU, error) {
112112
case 1:
113113
n2 := copy(base[n:], v1QuotaFile)
114114
path := base[:n+n2]
115-
quotaFD, errno := syscall.Open(&path[0], syscall.O_RDONLY|syscall.O_CLOEXEC, 0)
115+
quotaFD, errno := linux.Open(&path[0], linux.O_RDONLY|linux.O_CLOEXEC, 0)
116116
if errno != 0 {
117117
// This may fail if this process was migrated out of
118118
// the cgroup found by FindCPU and that cgroup has been
@@ -122,7 +122,7 @@ func OpenCPU(scratch []byte) (CPU, error) {
122122

123123
n2 = copy(base[n:], v1PeriodFile)
124124
path = base[:n+n2]
125-
periodFD, errno := syscall.Open(&path[0], syscall.O_RDONLY|syscall.O_CLOEXEC, 0)
125+
periodFD, errno := linux.Open(&path[0], linux.O_RDONLY|linux.O_CLOEXEC, 0)
126126
if errno != 0 {
127127
// This may fail if this process was migrated out of
128128
// the cgroup found by FindCPU and that cgroup has been
@@ -139,7 +139,7 @@ func OpenCPU(scratch []byte) (CPU, error) {
139139
case 2:
140140
n2 := copy(base[n:], v2MaxFile)
141141
path := base[:n+n2]
142-
maxFD, errno := syscall.Open(&path[0], syscall.O_RDONLY|syscall.O_CLOEXEC, 0)
142+
maxFD, errno := linux.Open(&path[0], linux.O_RDONLY|linux.O_CLOEXEC, 0)
143143
if errno != 0 {
144144
// This may fail if this process was migrated out of
145145
// the cgroup found by FindCPU and that cgroup has been
@@ -200,7 +200,7 @@ func readV1Number(fd int) (int64, error) {
200200
//
201201
// Always read from the beginning of the file to get a fresh value.
202202
var b [64]byte
203-
n, errno := syscall.Pread(fd, b[:], 0)
203+
n, errno := linux.Pread(fd, b[:], 0)
204204
if errno != 0 {
205205
return 0, errSyscallFailed
206206
}
@@ -248,7 +248,7 @@ func readV2Limit(fd int) (float64, bool, error) {
248248
//
249249
// Always read from the beginning of the file to get a fresh value.
250250
var b [64]byte
251-
n, errno := syscall.Pread(fd, b[:], 0)
251+
n, errno := linux.Pread(fd, b[:], 0)
252252
if errno != 0 {
253253
return 0, false, errSyscallFailed
254254
}
@@ -345,22 +345,22 @@ func FindCPU(out []byte, scratch []byte) (int, Version, error) {
345345
// Returns ErrNoCgroup if the process is not in a CPU cgroup.
346346
func FindCPURelativePath(out []byte, scratch []byte) (int, Version, error) {
347347
path := []byte("/proc/self/cgroup\x00")
348-
fd, errno := syscall.Open(&path[0], syscall.O_RDONLY|syscall.O_CLOEXEC, 0)
349-
if errno == syscall.ENOENT {
348+
fd, errno := linux.Open(&path[0], linux.O_RDONLY|linux.O_CLOEXEC, 0)
349+
if errno == linux.ENOENT {
350350
return 0, 0, ErrNoCgroup
351351
} else if errno != 0 {
352352
return 0, 0, errSyscallFailed
353353
}
354354

355355
// The relative path always starts with /, so we can directly append it
356356
// to the mount point.
357-
n, version, err := parseCPURelativePath(fd, syscall.Read, out[:], scratch)
357+
n, version, err := parseCPURelativePath(fd, linux.Read, out[:], scratch)
358358
if err != nil {
359-
syscall.Close(fd)
359+
linux.Close(fd)
360360
return 0, 0, err
361361
}
362362

363-
syscall.Close(fd)
363+
linux.Close(fd)
364364
return n, version, nil
365365
}
366366

@@ -489,19 +489,19 @@ func FindCPUMountPoint(out []byte, scratch []byte) (int, error) {
489489
checkBufferSize(scratch, ParseSize)
490490

491491
path := []byte("/proc/self/mountinfo\x00")
492-
fd, errno := syscall.Open(&path[0], syscall.O_RDONLY|syscall.O_CLOEXEC, 0)
493-
if errno == syscall.ENOENT {
492+
fd, errno := linux.Open(&path[0], linux.O_RDONLY|linux.O_CLOEXEC, 0)
493+
if errno == linux.ENOENT {
494494
return 0, ErrNoCgroup
495495
} else if errno != 0 {
496496
return 0, errSyscallFailed
497497
}
498498

499-
n, err := parseCPUMount(fd, syscall.Read, out, scratch)
499+
n, err := parseCPUMount(fd, linux.Read, out, scratch)
500500
if err != nil {
501-
syscall.Close(fd)
501+
linux.Close(fd)
502502
return 0, err
503503
}
504-
syscall.Close(fd)
504+
linux.Close(fd)
505505

506506
return n, nil
507507
}

src/internal/runtime/cgroup/line_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type lineReader struct {
5555
// remainder of the line skipped. See next for more details.
5656
//
5757
// read is the function used to read more bytes from fd. This is usually
58-
// internal/runtime/syscall.Read. Note that this follows syscall semantics (not
58+
// internal/runtime/syscall/linux.Read. Note that this follows syscall semantics (not
5959
// io.Reader), so EOF is indicated with n=0, errno=0.
6060
func newLineReader(fd int, scratch []byte, read func(fd int, b []byte) (n int, errno uintptr)) *lineReader {
6161
return &lineReader{

0 commit comments

Comments
 (0)