From owner-p4-projects@FreeBSD.ORG Thu May 1 17:38:22 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2B09D1065670; Thu, 1 May 2008 17:38:22 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E1575106566B for ; Thu, 1 May 2008 17:38:21 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CCD208FC0A for ; Thu, 1 May 2008 17:38:21 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m41HcLET038323 for ; Thu, 1 May 2008 17:38:21 GMT (envelope-from peter-gmail@wemm.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m41HcLq2038321 for perforce@freebsd.org; Thu, 1 May 2008 17:38:21 GMT (envelope-from peter-gmail@wemm.org) Date: Thu, 1 May 2008 17:38:21 GMT Message-Id: <200805011738.m41HcLq2038321@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter-gmail@wemm.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 140994 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 May 2008 17:38:22 -0000 http://perforce.freebsd.org/chv.cgi?CH=140994 Change 140994 by peter@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]); }