Question

There is an array in kernel called zone_table according to page_alloc.c it is an array of pointers pointing to zone_t (zone_struct) data structures:

/*
 *
 * The zone_table array is used to look up the address of the 
 * struct zone corresponding to a given zone number (ZONE_DMA,
 * ZONE_NORMAL, or ZONE_HIGHMEM).
 */
zone_t *zone_table[MAX_NR_ZONES*MAX_NR_NODES];

and I found its address from System.map

but as I guess this address 0xc04260c4 is address of zone_table[0].

but I need address of zone_table[1]

I don't know how to calculate this address. I thought in a 32 bit x86 system maybe 0xc04260c4 should be added to 0x4 to access address of zone_table[1]. Is it right?

Was it helpful?

Solution

If you have an array zone_t * zone_table[] then zone_table[x] is shorthand for *(zone_table+x)

BUT + in this case is pointer addition, so its zone_table + sizeof(zone_t *) * x

for 32 bit systems sizeof(zone_t *) is indeed 4

for 64 bit systems sizeof(zone_t *) is 8

Your assumption was correct:

if the address of zone_table[0] is 0xc04260c4

then the address of zone_table[1] is 0xc04260c8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top