tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Questions regarding 'struct modstat'



In article <Pine.NEB.4.64.1511040630430.19019%vps1.whooppee.com@localhost>,
Paul Goyette  <paul%whooppee.com@localhost> wrote:
>In sys/sys/module.h, we have the following definition of the 'struct 
>modstat' structure, (used by modctl(MODCTL_STAT, ...) to return kernel
>data to userland):
>
>...
>/*
>  * This structure intentionally has the same layout for 32 and 64
>  * bit builds.
>  */
>typedef struct modstat {
>         char            ms_name[MAXMODNAME];
>         char            ms_required[MAXMODNAME * MAXMODDEPS];
>         uint64_t        ms_addr;
>         modsrc_t        ms_source;
>         modclass_t      ms_class;
>         u_int           ms_size;
>         u_int           ms_refcnt;
>         u_int           ms_reserved[4];
>} modstat_t;
>...
>
>I have some questions:
>
>1. Despite the comment, aren't the u_int fields of different sizes in
>    32- vs 64-bit builds?  The comment seems to be somewhat misleading.

u_int is 32 bits in both ILP32 and LP64, so it is fine. It would have
been better to use uint32_t instead.

>2. Is there any assurance that the module's load address (in ms_addr)
>    can fit in a uint64_t?

Yes, for all platforms (currently). If it was uintptr_t be it would have
been different size in ILP32/LP64.

>3. If I wanted to add another address field (ms_modaddr for the address
>    of the module's 'struct module'), would it be better to
>
> 	a) insert a new uint64_t in the middle of this structure,
> 	   after the current ms_addr field,
>
> 	b) insert a new uint64_t in the middle of this structure,
> 	   immediately before the ms_reserved[] array,
>
> 	c) append a new uint64_t at the end of this structure, or
>
> 	d) replace some number of the ms_reserved[] array with a
> 	   new uint64_t structure (and how many to replace?)

You need to replace 2 u_ints (each u_int has 4 bytes and you need
8 bytes for a uint64_t).

christos



Home | Main Index | Thread Index | Old Index