Skip to content

Commit

Permalink
Added helpers for sup and ptrace syscalls
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
  • Loading branch information
GLVSKiriti committed Aug 8, 2024
1 parent 785f669 commit dae6cc6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/declarative/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,15 @@ func SymlinkSyscall(oldpath string, newpath string) error {
func LinkSyscall(oldpath string, newpath string) error {
return unix.Link(oldpath, newpath)
}

func DupSyscall(oldfd int) (int, error) {
newfd, err := unix.Dup(oldfd)
if err != nil {
return -1, err
}
return newfd, nil
}

func PtraceSyscall(pid int, signal int) error {
return unix.PtraceSyscall(pid, signal)
}
10 changes: 10 additions & 0 deletions pkg/declarative/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func (r *Hostrunner) ExecuteStep(ctx context.Context, test Test) error {
if err != nil {
return fmt.Errorf("link syscall failed with error: %v", err)
}
case "dup":
_, err := DupSyscall(*step.Args.Oldfd)
if err != nil {
return fmt.Errorf("dup syscall failed with error: %v", err)
}
case "ptrace":
err := PtraceSyscall(*step.Args.Pid, *step.Args.Ptracesignal)
if err != nil {
return fmt.Errorf("ptrace syscall failed with error: %v", err)
}
default:
return fmt.Errorf("unsupported syscall: %s", step.Syscall)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/declarative/yamltypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ type Args struct {
// For symlink and link syscalls
Oldpath *string `yaml:"oldpath,omitempty"`
Newpath *string `yaml:"newpath,omitempty"`

// For dup syscall
Oldfd *int `yaml:"oldfd,omitempty"`

// For ptrace syscall
Pid *int `yaml:"pid,omitempty"`
Ptracesignal *int `yaml:"ptracesignal,omitempty"`
}

type SyscallStep struct {
Expand Down

0 comments on commit dae6cc6

Please sign in to comment.