flat assembler
Message board for the users of flat assembler.

Index > Linux > Problem with structure size of sysinfo

Author
Thread Post new topic Reply to topic
yyc650102



Joined: 01 Jun 2006
Posts: 11
yyc650102
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)

Code:
#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...
Code:
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 !!
Post 09 Jun 2006, 06:06
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 465
Location: Czech republic, Slovak republic
Feryno
I don't have a time to recalculate this structure, but you must allways align 8 pointers and handles (8 byte size)

so like fictive structure:
dd ? ; something
dd ? ; dummy
dq handle
dw ? ; something
dw ? ; dummy
dw ? ; dummy
dw ? ; dummy
dq pointer

maybe the end of structure should be aligned 8 (I don't know this exactly)?
Post 09 Jun 2006, 07:52
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.