Skip to content

Commit 5a356c1

Browse files
GLVSKiritiLucaGuerra
authored andcommitted
Added helpers for sup and ptrace syscalls
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
1 parent cdf1ffa commit 5a356c1

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

pkg/declarative/helpers.go

+12
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,15 @@ func SymlinkSyscall(oldpath string, newpath string) error {
112112
func LinkSyscall(oldpath string, newpath string) error {
113113
return unix.Link(oldpath, newpath)
114114
}
115+
116+
func DupSyscall(oldfd int) (int, error) {
117+
newfd, err := unix.Dup(oldfd)
118+
if err != nil {
119+
return -1, err
120+
}
121+
return newfd, nil
122+
}
123+
124+
func PtraceSyscall(pid int, signal int) error {
125+
return unix.PtraceSyscall(pid, signal)
126+
}

pkg/declarative/host.go

+10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ func (r *Hostrunner) ExecuteStep(ctx context.Context, test Test) error {
7575
if err != nil {
7676
return fmt.Errorf("link syscall failed with error: %v", err)
7777
}
78+
case "dup":
79+
_, err := DupSyscall(*step.Args.Oldfd)
80+
if err != nil {
81+
return fmt.Errorf("dup syscall failed with error: %v", err)
82+
}
83+
case "ptrace":
84+
err := PtraceSyscall(*step.Args.Pid, *step.Args.Ptracesignal)
85+
if err != nil {
86+
return fmt.Errorf("ptrace syscall failed with error: %v", err)
87+
}
7888
default:
7989
return fmt.Errorf("unsupported syscall: %s", step.Syscall)
8090
}

pkg/declarative/yamltypes.go

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ type Args struct {
4242
// For symlink and link syscalls
4343
Oldpath *string `yaml:"oldpath,omitempty"`
4444
Newpath *string `yaml:"newpath,omitempty"`
45+
46+
// For dup syscall
47+
Oldfd *int `yaml:"oldfd,omitempty"`
48+
49+
// For ptrace syscall
50+
Pid *int `yaml:"pid,omitempty"`
51+
Ptracesignal *int `yaml:"ptracesignal,omitempty"`
4552
}
4653

4754
type SyscallStep struct {

0 commit comments

Comments
 (0)