Changeset View
Changeset View
Standalone View
Standalone View
lib/libkvm/kvm_pcpu.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#include <sys/pcpu.h> | #include <sys/pcpu.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <kvm.h> | #include <kvm.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "kvm_private.h" | #include "kvm_private.h" | ||||
static struct nlist kvm_pcpu_nl[] = { | static struct kvm_nlist kvm_pcpu_nl[] = { | ||||
{ .n_name = "_cpuid_to_pcpu" }, | { .n_name = "_cpuid_to_pcpu" }, | ||||
{ .n_name = "_mp_maxcpus" }, | { .n_name = "_mp_maxcpus" }, | ||||
{ .n_name = "_mp_ncpus" }, | { .n_name = "_mp_ncpus" }, | ||||
{ .n_name = NULL }, | { .n_name = NULL }, | ||||
}; | }; | ||||
#define NL_CPUID_TO_PCPU 0 | #define NL_CPUID_TO_PCPU 0 | ||||
#define NL_MP_MAXCPUS 1 | #define NL_MP_MAXCPUS 1 | ||||
#define NL_MP_NCPUS 2 | #define NL_MP_NCPUS 2 | ||||
Show All 12 Lines | |||||
static int | static int | ||||
_kvm_pcpu_init(kvm_t *kd) | _kvm_pcpu_init(kvm_t *kd) | ||||
{ | { | ||||
size_t len; | size_t len; | ||||
int max; | int max; | ||||
void *data; | void *data; | ||||
if (kvm_nlist(kd, kvm_pcpu_nl) < 0) | if (kvm_nlist2(kd, kvm_pcpu_nl) < 0) | ||||
return (-1); | return (-1); | ||||
if (kvm_pcpu_nl[NL_CPUID_TO_PCPU].n_value == 0) { | if (kvm_pcpu_nl[NL_CPUID_TO_PCPU].n_value == 0) { | ||||
_kvm_err(kd, kd->program, "unable to find cpuid_to_pcpu"); | _kvm_err(kd, kd->program, "unable to find cpuid_to_pcpu"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (kvm_pcpu_nl[NL_MP_MAXCPUS].n_value == 0) { | if (kvm_pcpu_nl[NL_MP_MAXCPUS].n_value == 0) { | ||||
_kvm_err(kd, kd->program, "unable to find mp_maxcpus"); | _kvm_err(kd, kd->program, "unable to find mp_maxcpus"); | ||||
return (-1); | return (-1); | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Set up libkvm to handle dynamic per-CPU memory. | * Set up libkvm to handle dynamic per-CPU memory. | ||||
*/ | */ | ||||
static int | static int | ||||
_kvm_dpcpu_init(kvm_t *kd) | _kvm_dpcpu_init(kvm_t *kd) | ||||
{ | { | ||||
struct nlist nl[] = { | struct kvm_nlist nl[] = { | ||||
#define NLIST_START_SET_PCPU 0 | #define NLIST_START_SET_PCPU 0 | ||||
{ .n_name = "___start_" DPCPU_SETNAME }, | { .n_name = "___start_" DPCPU_SETNAME }, | ||||
#define NLIST_STOP_SET_PCPU 1 | #define NLIST_STOP_SET_PCPU 1 | ||||
{ .n_name = "___stop_" DPCPU_SETNAME }, | { .n_name = "___stop_" DPCPU_SETNAME }, | ||||
#define NLIST_DPCPU_OFF 2 | #define NLIST_DPCPU_OFF 2 | ||||
{ .n_name = "_dpcpu_off" }, | { .n_name = "_dpcpu_off" }, | ||||
#define NLIST_MP_MAXCPUS 3 | #define NLIST_MP_MAXCPUS 3 | ||||
{ .n_name = "_mp_maxcpus" }, | { .n_name = "_mp_maxcpus" }, | ||||
{ .n_name = NULL }, | { .n_name = NULL }, | ||||
}; | }; | ||||
uintptr_t *dpcpu_off_buf; | uintptr_t *dpcpu_off_buf; | ||||
size_t len; | size_t len; | ||||
u_int dpcpu_maxcpus; | u_int dpcpu_maxcpus; | ||||
/* | /* | ||||
* XXX: This only works for native kernels for now. | |||||
*/ | |||||
if (!kvm_native(kd)) | |||||
return (-1); | |||||
/* | |||||
* Locate and cache locations of important symbols using the internal | * Locate and cache locations of important symbols using the internal | ||||
* version of _kvm_nlist, turning off initialization to avoid | * version of _kvm_nlist, turning off initialization to avoid | ||||
* recursion in case of unresolveable symbols. | * recursion in case of unresolveable symbols. | ||||
*/ | */ | ||||
if (_kvm_nlist(kd, nl, 0) != 0) | if (_kvm_nlist(kd, nl, 0) != 0) | ||||
return (-1); | return (-1); | ||||
if (kvm_read(kd, nl[NLIST_MP_MAXCPUS].n_value, &dpcpu_maxcpus, | if (kvm_read(kd, nl[NLIST_MP_MAXCPUS].n_value, &dpcpu_maxcpus, | ||||
sizeof(dpcpu_maxcpus)) != sizeof(dpcpu_maxcpus)) | sizeof(dpcpu_maxcpus)) != sizeof(dpcpu_maxcpus)) | ||||
Show All 31 Lines | _kvm_dpcpu_initialized(kvm_t *kd, int intialize) | ||||
return (kd->dpcpu_initialized); | return (kd->dpcpu_initialized); | ||||
} | } | ||||
/* | /* | ||||
* Check whether the value is within the dpcpu symbol range and only if so | * Check whether the value is within the dpcpu symbol range and only if so | ||||
* adjust the offset relative to the current offset. | * adjust the offset relative to the current offset. | ||||
*/ | */ | ||||
uintptr_t | kvaddr_t | ||||
_kvm_dpcpu_validaddr(kvm_t *kd, uintptr_t value) | _kvm_dpcpu_validaddr(kvm_t *kd, kvaddr_t value) | ||||
{ | { | ||||
if (value == 0) | if (value == 0) | ||||
return (value); | return (value); | ||||
if (!kd->dpcpu_initialized) | if (!kd->dpcpu_initialized) | ||||
return (value); | return (value); | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |