#define N_VALUE(index) ((caddr_t)kernelnames[index].n_value)
#define NLIST_IOSTAT 0
static struct nlist kernelnames[] = {
{"iostat", 0, 0, 0, 0, 0},
{NULL, 0, 0, 0, 0, 0}
};
//----function
body------------------------------------------------------------------------
knlist(kernelnames, 1, sizeof(struct nlist));
struct iostat _iostat;
if ((_kmem = open("/dev/kmem", O_RDONLY)) < 0) {
perror("kmem could not be accessed");
exit(1);
}
//geting iostat structure from kernel...
lseek(_kmem, (off_t) N_VALUE(NLIST_IOSTAT), SEEK_SET);
read(_kmem, &_iostat, sizeof(struct iostat));
int _disk_count = _iostat.dk_cnt; /*an unexpected value is
returned: 113022504 */
struct dkstat* dk = (struct dkstat *) malloc(sizeof(struct dkstat)));
//geting dkstat structure from kernel...
lseek(_kmem, (off_t) _iostat.dkstatp, SEEK_SET);
int n = read(_kmem, dk, sizeof(struct dkstat)); /*here it
is the crash*/
//--------end of function
body-----------------------------------------------------------------------------------------------
so when I run the program and it tries to get dkstat structure it
result that n is -1 and a segmentation fault(coredump) is arised.
when I check for the iostat kernel symbol
$kdb
(0)> nm iostat
Symbol Address : 02C24D00
TOC Address : 0146E190
(0)> d 02C24D00
02C24D00: F100 0800 06BC 9628 0000 0000 0000 0005
So 0xF100 0800 is an unreal dkstat address and 0x06BC 9628 (113022504)
is not the real dk_cnt value.
I think it is related to AIX v5.3 because with earlier versions it
worked fine.
I would appreciate a lot that someone help me out on this.
Thanks
Daniel