Date: Fri, 5 Dec 2008 13:55:44 GMT From: Marko Zec <zec@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 154110 for review Message-ID: <200812051355.mB5DtiBw080449@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=154110 Change 154110 by zec@zec_tca51 on 2008/12/05 13:55:17 Extend kldsym(9) lookups to resolve queries for virtualized variables, but only for those that have been explicitly exported via VNET_SYMMAP constructs. Affected files ... .. //depot/projects/vimage-commit2/src/sys/kern/kern_linker.c#4 edit .. //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#2 edit .. //depot/projects/vimage-commit2/src/sys/net/if.c#28 edit .. //depot/projects/vimage-commit2/src/sys/sys/vimage.h#24 edit Differences ... ==== //depot/projects/vimage-commit2/src/sys/kern/kern_linker.c#4 (text+ko) ==== @@ -51,6 +51,7 @@ #include <sys/vnode.h> #include <sys/syscallsubr.h> #include <sys/sysctl.h> +#include <sys/vimage.h> #include <security/mac/mac_framework.h> @@ -1278,8 +1279,24 @@ break; } } +#ifndef VIMAGE_GLOBALS + /* + * If the symbol is not found in global namespace, look up + * for it in the current vimage. + */ + if (lf == NULL) { + CURVNET_SET(TD_TO_VNET(td)); + error = vi_symlookup(&lookup, symstr); + CURVNET_RESTORE(); + if (error == 0) { + error = copyout(&lookup, uap->data, + sizeof(lookup)); + } + } +#else if (lf == NULL) error = ENOENT; +#endif } KLD_UNLOCK(); out: ==== //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#2 (text+ko) ==== @@ -28,3 +28,68 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD: $" +); + +#include <sys/param.h> +#include <sys/types.h> +#include <sys/kernel.h> +#include <sys/linker.h> +#include <sys/malloc.h> +#include <sys/systm.h> +#include <sys/vimage.h> + +#ifndef VIMAGE_GLOBALS + +MALLOC_DEFINE(M_VIMAGE, "vimage", "vimage resource container"); + +static TAILQ_HEAD(vnet_modlink_head, vnet_modlink) vnet_modlink_head; + +void +vnet_mod_register(const struct vnet_modinfo *vmi) +{ + struct vnet_modlink *vml, *vml_iter; + + /* Do not register the same module instance more than once */ + TAILQ_FOREACH(vml_iter, &vnet_modlink_head, vml_mod_le) + if (vml_iter->vml_modinfo == vmi) + break; + if (vml_iter != NULL) + panic("attempt to register an already registered vnet module"); + vml = malloc(sizeof(struct vnet_modlink), M_VIMAGE, M_NOWAIT); + + vml->vml_modinfo = vmi; +} + +/* + * vi_symlookup() attempts to resolve name to address queries for + * variables which have been moved from global namespace to virtualization + * container structures, but are still directly accessed from legacy + * userspace processes via kldsym(2) and kmem(4) interfaces. + */ +int +vi_symlookup(struct kld_sym_lookup *lookup, char *symstr) +{ + struct vnet_modlink *vml; + + TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le) { + struct vnet_symmap *mapentry; + + if (vml->vml_modinfo->vmi_symmap == NULL) + continue; + + for (mapentry = vml->vml_modinfo->vmi_symmap; + mapentry->name != NULL; mapentry++) { + if (strcmp(symstr, mapentry->name) == 0) { + lookup->symvalue = (u_long) mapentry->base; + lookup->symsize = mapentry->size; + return 0; + } + } + } + + return ENOENT; +} + +#endif /* !VIMAGE_GLOBALS */ ==== //depot/projects/vimage-commit2/src/sys/net/if.c#28 (text+ko) ==== @@ -159,6 +159,19 @@ static struct filterops netdev_filtops = { 1, NULL, filt_netdetach, filt_netdev }; +#ifndef VIMAGE_GLOBALS +static struct vnet_symmap vnet_net_symmap[] = { + VNET_SYMMAP(net, ifnet), + VNET_SYMMAP(net, rt_tables), + VNET_SYMMAP(net, rtstat), + VNET_SYMMAP(net, rttrash), + VNET_SYMMAP_END +}; + +VNET_MOD_DECLARE(NET, net, vnet_net_iattach, vnet_net_idetach, + NONE, vnet_net_symmap) +#endif + /* * System initialization */ @@ -359,6 +372,10 @@ { INIT_VNET_NET(curvnet); +#ifndef VIMAGE_GLOBALS + vnet_mod_register(&vnet_net_modinfo); +#endif + V_if_index = 0; V_ifindex_table = NULL; V_if_indexlim = 8; ==== //depot/projects/vimage-commit2/src/sys/sys/vimage.h#24 (text+ko) ==== @@ -33,12 +33,49 @@ #ifndef _SYS_VIMAGE_H_ #define _SYS_VIMAGE_H_ +#include <sys/queue.h> + +struct vnet_modinfo; +struct kld_sym_lookup; + +int vi_symlookup(struct kld_sym_lookup *, char *); +void vnet_mod_register(const struct vnet_modinfo *); + +struct vnet_symmap { + char *name; + void *base; + size_t size; +}; + +struct vnet_modinfo { + char *vmi_name; + struct vnet_symmap *vmi_symmap; +}; + +struct vnet_modlink { + TAILQ_ENTRY(vnet_modlink) vml_mod_le; + const struct vnet_modinfo *vml_modinfo; +}; + +#define VNET_MOD_DECLARE(m_name_uc, m_name_lc, m_iattach, m_idetach, \ + m_dependson, m_symmap) \ + static const struct vnet_modinfo vnet_##m_name_lc##_modinfo = { \ + .vmi_name = #m_name_lc, \ + .vmi_symmap = m_symmap \ +}; + #ifdef VIMAGE_GLOBALS #define VSYM(base, sym) (sym) #else #define VSYM(base, sym) (base ## _0._ ## sym) #endif +#define VNET_SYMMAP(mod, name) \ + { #name, &(vnet_ ## mod ## _0._ ## name), \ + sizeof(vnet_ ## mod ## _0._ ## name) } + +#define VNET_SYMMAP_END { NULL, 0 } + /* Non-VIMAGE null-macros */ #define CURVNET_SET(arg) #define CURVNET_SET_QUIET(arg)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812051355.mB5DtiBw080449>