Skip to content

Instantly share code, notes, and snippets.

@beordle
Forked from ianlewis/sys_sum.go
Created January 11, 2022 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beordle/f3ac34ef236195ef51b75d43861e3c43 to your computer and use it in GitHub Desktop.
Save beordle/f3ac34ef236195ef51b75d43861e3c43 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