How should this C code be translated to Go inside the runtime package ?
struct timespec {
int64_t tv_sec;
int32_t tv_nsec;
};
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
My first guess is:
type timespec struct{
tv_sec int64
tv_nsec int32
}
type itimerspec struct {
it_interval timespec
it_value timespec
}
However this is wrong in 2 ways due to int64_t being 8bytes aligned on mips O32 ABI and armv7 ABI.
1. theses structs can be stack allocated to a 4 bytes align giving a coin-flip on whether or not it is 8bytes aligned. (only causes problems if the kernel doesn't want to copy the 64bits value if it's unaligned)
2. the layout of itimerspec is wrong, since Go will think timespec is 12bytes wide, when it is 16bytes wide padding taken into account.
For point 2 you can manually add _ int32 in itimerspec.
I don't know how to fix point 1 without manually adding something like:
type timespec struct{
_ align8
tv_sec int64
tv_nsec int32
}
or:
type timespec struct{
tv_sec int64_aligned8
tv_nsec int32
}
to the compiler.