Date: Mon, 26 Jun 2006 05:49:41 GMT From: John Birrell <jb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 100027 for review Message-ID: <200606260549.k5Q5nfS7020736@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100027 Change 100027 by jb@jb_freebsd2 on 2006/06/26 05:48:50 Implement dof_get_property for FreeBSD. The DOF is in an ASCII hex string with two characters per byte. This was the easiest and most compact format for FreeBSD given that we don't have a device configuration file like Solaris does. Affected files ... .. //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_dof.c#7 edit Differences ... ==== //depot/projects/dtrace/src/sys/cddl/dev/dtrace/dtrace_dof.c#7 (text+ko) ==== @@ -120,15 +120,47 @@ return (dof); } +#if !defined(sun) +static __inline uchar_t dtrace_dof_char(char c) { + switch (c) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return (c - '0'); + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + return (c - 'A' + 10); + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return (c - 'a' + 10); + } +} +#endif + static dof_hdr_t * dtrace_dof_property(const char *name) { -#if defined(sun) uchar_t *buf; uint64_t loadsz; unsigned int len, i; dof_hdr_t *dof; +#if defined(sun) /* * Unfortunately, array of values in .conf files are always (and * only) interpreted to be integer arrays. We must read our DOF @@ -162,11 +194,50 @@ dof = kmem_alloc(loadsz, KM_SLEEP); bcopy(buf, dof, loadsz); ddi_prop_free(buf); +#else + char *p; + char *p_env; + + if ((p_env = getenv(name)) == NULL) + return (NULL); + len = strlen(p_env) / 2; + + buf = kmem_alloc(len, KM_SLEEP); + + dof = (dof_hdr_t *) buf; + + p = p_env; + + for (i = 0; i < len; i++) { + buf[i] = (dtrace_dof_char(p[0]) << 4) | + dtrace_dof_char(p[1]); + p += 2; + } + + freeenv(p_env); + + if (len < sizeof (dof_hdr_t)) { + free(buf, M_DTRACE); + dtrace_dof_error(NULL, "truncated header"); + return (NULL); + } + + if (len < (loadsz = dof->dofh_loadsz)) { + free(buf, M_DTRACE); + dtrace_dof_error(NULL, "truncated DOF"); + return (NULL); + } + + if (loadsz >= dtrace_dof_maxsize) { + free(buf, M_DTRACE); + dtrace_dof_error(NULL, "oversized DOF"); + return (NULL); + } + +#endif + return (dof); -#else - return (NULL); -#endif } static void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606260549.k5Q5nfS7020736>