From owner-p4-projects@FreeBSD.ORG Wed May 24 21:37:57 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1F90916A4EB; Wed, 24 May 2006 21:37:56 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3FA2716A4CE for ; Wed, 24 May 2006 21:37:54 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id B4B6A43D46 for ; Wed, 24 May 2006 21:37:53 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k4OLb1g0072680 for ; Wed, 24 May 2006 21:37:01 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k4OLb1Lp072675 for perforce@freebsd.org; Wed, 24 May 2006 21:37:01 GMT (envelope-from jhb@freebsd.org) Date: Wed, 24 May 2006 21:37:01 GMT Message-Id: <200605242137.k4OLb1Lp072675@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 97767 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: Wed, 24 May 2006 21:38:10 -0000 http://perforce.freebsd.org/chv.cgi?CH=97767 Change 97767 by jhb@jhb_mutex on 2006/05/24 21:36:09 Use linker_file_foreach(). Affected files ... .. //depot/projects/smpng/sys/kern/kern_linker.c#56 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_linker.c#56 (text+ko) ==== @@ -1747,53 +1747,61 @@ #ifdef HWPMC_HOOKS +struct hwpmc_context { + int nobjects; + int nmappings; + struct pmckern_map_in *kobase; +}; + +static int +linker_hwpmc_list_object(linker_file_t lf, void *arg) +{ + struct hwpmc_context *hc; + + hc = arg; + + /* If we run out of mappings, fail. */ + if (hc->nobjects >= hc->nmappings) + return (1); + + /* Save the info for this linker file. */ + hc->kobase[hc->nobjects].pm_file = lf->filename; + hc->kobase[hc->nobjects].pm_address = (uintptr_t)lf->address; + hc->nobjects++; + return (0); +} + /* * Inform hwpmc about the set of kernel modules currently loaded. */ void * linker_hwpmc_list_objects(void) { - int nobjects, nmappings; - linker_file_t lf; - struct pmckern_map_in *ko, *kobase; + struct hwpmc_context hc; - nmappings = 15; /* a reasonable default */ + hc.nmappings = 15; /* a reasonable default */ retry: /* allocate nmappings+1 entries */ - MALLOC(kobase, struct pmckern_map_in *, - (nmappings + 1) * sizeof(struct pmckern_map_in), M_LINKER, + MALLOC(hc.kobase, struct pmckern_map_in *, + (hc.nmappings + 1) * sizeof(struct pmckern_map_in), M_LINKER, M_WAITOK | M_ZERO); - nobjects = 0; - mtx_lock(&kld_mtx); - TAILQ_FOREACH(lf, &linker_files, link) - nobjects++; - - KASSERT(nobjects > 0, ("linker_hpwmc_list_objects: no kernel " - "objects?")); - - if (nobjects > nmappings) { - nmappings = nobjects; - FREE(kobase, M_LINKER); - mtx_unlock(&kld_mtx); + hc.nobjects = 0; + if (linker_file_foreach(linker_hwpmc_list_object, &hc) != 0) { + hc.nmappings = hc.nobjects; + FREE(hc.kobase, M_LINKER); goto retry; } - ko = kobase; - TAILQ_FOREACH(lf, &linker_files, link) { - ko->pm_file = lf->filename; - ko->pm_address = (uintptr_t) lf->address; - ko++; - } + KASSERT(hc.nobjects > 0, ("linker_hpwmc_list_objects: no kernel " + "objects?")); /* The last entry of the malloced area comprises of all zeros. */ - KASSERT(ko->pm_file == NULL, + KASSERT(hc.kobase[hc.nobjects].pm_file == NULL, ("linker_hwpmc_list_objects: last object not NULL")); - mtx_unlock(&kld_mtx); - - return ((void *) kobase); + return ((void *)hc.kobase); } #endif