1
2
3
4
5 package main
6
7 import (
8 "bytes"
9 "fmt"
10 "os"
11 "syscall"
12 )
13
14 func gettid() int {
15 return syscall.Gettid()
16 }
17
18 func tidExists(tid int) (exists, supported bool) {
19 stat, err := os.ReadFile(fmt.Sprintf("/proc/self/task/%d/stat", tid))
20 if os.IsNotExist(err) {
21 return false, true
22 }
23
24 state := bytes.Fields(stat)[2]
25 return !(len(state) == 1 && state[0] == 'Z'), true
26 }
27
28 func getcwd() (string, error) {
29 if !syscall.ImplementsGetwd {
30 return "", nil
31 }
32
33
34
35
36 var buf [4096]byte
37 n, err := syscall.Getcwd(buf[:])
38 if err != nil {
39 return "", err
40 }
41
42 return string(buf[:n-1]), nil
43 }
44
45 func unshareFs() error {
46 err := syscall.Unshare(syscall.CLONE_FS)
47 if err != nil {
48 errno, ok := err.(syscall.Errno)
49 if ok && errno == syscall.EPERM {
50 return errNotPermitted
51 }
52 }
53 return err
54 }
55
56 func chdir(path string) error {
57 return syscall.Chdir(path)
58 }
59
View as plain text