github.com/dara-project/godist@v0.0.0-20200823115410-e0c80c8f0c78/src/os/proc.go (about) 1 // Copyright 2009 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 // Process etc. 6 7 package os 8 9 import ( 10 "dara" 11 "runtime" 12 "syscall" 13 ) 14 15 // Args hold the command-line arguments, starting with the program name. 16 var Args []string 17 18 func init() { 19 if runtime.GOOS == "windows" { 20 // Initialized in exec_windows.go. 21 return 22 } 23 Args = runtime_args() 24 } 25 26 func runtime_args() []string // in package runtime 27 28 // Getuid returns the numeric user id of the caller. 29 // 30 // On Windows, it returns -1. 31 func Getuid() int { 32 id := syscall.Getuid() 33 // DARA Instrumentation 34 if runtime.Is_dara_profiling_on() { 35 runtime.Dara_Debug_Print(func() { println("[GETUID]") }) 36 retInfo := dara.GeneralType{Type:dara.INTEGER, Integer: id} 37 syscallInfo := dara.GeneralSyscall{dara.DSYS_GETUID, 0, 1, [10]dara.GeneralType{}, [10]dara.GeneralType{retInfo}} 38 runtime.Report_Syscall_To_Scheduler(dara.DSYS_GETUID, syscallInfo) 39 } 40 return id 41 } 42 43 // Geteuid returns the numeric effective user id of the caller. 44 // 45 // On Windows, it returns -1. 46 func Geteuid() int { 47 id := syscall.Geteuid() 48 // DARA Instrumentation 49 if runtime.Is_dara_profiling_on() { 50 runtime.Dara_Debug_Print(func() { println("[GETEUID]") }) 51 retInfo := dara.GeneralType{Type:dara.INTEGER, Integer: id} 52 syscallInfo := dara.GeneralSyscall{dara.DSYS_GETEUID, 0, 1, [10]dara.GeneralType{}, [10]dara.GeneralType{retInfo}} 53 runtime.Report_Syscall_To_Scheduler(dara.DSYS_GETEUID, syscallInfo) 54 } 55 return id 56 } 57 58 // Getgid returns the numeric group id of the caller. 59 // 60 // On Windows, it returns -1. 61 func Getgid() int { 62 id := syscall.Getgid() 63 // DARA Instrumentation 64 if runtime.Is_dara_profiling_on() { 65 runtime.Dara_Debug_Print(func() { println("[GETGID]") }) 66 retInfo := dara.GeneralType{Type:dara.INTEGER, Integer: id} 67 syscallInfo := dara.GeneralSyscall{dara.DSYS_GETGID, 0, 1, [10]dara.GeneralType{}, [10]dara.GeneralType{retInfo}} 68 runtime.Report_Syscall_To_Scheduler(dara.DSYS_GETGID, syscallInfo) 69 } 70 return id 71 } 72 73 // Getegid returns the numeric effective group id of the caller. 74 // 75 // On Windows, it returns -1. 76 func Getegid() int { 77 id := syscall.Getegid() 78 // DARA Instrumentation 79 if runtime.Is_dara_profiling_on() { 80 runtime.Dara_Debug_Print(func() { println("[GETEGID]") }) 81 retInfo := dara.GeneralType{Type:dara.INTEGER, Integer: id} 82 syscallInfo := dara.GeneralSyscall{dara.DSYS_GETEGID, 0, 1, [10]dara.GeneralType{}, [10]dara.GeneralType{retInfo}} 83 runtime.Report_Syscall_To_Scheduler(dara.DSYS_GETEGID, syscallInfo) 84 } 85 return id 86 } 87 88 // Getgroups returns a list of the numeric ids of groups that the caller belongs to. 89 // 90 // On Windows, it returns syscall.EWINDOWS. See the os/user package 91 // for a possible alternative. 92 func Getgroups() ([]int, error) { 93 gids, e := syscall.Getgroups() 94 // DARA Instrumentation 95 if runtime.Is_dara_profiling_on() { 96 runtime.Dara_Debug_Print(func() { println("[GETGROUPS]") }) 97 retInfo1 := dara.GeneralType{Type: dara.ARRAY, Integer: len(gids)} 98 retInfo2 := dara.GeneralType{Type: dara.ERROR, Unsupported: dara.UNSUPPORTEDVAL} 99 syscallInfo := dara.GeneralSyscall{dara.DSYS_GETGROUPS, 0, 2, [10]dara.GeneralType{}, [10]dara.GeneralType{retInfo1, retInfo2}} 100 runtime.Report_Syscall_To_Scheduler(dara.DSYS_GETGROUPS, syscallInfo) 101 } 102 return gids, NewSyscallError("getgroups", e) 103 } 104 105 // Exit causes the current program to exit with the given status code. 106 // Conventionally, code zero indicates success, non-zero an error. 107 // The program terminates immediately; deferred functions are not run. 108 func Exit(code int) { 109 if runtime.Is_dara_profiling_on() { 110 runtime.Dara_Debug_Print(func() { 111 print("[EXIT] : ") 112 println(code) 113 }) 114 argInfo := dara.GeneralType{Type: dara.INTEGER, Integer: code} 115 syscallInfo := dara.GeneralSyscall{dara.DSYS_EXIT, 1, 0, [10]dara.GeneralType{argInfo}, [10]dara.GeneralType{}} 116 runtime.Report_Syscall_To_Scheduler(dara.DSYS_EXIT, syscallInfo) 117 } 118 if code == 0 { 119 // Give race detector a chance to fail the program. 120 // Racy programs do not have the right to finish successfully. 121 runtime_beforeExit() 122 } 123 syscall.Exit(code) 124 } 125 126 func runtime_beforeExit() // implemented in runtime