The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/xdr/xdr_sizeof.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
    3  * unrestricted use provided that this legend is included on all tape
    4  * media and as a part of the software program in whole or part.  Users
    5  * may copy or modify Sun RPC without charge, but are not authorized
    6  * to license or distribute it to anyone else except as part of a product or
    7  * program developed by the user.
    8  * 
    9  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
   10  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
   11  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
   12  * 
   13  * Sun RPC is provided with no support and without any obligation on the
   14  * part of Sun Microsystems, Inc. to assist in its use, correction,
   15  * modification or enhancement.
   16  * 
   17  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
   18  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
   19  * OR ANY PART THEREOF.
   20  * 
   21  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
   22  * or profits or other special, indirect and consequential damages, even if
   23  * Sun has been advised of the possibility of such damages.
   24  * 
   25  * Sun Microsystems, Inc.
   26  * 2550 Garcia Avenue
   27  * Mountain View, California  94043
   28  */
   29 /*
   30  * xdr_sizeof.c
   31  *
   32  * Copyright 1990 Sun Microsystems, Inc.
   33  *
   34  * General purpose routine to see how much space something will use
   35  * when serialized using XDR.
   36  */
   37 
   38 #include <sys/cdefs.h>
   39 __FBSDID("$FreeBSD: stable/12/sys/xdr/xdr_sizeof.c 177633 2008-03-26 15:23:12Z dfr $");
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/malloc.h>
   44 
   45 #include <rpc/types.h>
   46 #include <rpc/xdr.h>
   47 
   48 /* ARGSUSED */
   49 static bool_t
   50 x_putlong(XDR *xdrs, const long *longp)
   51 {
   52 
   53         xdrs->x_handy += BYTES_PER_XDR_UNIT;
   54         return (TRUE);
   55 }
   56 
   57 /* ARGSUSED */
   58 static bool_t
   59 x_putbytes(XDR *xdrs, const char *bp, u_int len)
   60 {
   61 
   62         xdrs->x_handy += len;
   63         return (TRUE);
   64 }
   65 
   66 static u_int
   67 x_getpostn(XDR *xdrs)
   68 {
   69 
   70         return (xdrs->x_handy);
   71 }
   72 
   73 /* ARGSUSED */
   74 static bool_t
   75 x_setpostn(XDR *xdrs, u_int pos)
   76 {
   77 
   78         /* This is not allowed */
   79         return (FALSE);
   80 }
   81 
   82 static int32_t *
   83 x_inline(XDR *xdrs, u_int len)
   84 {
   85 
   86         if (len == 0) {
   87                 return (NULL);
   88         }
   89         if (xdrs->x_op != XDR_ENCODE) {
   90                 return (NULL);
   91         }
   92         if (len < (u_int)(uintptr_t)xdrs->x_base) {
   93                 /* x_private was already allocated */
   94                 xdrs->x_handy += len;
   95                 return ((int32_t *) xdrs->x_private);
   96         } else {
   97                 /* Free the earlier space and allocate new area */
   98                 if (xdrs->x_private)
   99                         free(xdrs->x_private, M_RPC);
  100                 if ((xdrs->x_private = (caddr_t) malloc(len, M_RPC, M_WAITOK)) == NULL) {
  101                         xdrs->x_base = 0;
  102                         return (NULL);
  103                 }
  104                 xdrs->x_base = (caddr_t)(uintptr_t) len;
  105                 xdrs->x_handy += len;
  106                 return ((int32_t *) xdrs->x_private);
  107         }
  108 }
  109 
  110 static int
  111 harmless(void)
  112 {
  113 
  114         /* Always return FALSE/NULL, as the case may be */
  115         return (0);
  116 }
  117 
  118 static void
  119 x_destroy(XDR *xdrs)
  120 {
  121 
  122         xdrs->x_handy = 0;
  123         xdrs->x_base = 0;
  124         if (xdrs->x_private) {
  125                 free(xdrs->x_private, M_RPC);
  126                 xdrs->x_private = NULL;
  127         }
  128         return;
  129 }
  130 
  131 unsigned long
  132 xdr_sizeof(xdrproc_t func, void *data)
  133 {
  134         XDR x;
  135         struct xdr_ops ops;
  136         bool_t stat;
  137         /* to stop ANSI-C compiler from complaining */
  138         typedef  bool_t (* dummyfunc1)(XDR *, long *);
  139         typedef  bool_t (* dummyfunc2)(XDR *, caddr_t, u_int);
  140 
  141         ops.x_putlong = x_putlong;
  142         ops.x_putbytes = x_putbytes;
  143         ops.x_inline = x_inline;
  144         ops.x_getpostn = x_getpostn;
  145         ops.x_setpostn = x_setpostn;
  146         ops.x_destroy = x_destroy;
  147 
  148         /* the other harmless ones */
  149         ops.x_getlong =  (dummyfunc1) harmless;
  150         ops.x_getbytes = (dummyfunc2) harmless;
  151 
  152         x.x_op = XDR_ENCODE;
  153         x.x_ops = &ops;
  154         x.x_handy = 0;
  155         x.x_private = (caddr_t) NULL;
  156         x.x_base = (caddr_t) 0;
  157 
  158         stat = func(&x, data);
  159         if (x.x_private)
  160                 free(x.x_private, M_RPC);
  161         return (stat == TRUE ? (unsigned) x.x_handy: 0);
  162 }

Cache object: 8ae7f92057aa5cd415aaa1074907aa85


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.