Passing Structures by Value
When structures are passed by value, the structure is loaded into as many parameter registers as are needed. When the data model of an application and the data model of the kernel extension differ, the values in the registers cannot be used directly. Instead, the registers must be stored in a temporary variable.
For example:
Note: This example builds upon the structure definitions
defined in Dual Implementation.
/* Application prototype: syscall9(struct foo f); */
syscall9(unsigned long a1, unsigned long a1)
{
union {
struct foo f1; /* Structure for 64-bit caller. */
struct foo32 f2; /* Structure for 32-bit caller. */
unsigned long p64[2]; /* Overlay for parameter registers
* when caller is 64-bit program
*/
unsigned int p32[2]; /* Overlay for parameter registers
* when caller is 32-bit program
*/
} uarg;
if (IS64U()) {
uarg.p64[0] = a1;
uarg.p64[1] = a2;
/* Now uarg.f1 can be used */
.
.
.
}
else {
uarg.p32[0] = a1;
uarg.p32[1] = a2;
/* Now uarg.f2 can be used */
.
.
.
}
}