mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add itimer types to linux package, strace
PiperOrigin-RevId: 215278262 Change-Id: Icd10384c99802be6097be938196044386441e282
This commit is contained in:
@@ -44,6 +44,7 @@ go_library(
|
||||
"signal.go",
|
||||
"socket.go",
|
||||
"time.go",
|
||||
"timer.go",
|
||||
"tty.go",
|
||||
"uio.go",
|
||||
"utsname.go",
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2018 Google Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package linux
|
||||
|
||||
// itimer types for getitimer(2) and setitimer(2), from
|
||||
// include/uapi/linux/time.h.
|
||||
const (
|
||||
ITIMER_REAL = 0
|
||||
ITIMER_VIRTUAL = 1
|
||||
ITIMER_PROF = 2
|
||||
)
|
||||
@@ -53,9 +53,9 @@ var linuxAMD64 = SyscallMap{
|
||||
33: makeSyscallInfo("dup2", Hex, Hex),
|
||||
34: makeSyscallInfo("pause"),
|
||||
35: makeSyscallInfo("nanosleep", Timespec, PostTimespec),
|
||||
36: makeSyscallInfo("getitimer", Hex, PostItimerVal),
|
||||
36: makeSyscallInfo("getitimer", ItimerType, PostItimerVal),
|
||||
37: makeSyscallInfo("alarm", Hex),
|
||||
38: makeSyscallInfo("setitimer", Hex, ItimerVal, PostItimerVal),
|
||||
38: makeSyscallInfo("setitimer", ItimerType, ItimerVal, PostItimerVal),
|
||||
39: makeSyscallInfo("getpid"),
|
||||
40: makeSyscallInfo("sendfile", Hex, Hex, Hex, Hex),
|
||||
41: makeSyscallInfo("socket", SockFamily, SockType, SockProtocol),
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gvisor.googlesource.com/gvisor/pkg/abi"
|
||||
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
|
||||
"gvisor.googlesource.com/gvisor/pkg/bits"
|
||||
"gvisor.googlesource.com/gvisor/pkg/eventchannel"
|
||||
@@ -46,6 +47,22 @@ var LogMaximumSize uint = DefaultLogMaximumSize
|
||||
// do anything useful with binary text dump of byte array arguments.
|
||||
var EventMaximumSize uint
|
||||
|
||||
// ItimerTypes are the possible itimer types.
|
||||
var ItimerTypes = abi.ValueSet{
|
||||
{
|
||||
Value: linux.ITIMER_REAL,
|
||||
Name: "ITIMER_REAL",
|
||||
},
|
||||
{
|
||||
Value: linux.ITIMER_VIRTUAL,
|
||||
Name: "ITIMER_VIRTUAL",
|
||||
},
|
||||
{
|
||||
Value: linux.ITIMER_PROF,
|
||||
Name: "ITIMER_PROF",
|
||||
},
|
||||
}
|
||||
|
||||
func iovecs(t *kernel.Task, addr usermem.Addr, iovcnt int, printContent bool, maxBytes uint64) string {
|
||||
if iovcnt < 0 || iovcnt > linux.UIO_MAXIOV {
|
||||
return fmt.Sprintf("%#x (error decoding iovecs: invalid iovcnt)", addr)
|
||||
@@ -322,6 +339,8 @@ func (i *SyscallInfo) pre(t *kernel.Task, args arch.SyscallArguments, maximumBlo
|
||||
output = append(output, futex(uint64(args[arg].Uint())))
|
||||
case PtraceRequest:
|
||||
output = append(output, PtraceRequestSet.Parse(args[arg].Uint64()))
|
||||
case ItimerType:
|
||||
output = append(output, ItimerTypes.Parse(uint64(args[arg].Int())))
|
||||
case Oct:
|
||||
output = append(output, "0o"+strconv.FormatUint(args[arg].Uint64(), 8))
|
||||
case Hex:
|
||||
|
||||
@@ -150,6 +150,9 @@ const (
|
||||
// Utimbuf is a pointer to a struct utimbuf.
|
||||
Utimbuf
|
||||
|
||||
// Rusage is a struct rusage, formatted after syscall execution.
|
||||
Rusage
|
||||
|
||||
// CloneFlags are clone(2) flags.
|
||||
CloneFlags
|
||||
|
||||
@@ -165,8 +168,8 @@ const (
|
||||
// PtraceRequest is the ptrace(2) request.
|
||||
PtraceRequest
|
||||
|
||||
// Rusage is a struct rusage, formatted after syscall execution.
|
||||
Rusage
|
||||
// ItimerType is an itimer type (ITIMER_REAL, etc).
|
||||
ItimerType
|
||||
)
|
||||
|
||||
// defaultFormat is the syscall argument format to use if the actual format is
|
||||
|
||||
@@ -25,19 +25,6 @@ import (
|
||||
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
|
||||
)
|
||||
|
||||
// ItimerType denotes the type of interval timer.
|
||||
type ItimerType int
|
||||
|
||||
// Interval timer types from <sys/time.h>.
|
||||
const (
|
||||
// ItimerReal equals to ITIMER_REAL.
|
||||
ItimerReal ItimerType = iota
|
||||
// ItimerVirtual equals to ITIMER_VIRTUAL.
|
||||
ItimerVirtual
|
||||
// ItimerProf equals to ITIMER_PROF.
|
||||
ItimerProf
|
||||
)
|
||||
|
||||
const nsecPerSec = int64(time.Second)
|
||||
|
||||
// copyItimerValIn copies an ItimerVal from the untrusted app range to the
|
||||
@@ -83,13 +70,13 @@ func copyItimerValOut(t *kernel.Task, addr usermem.Addr, itv *linux.ItimerVal) e
|
||||
}
|
||||
}
|
||||
|
||||
func findTimer(t *kernel.Task, w ItimerType) (*ktime.Timer, error) {
|
||||
switch w {
|
||||
case ItimerReal:
|
||||
func findTimer(t *kernel.Task, which int32) (*ktime.Timer, error) {
|
||||
switch which {
|
||||
case linux.ITIMER_REAL:
|
||||
return t.ThreadGroup().Timer().RealTimer, nil
|
||||
case ItimerVirtual:
|
||||
case linux.ITIMER_VIRTUAL:
|
||||
return t.ThreadGroup().Timer().VirtualTimer, nil
|
||||
case ItimerProf:
|
||||
case linux.ITIMER_PROF:
|
||||
return t.ThreadGroup().Timer().ProfTimer, nil
|
||||
default:
|
||||
return nil, syscall.EINVAL
|
||||
@@ -98,7 +85,7 @@ func findTimer(t *kernel.Task, w ItimerType) (*ktime.Timer, error) {
|
||||
|
||||
// Getitimer implements linux syscall getitimer(2).
|
||||
func Getitimer(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
timerID := ItimerType(args[0].Int())
|
||||
timerID := args[0].Int()
|
||||
val := args[1].Pointer()
|
||||
|
||||
timer, err := findTimer(t, timerID)
|
||||
@@ -116,7 +103,7 @@ func Getitimer(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Sys
|
||||
|
||||
// Setitimer implements linux syscall setitimer(2).
|
||||
func Setitimer(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
timerID := ItimerType(args[0].Int())
|
||||
timerID := args[0].Int()
|
||||
newVal := args[1].Pointer()
|
||||
oldVal := args[2].Pointer()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user