I am working on a dynamic language written in go. I am using C to allow this language to access syscalls (for linux at least). C's any
type is a void*
, so I thought that I can pass them into a syscall. I tested using some code which looks like:
#include <stdio.h>
#include <unistd.h>
static inline long int vpsyscall(void* a0, void* a1, void* a2, void* a3) {
return syscall(*((int*)a0), a1, a2, a3);
}
int main() {
int a_ = 1;
void* a = &a_;
int b_ = 1;
void* b = &b_;
char* c_ = "hello\n";
void* c = &c_;
int d_ = 6;
void* d = &d_;
long int ret = tusksyscall(a, b, c, d);
printf("%ld\n", ret);
}
I expect that this code should output
hello
0
to the console.
Instead, I get
-1
which (at least to my knowledge) means error.
Strangely, when I pass 1 argument (the ax), it works
int _ax = 39;
void* ax = &_ax;
long int ret = vpsyscall(ax, 0, 0, 0);
printf("%ld\n", ret);
It gives me the desired output (in this case, just the pid). So, whats going on here, and how can I pass void pointers to a syscall (if there is any way)?