diff options
| author | Ryan Moeller <freqlabs@FreeBSD.org> | 2020-08-04 12:04:47 +0000 |
|---|---|---|
| committer | Ryan Moeller <freqlabs@FreeBSD.org> | 2020-08-04 12:04:47 +0000 |
| commit | 83fbe66ef7255fa4d1223ea0bd82fc54e1e8122d (patch) | |
| tree | 417f9f035edf3a162c30dd2b1c4638edf81d67b7 /lib/libpmc | |
| parent | 338a24fd6c0adac829db078732dd88a02f35242f (diff) | |
Notes
Diffstat (limited to 'lib/libpmc')
| -rw-r--r-- | lib/libpmc/libpmc_pmu_util.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c index 11949a3ad3cd..d652573a883f 100644 --- a/lib/libpmc/libpmc_pmu_util.c +++ b/lib/libpmc/libpmc_pmu_util.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/errno.h> +#include <sys/pmc.h> #include <sys/sysctl.h> #include <stddef.h> #include <stdlib.h> @@ -89,20 +90,13 @@ static struct pmu_alias pmu_amd_alias_table[] = { static pmu_mfr_t pmu_events_mfr(void) { - char *buf; - size_t s; + char buf[PMC_CPUID_LEN]; + size_t s = sizeof(buf); pmu_mfr_t mfr; - if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s, - (void *)NULL, 0) == -1) - return (PMU_INVALID); - if ((buf = malloc(s + 1)) == NULL) - return (PMU_INVALID); if (sysctlbyname("kern.hwpmc.cpuid", buf, &s, - (void *)NULL, 0) == -1) { - free(buf); + (void *)NULL, 0) == -1) return (PMU_INVALID); - } if (strcasestr(buf, "AuthenticAMD") != NULL || strcasestr(buf, "HygonGenuine") != NULL) mfr = PMU_AMD; @@ -110,7 +104,6 @@ pmu_events_mfr(void) mfr = PMU_INTEL; else mfr = PMU_INVALID; - free(buf); return (mfr); } @@ -169,17 +162,14 @@ pmu_events_map_get(const char *cpuid) { regex_t re; regmatch_t pmatch[1]; - size_t s; - char buf[64]; + char buf[PMC_CPUID_LEN]; + size_t s = sizeof(buf); int match; const struct pmu_events_map *pme; if (cpuid != NULL) { - memcpy(buf, cpuid, 64); + strlcpy(buf, cpuid, s); } else { - if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s, - (void *)NULL, 0) == -1) - return (NULL); if (sysctlbyname("kern.hwpmc.cpuid", buf, &s, (void *)NULL, 0) == -1) return (NULL); |
