Print this page
3373 gcc >= 4.5 concerns about offsetof()
Portions contributed by: Igor Pashev <pashev.igor@gmail.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/xen/public/io/ring.h
          +++ new/usr/src/uts/common/xen/public/io/ring.h
↓ open down ↓ 39 lines elided ↑ open up ↑
  40   40  /* Round a 32-bit unsigned constant down to the nearest power of two. */
  41   41  #define __RD2(_x)  (((_x) & 0x00000002) ? 0x2                  : ((_x) & 0x1))
  42   42  #define __RD4(_x)  (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2    : __RD2(_x))
  43   43  #define __RD8(_x)  (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4    : __RD4(_x))
  44   44  #define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8    : __RD8(_x))
  45   45  #define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
  46   46  
  47   47  /*
  48   48   * Calculate size of a shared ring, given the total available space for the
  49   49   * ring and indexes (_sz), and the name tag of the request/response structure.
  50      - * A ring contains as many entries as will fit, rounded down to the nearest 
       50 + * A ring contains as many entries as will fit, rounded down to the nearest
  51   51   * power of two (so we can mask with (size-1) to loop around).
  52   52   */
       53 +#define __CONST_RING_SIZE(_s, _sz) \
       54 +    (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
       55 +       sizeof(((struct _s##_sring *)0)->ring[0])))
       56 +/*
       57 + * The same for passing in an actual pointer instead of a name tag.
       58 + */
  53   59  #define __RING_SIZE(_s, _sz) \
  54   60      (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
  55   61  
  56   62  /*
  57   63   * Macros to make the correct C datatypes for a new kind of ring.
  58   64   * 
  59   65   * To make a new ring datatype, you need to have two message structures,
  60   66   * let's say request_t, and response_t already defined.
  61   67   *
  62   68   * In a header where you want the ring datatype declared, you then do:
↓ open down ↓ 245 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX