-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move syscall routines and stubs
- Loading branch information
Showing
3 changed files
with
109 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package acheron | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func execIndirectSyscall(ssn uint16, gateAddr uintptr, argh ...uintptr) (errcode uint32) | ||
|
||
func execDirectSyscall(ssn uint16, argh ...uintptr) (errcode uint32) | ||
|
||
// Syscall executes an indirect syscall with the given function hash and arguments. Returns the error code if it fails. | ||
func (a *Acheron) Syscall(fnHash uint64, args ...uintptr) error { | ||
sys, err := a.resolver.GetSyscall(fnHash) | ||
if err != nil { | ||
return err | ||
} | ||
if errCode := execIndirectSyscall(sys.SSN, sys.TrampolineAddr, args...); errCode != 0 { // !NT_SUCCESS | ||
return errors.New(fmt.Sprintf("syscall failed with error code %d", errCode)) | ||
} | ||
return nil | ||
} | ||
|
||
// DirectSyscall executes a direct syscall with the given function hash and arguments. Returns the error code if it fails. | ||
func (a *Acheron) DirectSyscall(fnHash uint64, args ...uintptr) error { | ||
sys, err := a.resolver.GetSyscall(fnHash) | ||
if err != nil { | ||
return err | ||
} | ||
if errCode := execDirectSyscall(sys.SSN, args...); errCode != 0 { // !NT_SUCCESS | ||
return errors.New(fmt.Sprintf("syscall failed with error code %d", errCode)) | ||
} | ||
return nil | ||
} |