]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/kern/kern_environment.c
Permit the kernel environment to set an array of numeric values for a single
[FreeBSD/FreeBSD.git] / sys / kern / kern_environment.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 1998 Michael Smith
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 /*
30  * The unified bootloader passes us a pointer to a preserved copy of
31  * bootstrap/kernel environment variables.  We convert them to a
32  * dynamic array of strings later when the VM subsystem is up.
33  *
34  * We make these available through the kenv(2) syscall for userland
35  * and through kern_getenv()/freeenv() kern_setenv() kern_unsetenv() testenv() for
36  * the kernel.
37  */
38
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/proc.h>
45 #include <sys/queue.h>
46 #include <sys/lock.h>
47 #include <sys/malloc.h>
48 #include <sys/mutex.h>
49 #include <sys/priv.h>
50 #include <sys/kernel.h>
51 #include <sys/systm.h>
52 #include <sys/sysent.h>
53 #include <sys/sysproto.h>
54 #include <sys/libkern.h>
55 #include <sys/kenv.h>
56 #include <sys/limits.h>
57
58 #include <security/mac/mac_framework.h>
59
60 static MALLOC_DEFINE(M_KENV, "kenv", "kernel environment");
61
62 #define KENV_SIZE       512     /* Maximum number of environment strings */
63
64 /* pointer to the static environment */
65 char            *kern_envp;
66 static int      env_len;
67 static int      env_pos;
68 static char     *kernenv_next(char *);
69
70 /* dynamic environment variables */
71 char            **kenvp;
72 struct mtx      kenv_lock;
73
74 /*
75  * No need to protect this with a mutex since SYSINITS are single threaded.
76  */
77 int     dynamic_kenv = 0;
78
79 #define KENV_CHECK      if (!dynamic_kenv) \
80                             panic("%s: called before SI_SUB_KMEM", __func__)
81
82 int
83 sys_kenv(td, uap)
84         struct thread *td;
85         struct kenv_args /* {
86                 int what;
87                 const char *name;
88                 char *value;
89                 int len;
90         } */ *uap;
91 {
92         char *name, *value, *buffer = NULL;
93         size_t len, done, needed, buflen;
94         int error, i;
95
96         KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = 0"));
97
98         error = 0;
99         if (uap->what == KENV_DUMP) {
100 #ifdef MAC
101                 error = mac_kenv_check_dump(td->td_ucred);
102                 if (error)
103                         return (error);
104 #endif
105                 done = needed = 0;
106                 buflen = uap->len;
107                 if (buflen > KENV_SIZE * (KENV_MNAMELEN + KENV_MVALLEN + 2))
108                         buflen = KENV_SIZE * (KENV_MNAMELEN +
109                             KENV_MVALLEN + 2);
110                 if (uap->len > 0 && uap->value != NULL)
111                         buffer = malloc(buflen, M_TEMP, M_WAITOK|M_ZERO);
112                 mtx_lock(&kenv_lock);
113                 for (i = 0; kenvp[i] != NULL; i++) {
114                         len = strlen(kenvp[i]) + 1;
115                         needed += len;
116                         len = min(len, buflen - done);
117                         /*
118                          * If called with a NULL or insufficiently large
119                          * buffer, just keep computing the required size.
120                          */
121                         if (uap->value != NULL && buffer != NULL && len > 0) {
122                                 bcopy(kenvp[i], buffer + done, len);
123                                 done += len;
124                         }
125                 }
126                 mtx_unlock(&kenv_lock);
127                 if (buffer != NULL) {
128                         error = copyout(buffer, uap->value, done);
129                         free(buffer, M_TEMP);
130                 }
131                 td->td_retval[0] = ((done == needed) ? 0 : needed);
132                 return (error);
133         }
134
135         switch (uap->what) {
136         case KENV_SET:
137                 error = priv_check(td, PRIV_KENV_SET);
138                 if (error)
139                         return (error);
140                 break;
141
142         case KENV_UNSET:
143                 error = priv_check(td, PRIV_KENV_UNSET);
144                 if (error)
145                         return (error);
146                 break;
147         }
148
149         name = malloc(KENV_MNAMELEN + 1, M_TEMP, M_WAITOK);
150
151         error = copyinstr(uap->name, name, KENV_MNAMELEN + 1, NULL);
152         if (error)
153                 goto done;
154
155         switch (uap->what) {
156         case KENV_GET:
157 #ifdef MAC
158                 error = mac_kenv_check_get(td->td_ucred, name);
159                 if (error)
160                         goto done;
161 #endif
162                 value = kern_getenv(name);
163                 if (value == NULL) {
164                         error = ENOENT;
165                         goto done;
166                 }
167                 len = strlen(value) + 1;
168                 if (len > uap->len)
169                         len = uap->len;
170                 error = copyout(value, uap->value, len);
171                 freeenv(value);
172                 if (error)
173                         goto done;
174                 td->td_retval[0] = len;
175                 break;
176         case KENV_SET:
177                 len = uap->len;
178                 if (len < 1) {
179                         error = EINVAL;
180                         goto done;
181                 }
182                 if (len > KENV_MVALLEN + 1)
183                         len = KENV_MVALLEN + 1;
184                 value = malloc(len, M_TEMP, M_WAITOK);
185                 error = copyinstr(uap->value, value, len, NULL);
186                 if (error) {
187                         free(value, M_TEMP);
188                         goto done;
189                 }
190 #ifdef MAC
191                 error = mac_kenv_check_set(td->td_ucred, name, value);
192                 if (error == 0)
193 #endif
194                         kern_setenv(name, value);
195                 free(value, M_TEMP);
196                 break;
197         case KENV_UNSET:
198 #ifdef MAC
199                 error = mac_kenv_check_unset(td->td_ucred, name);
200                 if (error)
201                         goto done;
202 #endif
203                 error = kern_unsetenv(name);
204                 if (error)
205                         error = ENOENT;
206                 break;
207         default:
208                 error = EINVAL;
209                 break;
210         }
211 done:
212         free(name, M_TEMP);
213         return (error);
214 }
215
216 /*
217  * Populate the initial kernel environment.
218  *
219  * This is called very early in MD startup, either to provide a copy of the
220  * environment obtained from a boot loader, or to provide an empty buffer into
221  * which MD code can store an initial environment using kern_setenv() calls.
222  *
223  * When a copy of an initial environment is passed in, we start by scanning that
224  * env for overrides to the compiled-in envmode and hintmode variables.
225  *
226  * If the global envmode is 1, the environment is initialized from the global
227  * static_env[], regardless of the arguments passed.  This implements the env
228  * keyword described in config(5).  In this case env_pos is set to env_len,
229  * causing kern_setenv() to return -1 (if len > 0) or panic (if len == 0) until
230  * the dynamic environment is available.  The envmode and static_env variables
231  * are defined in env.c which is generated by config(8).
232  *
233  * If len is non-zero, the caller is providing an empty buffer.  The caller will
234  * subsequently use kern_setenv() to add up to len bytes of initial environment
235  * before the dynamic environment is available.
236  *
237  * If len is zero, the caller is providing a pre-loaded buffer containing
238  * environment strings.  Additional strings cannot be added until the dynamic
239  * environment is available.  The memory pointed to must remain stable at least
240  * until sysinit runs init_dynamic_kenv().  If no initial environment is
241  * available from the boot loader, passing a NULL pointer allows the static_env
242  * to be installed if it is configured.
243  */
244 void
245 init_static_kenv(char *buf, size_t len)
246 {
247         char *cp;
248         
249         for (cp = buf; cp != NULL && cp[0] != '\0'; cp += strlen(cp) + 1) {
250                 if (strcmp(cp, "static_env.disabled=1") == 0)
251                         envmode = 0;
252                 if (strcmp(cp, "static_hints.disabled=1") == 0)
253                         hintmode = 0;
254         }
255
256         if (envmode == 1) {
257                 kern_envp = static_env;
258                 env_len = len;
259                 env_pos = len;
260         } else {
261                 kern_envp = buf;
262                 env_len = len;
263                 env_pos = 0;
264         }
265 }
266
267 /*
268  * Setup the dynamic kernel environment.
269  */
270 static void
271 init_dynamic_kenv(void *data __unused)
272 {
273         char *cp, *cpnext;
274         size_t len;
275         int i;
276
277         kenvp = malloc((KENV_SIZE + 1) * sizeof(char *), M_KENV,
278                 M_WAITOK | M_ZERO);
279         i = 0;
280         if (kern_envp && *kern_envp != '\0') {
281                 for (cp = kern_envp; cp != NULL; cp = cpnext) {
282                         cpnext = kernenv_next(cp);
283                         len = strlen(cp) + 1;
284                         if (len > KENV_MNAMELEN + 1 + KENV_MVALLEN + 1) {
285                                 printf(
286                                 "WARNING: too long kenv string, ignoring %s\n",
287                                     cp);
288                                 continue;
289                         }
290                         if (i < KENV_SIZE) {
291                                 kenvp[i] = malloc(len, M_KENV, M_WAITOK);
292                                 strcpy(kenvp[i++], cp);
293                                 explicit_bzero(cp, strlen(cp));
294                         } else
295                                 printf(
296                                 "WARNING: too many kenv strings, ignoring %s\n",
297                                     cp);
298                 }
299         }
300         kenvp[i] = NULL;
301
302         mtx_init(&kenv_lock, "kernel environment", NULL, MTX_DEF);
303         dynamic_kenv = 1;
304 }
305 SYSINIT(kenv, SI_SUB_KMEM, SI_ORDER_ANY, init_dynamic_kenv, NULL);
306
307 void
308 freeenv(char *env)
309 {
310
311         if (dynamic_kenv && env != NULL) {
312                 explicit_bzero(env, strlen(env));
313                 free(env, M_KENV);
314         }
315 }
316
317 /*
318  * Internal functions for string lookup.
319  */
320 static char *
321 _getenv_dynamic(const char *name, int *idx)
322 {
323         char *cp;
324         int len, i;
325
326         mtx_assert(&kenv_lock, MA_OWNED);
327         len = strlen(name);
328         for (cp = kenvp[0], i = 0; cp != NULL; cp = kenvp[++i]) {
329                 if ((strncmp(cp, name, len) == 0) &&
330                     (cp[len] == '=')) {
331                         if (idx != NULL)
332                                 *idx = i;
333                         return (cp + len + 1);
334                 }
335         }
336         return (NULL);
337 }
338
339 static char *
340 _getenv_static(const char *name)
341 {
342         char *cp, *ep;
343         int len;
344
345         for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) {
346                 for (ep = cp; (*ep != '=') && (*ep != 0); ep++)
347                         ;
348                 if (*ep != '=')
349                         continue;
350                 len = ep - cp;
351                 ep++;
352                 if (!strncmp(name, cp, len) && name[len] == 0)
353                         return (ep);
354         }
355         return (NULL);
356 }
357
358 /*
359  * Look up an environment variable by name.
360  * Return a pointer to the string if found.
361  * The pointer has to be freed with freeenv()
362  * after use.
363  */
364 char *
365 kern_getenv(const char *name)
366 {
367         char buf[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
368         char *ret;
369
370         if (dynamic_kenv) {
371                 if (getenv_string(name, buf, sizeof(buf))) {
372                         ret = strdup(buf, M_KENV);
373                 } else {
374                         ret = NULL;
375                         WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
376                             "getenv");
377                 }
378         } else
379                 ret = _getenv_static(name);
380         return (ret);
381 }
382
383 /*
384  * Test if an environment variable is defined.
385  */
386 int
387 testenv(const char *name)
388 {
389         char *cp;
390
391         if (dynamic_kenv) {
392                 mtx_lock(&kenv_lock);
393                 cp = _getenv_dynamic(name, NULL);
394                 mtx_unlock(&kenv_lock);
395         } else
396                 cp = _getenv_static(name);
397         if (cp != NULL)
398                 return (1);
399         return (0);
400 }
401
402 static int
403 setenv_static(const char *name, const char *value)
404 {
405         int len;
406
407         if (env_pos >= env_len)
408                 return (-1);
409
410         /* Check space for x=y and two nuls */
411         len = strlen(name) + strlen(value);
412         if (len + 3 < env_len - env_pos) {
413                 len = sprintf(&kern_envp[env_pos], "%s=%s", name, value);
414                 env_pos += len+1;
415                 kern_envp[env_pos] = '\0';
416                 return (0);
417         } else
418                 return (-1);
419
420 }
421
422 /*
423  * Set an environment variable by name.
424  */
425 int
426 kern_setenv(const char *name, const char *value)
427 {
428         char *buf, *cp, *oldenv;
429         int namelen, vallen, i;
430
431         if (dynamic_kenv == 0 && env_len > 0)
432                 return (setenv_static(name, value));
433
434         KENV_CHECK;
435
436         namelen = strlen(name) + 1;
437         if (namelen > KENV_MNAMELEN + 1)
438                 return (-1);
439         vallen = strlen(value) + 1;
440         if (vallen > KENV_MVALLEN + 1)
441                 return (-1);
442         buf = malloc(namelen + vallen, M_KENV, M_WAITOK);
443         sprintf(buf, "%s=%s", name, value);
444
445         mtx_lock(&kenv_lock);
446         cp = _getenv_dynamic(name, &i);
447         if (cp != NULL) {
448                 oldenv = kenvp[i];
449                 kenvp[i] = buf;
450                 mtx_unlock(&kenv_lock);
451                 free(oldenv, M_KENV);
452         } else {
453                 /* We add the option if it wasn't found */
454                 for (i = 0; (cp = kenvp[i]) != NULL; i++)
455                         ;
456
457                 /* Bounds checking */
458                 if (i < 0 || i >= KENV_SIZE) {
459                         free(buf, M_KENV);
460                         mtx_unlock(&kenv_lock);
461                         return (-1);
462                 }
463
464                 kenvp[i] = buf;
465                 kenvp[i + 1] = NULL;
466                 mtx_unlock(&kenv_lock);
467         }
468         return (0);
469 }
470
471 /*
472  * Unset an environment variable string.
473  */
474 int
475 kern_unsetenv(const char *name)
476 {
477         char *cp, *oldenv;
478         int i, j;
479
480         KENV_CHECK;
481
482         mtx_lock(&kenv_lock);
483         cp = _getenv_dynamic(name, &i);
484         if (cp != NULL) {
485                 oldenv = kenvp[i];
486                 for (j = i + 1; kenvp[j] != NULL; j++)
487                         kenvp[i++] = kenvp[j];
488                 kenvp[i] = NULL;
489                 mtx_unlock(&kenv_lock);
490                 explicit_bzero(oldenv, strlen(oldenv));
491                 free(oldenv, M_KENV);
492                 return (0);
493         }
494         mtx_unlock(&kenv_lock);
495         return (-1);
496 }
497
498 /*
499  * Return a string value from an environment variable.
500  */
501 int
502 getenv_string(const char *name, char *data, int size)
503 {
504         char *cp;
505
506         if (dynamic_kenv) {
507                 mtx_lock(&kenv_lock);
508                 cp = _getenv_dynamic(name, NULL);
509                 if (cp != NULL)
510                         strlcpy(data, cp, size);
511                 mtx_unlock(&kenv_lock);
512         } else {
513                 cp = _getenv_static(name);
514                 if (cp != NULL)
515                         strlcpy(data, cp, size);
516         }
517         return (cp != NULL);
518 }
519
520 /*
521  * Return an array of integers at the given type size and signedness.
522  */
523 int
524 getenv_array(const char *name, void *pdata, int size, int *psize,
525     int type_size, bool allow_signed)
526 {
527         char buf[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
528         uint8_t shift;
529         int64_t value;
530         int64_t old;
531         char *end;
532         char *ptr;
533         int n;
534
535         if (getenv_string(name, buf, sizeof(buf)) == 0)
536                 return (0);
537
538         /* get maximum number of elements */
539         size /= type_size;
540
541         n = 0;
542
543         for (ptr = buf; *ptr != 0; ) {
544
545                 value = strtoq(ptr, &end, 0);
546
547                 /* check if signed numbers are allowed */
548                 if (value < 0 && !allow_signed)
549                         goto error;
550
551                 /* check for invalid value */
552                 if (ptr == end)
553                         goto error;
554                 
555                 /* check for valid suffix */
556                 switch (*end) {
557                 case 't':
558                 case 'T':
559                         shift = 40;
560                         end++;
561                         break;
562                 case 'g':
563                 case 'G':
564                         shift = 30;
565                         end++;
566                         break;
567                 case 'm':
568                 case 'M':
569                         shift = 20;
570                         end++;
571                         break;
572                 case 'k':
573                 case 'K':
574                         shift = 10;
575                         end++;
576                         break;
577                 case ' ':
578                 case '\t':
579                 case ',':
580                 case 0:
581                         shift = 0;
582                         break;
583                 default:
584                         /* garbage after numeric value */
585                         goto error;
586                 }
587
588                 /* skip till next value, if any */
589                 while (*end == '\t' || *end == ',' || *end == ' ')
590                         end++;
591
592                 /* update pointer */
593                 ptr = end;
594
595                 /* apply shift */
596                 old = value;
597                 value <<= shift;
598
599                 /* overflow check */
600                 if ((value >> shift) != old)
601                         goto error;
602
603                 /* check for buffer overflow */
604                 if (n >= size)
605                         goto error;
606
607                 /* store value according to type size */
608                 switch (type_size) {
609                 case 1:
610                         if (allow_signed) {
611                                 if (value < SCHAR_MIN || value > SCHAR_MAX)
612                                         goto error;
613                         } else {
614                                 if (value < 0 || value > UCHAR_MAX)
615                                         goto error;
616                         }
617                         ((uint8_t *)pdata)[n] = (uint8_t)value;
618                         break;
619                 case 2:
620                         if (allow_signed) {
621                                 if (value < SHRT_MIN || value > SHRT_MAX)
622                                         goto error;
623                         } else {
624                                 if (value < 0 || value > USHRT_MAX)
625                                         goto error;
626                         }
627                         ((uint16_t *)pdata)[n] = (uint16_t)value;
628                         break;
629                 case 4:
630                         if (allow_signed) {
631                                 if (value < INT_MIN || value > INT_MAX)
632                                         goto error;
633                         } else {
634                                 if (value > UINT_MAX)
635                                         goto error;
636                         }
637                         ((uint32_t *)pdata)[n] = (uint32_t)value;
638                         break;
639                 case 8:
640                         ((uint64_t *)pdata)[n] = (uint64_t)value;
641                         break;
642                 default:
643                         goto error;
644                 }
645                 n++;
646         }
647         *psize = n * type_size;
648
649         if (n != 0)
650                 return (1);     /* success */
651 error:
652         return (0);     /* failure */
653 }
654
655 /*
656  * Return an integer value from an environment variable.
657  */
658 int
659 getenv_int(const char *name, int *data)
660 {
661         quad_t tmp;
662         int rval;
663
664         rval = getenv_quad(name, &tmp);
665         if (rval)
666                 *data = (int) tmp;
667         return (rval);
668 }
669
670 /*
671  * Return an unsigned integer value from an environment variable.
672  */
673 int
674 getenv_uint(const char *name, unsigned int *data)
675 {
676         quad_t tmp;
677         int rval;
678
679         rval = getenv_quad(name, &tmp);
680         if (rval)
681                 *data = (unsigned int) tmp;
682         return (rval);
683 }
684
685 /*
686  * Return an int64_t value from an environment variable.
687  */
688 int
689 getenv_int64(const char *name, int64_t *data)
690 {
691         quad_t tmp;
692         int64_t rval;
693
694         rval = getenv_quad(name, &tmp);
695         if (rval)
696                 *data = (int64_t) tmp;
697         return (rval);
698 }
699
700 /*
701  * Return an uint64_t value from an environment variable.
702  */
703 int
704 getenv_uint64(const char *name, uint64_t *data)
705 {
706         quad_t tmp;
707         uint64_t rval;
708
709         rval = getenv_quad(name, &tmp);
710         if (rval)
711                 *data = (uint64_t) tmp;
712         return (rval);
713 }
714
715 /*
716  * Return a long value from an environment variable.
717  */
718 int
719 getenv_long(const char *name, long *data)
720 {
721         quad_t tmp;
722         int rval;
723
724         rval = getenv_quad(name, &tmp);
725         if (rval)
726                 *data = (long) tmp;
727         return (rval);
728 }
729
730 /*
731  * Return an unsigned long value from an environment variable.
732  */
733 int
734 getenv_ulong(const char *name, unsigned long *data)
735 {
736         quad_t tmp;
737         int rval;
738
739         rval = getenv_quad(name, &tmp);
740         if (rval)
741                 *data = (unsigned long) tmp;
742         return (rval);
743 }
744
745 /*
746  * Return a quad_t value from an environment variable.
747  */
748 int
749 getenv_quad(const char *name, quad_t *data)
750 {
751         char    value[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
752         char    *vtp;
753         quad_t  iv;
754
755         if (!getenv_string(name, value, sizeof(value)))
756                 return (0);
757         iv = strtoq(value, &vtp, 0);
758         if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0'))
759                 return (0);
760         switch (vtp[0]) {
761         case 't': case 'T':
762                 iv *= 1024;
763         case 'g': case 'G':
764                 iv *= 1024;
765         case 'm': case 'M':
766                 iv *= 1024;
767         case 'k': case 'K':
768                 iv *= 1024;
769         case '\0':
770                 break;
771         default:
772                 return (0);
773         }
774         *data = iv;
775         return (1);
776 }
777
778 /*
779  * Find the next entry after the one which (cp) falls within, return a
780  * pointer to its start or NULL if there are no more.
781  */
782 static char *
783 kernenv_next(char *cp)
784 {
785
786         if (cp != NULL) {
787                 while (*cp != 0)
788                         cp++;
789                 cp++;
790                 if (*cp == 0)
791                         cp = NULL;
792         }
793         return (cp);
794 }
795
796 void
797 tunable_int_init(void *data)
798 {
799         struct tunable_int *d = (struct tunable_int *)data;
800
801         TUNABLE_INT_FETCH(d->path, d->var);
802 }
803
804 void
805 tunable_long_init(void *data)
806 {
807         struct tunable_long *d = (struct tunable_long *)data;
808
809         TUNABLE_LONG_FETCH(d->path, d->var);
810 }
811
812 void
813 tunable_ulong_init(void *data)
814 {
815         struct tunable_ulong *d = (struct tunable_ulong *)data;
816
817         TUNABLE_ULONG_FETCH(d->path, d->var);
818 }
819
820 void
821 tunable_int64_init(void *data)
822 {
823         struct tunable_int64 *d = (struct tunable_int64 *)data;
824
825         TUNABLE_INT64_FETCH(d->path, d->var);
826 }
827
828 void
829 tunable_uint64_init(void *data)
830 {
831         struct tunable_uint64 *d = (struct tunable_uint64 *)data;
832
833         TUNABLE_UINT64_FETCH(d->path, d->var);
834 }
835
836 void
837 tunable_quad_init(void *data)
838 {
839         struct tunable_quad *d = (struct tunable_quad *)data;
840
841         TUNABLE_QUAD_FETCH(d->path, d->var);
842 }
843
844 void
845 tunable_str_init(void *data)
846 {
847         struct tunable_str *d = (struct tunable_str *)data;
848
849         TUNABLE_STR_FETCH(d->path, d->var, d->size);
850 }