2009-06-01 23:14:39 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Process etc.
|
|
|
|
|
|
|
|
package os
|
|
|
|
|
2014-09-24 16:50:54 -06:00
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"syscall"
|
|
|
|
)
|
2009-06-01 23:14:39 -06:00
|
|
|
|
2011-11-15 12:54:00 -07:00
|
|
|
// Args hold the command-line arguments, starting with the program name.
|
2011-11-14 12:06:50 -07:00
|
|
|
var Args []string
|
2009-06-01 23:14:39 -06:00
|
|
|
|
cmd/cc, cmd/ld, runtime: disallow conservative data/bss objects
In linker, refuse to write conservative (array of pointers) as the
garbage collection type for any variable in the data/bss GC program.
In the linker, attach the Go type to an already-read C declaration
during dedup. This gives us Go types for C globals for free as long
as the cmd/dist-generated Go code contains the declaration.
(Most runtime C declarations have a corresponding Go declaration.
Both are bss declarations and so the linker dedups them.)
In cmd/dist, add a few more C files to the auto-Go-declaration list
in order to get Go type information for the C declarations into the linker.
In C compiler, mark all non-pointer-containing global declarations
and all string data as NOPTR. This allows them to exist in C files
without any corresponding Go declaration. Count C function pointers
as "non-pointer-containing", since we have no heap-allocated C functions.
In runtime, add NOPTR to the remaining pointer-containing declarations,
none of which refer to Go heap objects.
In runtime, also move os.Args and syscall.envs data into runtime-owned
variables. Otherwise, in programs that do not import os or syscall, the
runtime variables named os.Args and syscall.envs will be missing type
information.
I believe that this CL eliminates the final source of conservative GC scanning
in non-SWIG Go programs, and therefore...
Fixes #909.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/149770043
2014-09-24 14:55:26 -06:00
|
|
|
func init() {
|
2014-09-24 16:50:54 -06:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Initialized in exec_windows.go.
|
|
|
|
return
|
|
|
|
}
|
cmd/cc, cmd/ld, runtime: disallow conservative data/bss objects
In linker, refuse to write conservative (array of pointers) as the
garbage collection type for any variable in the data/bss GC program.
In the linker, attach the Go type to an already-read C declaration
during dedup. This gives us Go types for C globals for free as long
as the cmd/dist-generated Go code contains the declaration.
(Most runtime C declarations have a corresponding Go declaration.
Both are bss declarations and so the linker dedups them.)
In cmd/dist, add a few more C files to the auto-Go-declaration list
in order to get Go type information for the C declarations into the linker.
In C compiler, mark all non-pointer-containing global declarations
and all string data as NOPTR. This allows them to exist in C files
without any corresponding Go declaration. Count C function pointers
as "non-pointer-containing", since we have no heap-allocated C functions.
In runtime, add NOPTR to the remaining pointer-containing declarations,
none of which refer to Go heap objects.
In runtime, also move os.Args and syscall.envs data into runtime-owned
variables. Otherwise, in programs that do not import os or syscall, the
runtime variables named os.Args and syscall.envs will be missing type
information.
I believe that this CL eliminates the final source of conservative GC scanning
in non-SWIG Go programs, and therefore...
Fixes #909.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/149770043
2014-09-24 14:55:26 -06:00
|
|
|
Args = runtime_args()
|
|
|
|
}
|
|
|
|
|
|
|
|
func runtime_args() []string // in package runtime
|
|
|
|
|
2009-06-01 23:14:39 -06:00
|
|
|
// Getuid returns the numeric user id of the caller.
|
2017-06-29 16:47:29 -06:00
|
|
|
//
|
|
|
|
// On Windows, it returns -1.
|
2009-12-15 16:40:16 -07:00
|
|
|
func Getuid() int { return syscall.Getuid() }
|
2009-06-01 23:14:39 -06:00
|
|
|
|
|
|
|
// Geteuid returns the numeric effective user id of the caller.
|
2017-06-29 16:47:29 -06:00
|
|
|
//
|
|
|
|
// On Windows, it returns -1.
|
2009-12-15 16:40:16 -07:00
|
|
|
func Geteuid() int { return syscall.Geteuid() }
|
2009-06-01 23:14:39 -06:00
|
|
|
|
|
|
|
// Getgid returns the numeric group id of the caller.
|
2017-06-29 16:47:29 -06:00
|
|
|
//
|
|
|
|
// On Windows, it returns -1.
|
2009-12-15 16:40:16 -07:00
|
|
|
func Getgid() int { return syscall.Getgid() }
|
2009-06-01 23:14:39 -06:00
|
|
|
|
|
|
|
// Getegid returns the numeric effective group id of the caller.
|
2017-06-29 16:47:29 -06:00
|
|
|
//
|
|
|
|
// On Windows, it returns -1.
|
2009-12-15 16:40:16 -07:00
|
|
|
func Getegid() int { return syscall.Getegid() }
|
2009-06-01 23:14:39 -06:00
|
|
|
|
|
|
|
// Getgroups returns a list of the numeric ids of groups that the caller belongs to.
|
2017-06-29 16:47:29 -06:00
|
|
|
//
|
|
|
|
// On Windows, it returns syscall.EWINDOWS. See the os/user package
|
|
|
|
// for a possible alternative.
|
2011-11-01 19:49:08 -06:00
|
|
|
func Getgroups() ([]int, error) {
|
2011-04-02 15:28:58 -06:00
|
|
|
gids, e := syscall.Getgroups()
|
|
|
|
return gids, NewSyscallError("getgroups", e)
|
2009-06-01 23:14:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exit causes the current program to exit with the given status code.
|
|
|
|
// Conventionally, code zero indicates success, non-zero an error.
|
2015-02-10 07:26:26 -07:00
|
|
|
// The program terminates immediately; deferred functions are not run.
|
|
|
|
func Exit(code int) {
|
|
|
|
if code == 0 {
|
|
|
|
// Give race detector a chance to fail the program.
|
|
|
|
// Racy programs do not have the right to finish successfully.
|
|
|
|
runtime_beforeExit()
|
|
|
|
}
|
|
|
|
syscall.Exit(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runtime_beforeExit() // implemented in runtime
|