PERFORCE change 140994 for review
Peter Wemm
peter at FreeBSD.org
Thu May 1 17:38:22 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=140994
Change 140994 by peter at peter_daintree on 2008/05/01 17:37:28
Update. Use the correct fields. Look for pcpu_size in the kernel
to adapt to any layout changes. (Let the consumer deal with variance
rather than guaranteeing that libkvm breaks first)
Affected files ...
.. //depot/projects/hammer/lib/libkvm/kvm_amd64.c#24 edit
Differences ...
==== //depot/projects/hammer/lib/libkvm/kvm_amd64.c#24 (text+ko) ====
@@ -76,7 +76,8 @@
size_t mmapsize;
pml4_entry_t *PML4;
int mp_maxcpus;
- struct pcpu *pcpu;
+ int pcpu_recsize;
+ char *pcpu;
};
/*
@@ -375,9 +376,23 @@
/* UP system; symbol doesn't exist */
vmst->mp_maxcpus = 1;
}
- vm->pcpu = _kvm_malloc(kd, sizeof(struct pcpu) * vm->mp_maxcpus);
+ /*
+ * The __pcpu array may have different inter-record padding or may
+ * grow additional fields. We have to adapt the best we can.
+ */
+ nlist[0].n_name = "pcpu_size";
+ nlist[1].n_name = 0;
+ if (kvm_nlist(kd, nlist) == 0) {
+ if (kvm_read(kd, nlist[0].n_value, &vm->pcpu_recsize,
+ sizeof(vm->pcpu_recsize)) != sizeof(vm->pcpu_recsize)) {
+ _kvm_err(kd, kd->program, "cannot read pcpu_size");
+ } else {
+ /* Older kernel's dont have it. Hope for the best. */
+ vmst->pcpu_recsize = sizeof(struct pcpu);
+ }
+ vm->pcpu = _kvm_malloc(kd, vm->pcpu_recsize * vm->mp_maxcpus);
- nlist[0].n_name = "pcpu";
+ nlist[0].n_name = "__pcpu";
nlist[1].n_name = 0;
if (kvm_nlist(kd, nlist) != 0) {
@@ -385,8 +400,8 @@
return (-1);
}
if (kvm_read(kd, nlist[0].n_value, vm->pcpu,
- sizeof(struct pcpu) * vm->mp_maxcpus) !=
- sizeof(struct pcpu) * vm->mp_maxcpus) {
+ vm->pcpu_recsize * vm->mp_maxcpus) !=
+ vm->pcpu_recsize * vm->mp_maxcpus) {
_kvm_err(kd, kd->program, "cannot read pcpu chunk");
return (-1);
}
@@ -407,8 +422,8 @@
return (NULL);
}
- if (cpu < 0 || cpu > vm->vm_maxcpus)
+ if (cpu < 0 || cpu > vm->vm_maxcpus)
_kvm_err(kd, kd->program, "
return (NULL); /* EDOOFUS actually */
- return (&vm->pcpu[cpu]);
+ return ((struct pcpu *)&vm->pcpu[cpu * vm->pcpu_recsize]);
}
More information about the p4-projects
mailing list