What is syscall.Syscall?

Can someone explain this function’s arguments and return value?
A standard library without documents, Thank you

func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)

For one thing, it’s deprecated:

Deprecated: this package is locked down. Callers should use the corresponding package in the golang.org/x/sys repository instead. That is also where updates required by new systems or versions should be applied. See The syscall package - Google Docs for more information.

Regarding the lack of detailed documentation on that specific function, I think it is because familiarity with syscalls is assumed if you are going to be using that package. What specifically do you find confusing about the arguments and return value? Except error, all arguments are of type uintptr. a[n] is short for argument[n]. r is short for response. Quoting from this answer:

trap: The API we want to call.

a1, a2, a3: Arguments to that API.

r1, r2, err: Whatever that API returns. There are three, but we would probably use only one of them.

Also - in addition to that package being deprecated, that function was already deprecated in favor of the variadic function SyscallN. Anyway, what are you trying to do and what problems are you running in to exactly?

1 Like

Thanks for @Dean_Davidson. Your information is very useful.

This explanation is certainly helpful, and like @andrewvo148 I think it should be with the documentation. I too wondered why “trap” was used as a variable name for the code to call (look at how you described it - why couldn’t that be in the documentation?). I’ll also note that I have literally wasted hours in the last 3 days going down the rabbit hole of Go documentation. Sometimes I can find Syscall / SyscallN, sometimes I can’t (even while attempting to save bookmarks in Brave browser). And getting/installing the Sys packages in the “right” way still eludes me. For mkwinsyscall, I finally threw up my hands and copied the source into a local .go file and built it. Maddening. (BTW, sorry for the rant - not directed to you - but to emphasize how helpful your seemingly simple response was).
More to the point now, I cannot get SyscallN to work, where Syscall (and associated code generated by mkwinsyscall) works to interface with Windows DLLs.
Specifically, I need to reference a legacy Windows DLL written in C (NOT a DLL of Windows itself). I have written the interfaces for Java and .NET (64-bit and 32-bit to match the required bitness of the legacy DLLs), so I have a pretty good idea of what should happen, and how to do it. But the issue with Go seems to relate to whether a value that is expected to be 32 bits (uint32 in Go land) by the C function in a 64-bit DLL (built with MS Visual Studio) is correctly passed to the C function. It seems SyscallN does not honor passing 32-bit parameters from 64-bit Go (I am using Go 1.18 on a Windows 10 machine). Would you have any suggestions on how to best proceed - I presume since Syscall was just deprecated in 1.17 it will be around for a while, but I’d prefer to do the “right” thing now.
Thanks,
Jack

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.