Skip to content

Instantly share code, notes, and snippets.

@ianlewis
Created May 25, 2019 16:42
Show Gist options
  • Save ianlewis/7ed8257e07878a91aba1e12c39be7df8 to your computer and use it in GitHub Desktop.
Save ianlewis/7ed8257e07878a91aba1e12c39be7df8 to your computer and use it in GitHub Desktop.
Simple syscall in gVisor
// Copyright 2018 The gVisor Authors.
//
// 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
import (
"gvisor.googlesource.com/gvisor/pkg/sentry/arch"
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel"
)
// Sum returns the sum of the first two passed integer arguments
func Sum(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
num1 := args[0].Int()
num2 := args[1].Int()
return uintptr(num1 + num2), nil, nil
}
// Copyright 2018 The gVisor Authors.
//
// 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 main
import (
"fmt"
"os"
"syscall"
)
const SUM = 400
func main() {
r1, _, errNo := syscall.RawSyscall(SUM, 5, 6, 0)
if errNo != 0 {
fmt.Fprintf(os.Stderr, "ERROR: %d\n", errNo)
os.Exit(1)
}
fmt.Printf("%d\n", r1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment