To get the result of sysinfo by syscall in fasm, I have to declare memory size for storing the information. However, the size of the structure seems not match what Linux declared in kernel.h...
So, I use gcc (v4.1.0) to confirm the size of the structure...
Please compare the following 3 structures... (Fedora Code 5, x86_64)
#include <iostream>
using namespace std;
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram;/* Amount of shared memory */
unsigned long bufferram;/* Memory used by buffers */
unsigned long totalswap;/* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned short pad; /* explicit padding for m68k */
unsigned long totalhigh;/* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
struct sysinfo_2 {
unsigned short procs; /* Number of current processes */
unsigned short pad; /* explicit padding for m68k */
};
struct sysinfo_3 {
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned short pad; /* explicit padding for m68k */
};
int main()
{
cout << "Size of char = " << sizeof(char) << endl;
cout << "Size of short = " << sizeof(short) << endl;
cout << "Size of int = " << sizeof(int) << endl;
cout << "Size of long = " << sizeof(long) << endl;
cout << "Size of double = " << sizeof(double) << endl;
cout << "Size of sysinfo = " << sizeof(sysinfo) << endl;
cout << "Size of sysinfo_2 = " << sizeof(sysinfo_2) << endl;
cout << "Size of sysinfo_3 = " << sizeof(sysinfo_3) << endl;
exit(0);
}
and result is...
Size of char = 1
Size of short = 2
Size of int = 4
Size of long = 8
Size of double = 8
Size of sysinfo = 112
Size of sysinfo_2 = 4
Size of sysinfo_3 = 16
the size of sysinfo should be 104 instead of 112, the size of sysinfo_2 is correct and the size of sysinfo_3 should be 12 instead of 16...
anyone knows what's going on ?? gcc bug?
Thanks a lot !!