[PATCH] C++ compatibility for some kernel headers

Eric van Gyzen eric at vangyzen.net
Wed Sep 17 18:47:02 UTC 2014


While we're on the topic, I'd like to see the definition of struct
prf_ra moved outside the definition of struct in6_prflags in
netinet6/in6_var.h, in order to play nicely with C++ scoping.  I'll whip
up a patch, if anyone would like.

Eric

On 09/17/2014 13:37, Adrian Chadd wrote:
> Hi!
>
> This is of interest to me at ${WORK}.
>
> So please do file a PR (https://bugs.freebsd.org/submit/) and I'll
> make sure we fix -HEAD up to do this.
>
> Thanks!
>
> -a
>
>
> On 17 September 2014 04:13, Sebastian Huber
> <sebastian.huber at embedded-brains.de> wrote:
>> We ported the FreeBSD network stack to RTEMS.  Some users want to write
>> network interface drivers in C++.  It would be nice if we can make some
>> FreeBSD kernel headers C++ compatible.
>>
>> sys/buf_ring.h:
>>
>> Mabye it is better to fix the integer type of br_cons_head to be able to
>> use it in atomic_cmpset_int().
>>
>> sys/mbuf.h:
>>
>> Maybe it is better to fix the integer type of ext_cnt to be able to use
>> it for uma_find_refcnt().
>> ---
>>  sys/net/ifq.h      | 16 ++++++++--------
>>  sys/sys/buf_ring.h |  9 +++++----
>>  sys/sys/mbuf.h     | 17 +++++++++--------
>>  3 files changed, 22 insertions(+), 20 deletions(-)
>>
>> diff --git a/sys/net/ifq.h b/sys/net/ifq.h
>> index cf0c506..c970443 100644
>> --- a/sys/net/ifq.h
>> +++ b/sys/net/ifq.h
>> @@ -332,7 +332,7 @@ drbr_enqueue(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m)
>>  }
>>
>>  static __inline void
>> -drbr_putback(struct ifnet *ifp, struct buf_ring *br, struct mbuf *new)
>> +drbr_putback(struct ifnet *ifp, struct buf_ring *br, struct mbuf *new_mbuf)
>>  {
>>         /*
>>          * The top of the list needs to be swapped
>> @@ -344,11 +344,11 @@ drbr_putback(struct ifnet *ifp, struct buf_ring *br, struct mbuf *new)
>>                  * Peek in altq case dequeued it
>>                  * so put it back.
>>                  */
>> -               IFQ_DRV_PREPEND(&ifp->if_snd, new);
>> +               IFQ_DRV_PREPEND(&ifp->if_snd, new_mbuf);
>>                 return;
>>         }
>>  #endif
>> -       buf_ring_putback_sc(br, new);
>> +       buf_ring_putback_sc(br, new_mbuf);
>>  }
>>
>>  static __inline struct mbuf *
>> @@ -367,7 +367,7 @@ drbr_peek(struct ifnet *ifp, struct buf_ring *br)
>>                 return (m);
>>         }
>>  #endif
>> -       return(buf_ring_peek(br));
>> +       return ((struct mbuf *)buf_ring_peek(br));
>>  }
>>
>>  static __inline void
>> @@ -379,7 +379,7 @@ drbr_flush(struct ifnet *ifp, struct buf_ring *br)
>>         if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd))
>>                 IFQ_PURGE(&ifp->if_snd);
>>  #endif
>> -       while ((m = buf_ring_dequeue_sc(br)) != NULL)
>> +       while ((m = (struct mbuf *)buf_ring_dequeue_sc(br)) != NULL)
>>                 m_freem(m);
>>  }
>>
>> @@ -402,7 +402,7 @@ drbr_dequeue(struct ifnet *ifp, struct buf_ring *br)
>>                 return (m);
>>         }
>>  #endif
>> -       return (buf_ring_dequeue_sc(br));
>> +       return ((struct mbuf *)buf_ring_dequeue_sc(br));
>>  }
>>
>>  static __inline void
>> @@ -435,11 +435,11 @@ drbr_dequeue_cond(struct ifnet *ifp, struct buf_ring *br,
>>                 return (m);
>>         }
>>  #endif
>> -       m = buf_ring_peek(br);
>> +       m = (struct mbuf *)buf_ring_peek(br);
>>         if (m == NULL || func(m, arg) == 0)
>>                 return (NULL);
>>
>> -       return (buf_ring_dequeue_sc(br));
>> +       return ((struct mbuf *)buf_ring_dequeue_sc(br));
>>  }
>>
>>  static __inline int
>> diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h
>> index a46aa2d..934f1a7 100644
>> --- a/sys/sys/buf_ring.h
>> +++ b/sys/sys/buf_ring.h
>> @@ -86,7 +86,8 @@ buf_ring_enqueue(struct buf_ring *br, void *buf)
>>                         critical_exit();
>>                         return (ENOBUFS);
>>                 }
>> -       } while (!atomic_cmpset_int(&br->br_prod_head, prod_head, prod_next));
>> +       } while (!atomic_cmpset_int((volatile int *)&br->br_prod_head,
>> +           prod_head, prod_next));
>>  #ifdef DEBUG_BUFRING
>>         if (br->br_ring[prod_head] != NULL)
>>                 panic("dangling value in enqueue");
>> @@ -135,7 +136,7 @@ buf_ring_dequeue_mc(struct buf_ring *br)
>>                         return (NULL);
>>                 }
>>
>> -               success = atomic_cmpset_int(&br->br_cons_head, cons_head,
>> +               success = atomic_cmpset_int((volatile int *)&br->br_cons_head, cons_head,
>>                     cons_next);
>>         } while (success == 0);
>>
>> @@ -253,11 +254,11 @@ buf_ring_advance_sc(struct buf_ring *br)
>>   * the compare and an atomic.
>>   */
>>  static __inline void
>> -buf_ring_putback_sc(struct buf_ring *br, void *new)
>> +buf_ring_putback_sc(struct buf_ring *br, void *new_item)
>>  {
>>         KASSERT(br->br_cons_head != br->br_prod_tail,
>>                 ("Buf-Ring has none in putback")) ;
>> -       br->br_ring[br->br_cons_head] = new;
>> +       br->br_ring[br->br_cons_head] = new_item;
>>  }
>>
>>  /*
>> diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
>> index d3e6ce0..960636b 100644
>> --- a/sys/sys/mbuf.h
>> +++ b/sys/sys/mbuf.h
>> @@ -627,7 +627,7 @@ m_get(int how, short type)
>>
>>         args.flags = 0;
>>         args.type = type;
>> -       return (uma_zalloc_arg(zone_mbuf, &args, how));
>> +       return ((struct mbuf *)uma_zalloc_arg(zone_mbuf, &args, how));
>>  }
>>
>>  /*
>> @@ -641,7 +641,7 @@ m_getclr(int how, short type)
>>
>>         args.flags = 0;
>>         args.type = type;
>> -       m = uma_zalloc_arg(zone_mbuf, &args, how);
>> +       m = (struct mbuf *)uma_zalloc_arg(zone_mbuf, &args, how);
>>         if (m != NULL)
>>                 bzero(m->m_data, MLEN);
>>         return (m);
>> @@ -654,7 +654,7 @@ m_gethdr(int how, short type)
>>
>>         args.flags = M_PKTHDR;
>>         args.type = type;
>> -       return (uma_zalloc_arg(zone_mbuf, &args, how));
>> +       return ((struct mbuf *)uma_zalloc_arg(zone_mbuf, &args, how));
>>  }
>>
>>  static __inline struct mbuf *
>> @@ -664,7 +664,7 @@ m_getcl(int how, short type, int flags)
>>
>>         args.flags = flags;
>>         args.type = type;
>> -       return (uma_zalloc_arg(zone_pack, &args, how));
>> +       return ((struct mbuf *)uma_zalloc_arg(zone_pack, &args, how));
>>  }
>>
>>  static __inline void
>> @@ -703,7 +703,7 @@ m_cljget(struct mbuf *m, int how, int size)
>>                 m->m_ext.ext_buf = NULL;
>>
>>         zone = m_getzone(size);
>> -       return (uma_zalloc_arg(zone, m, how));
>> +       return ((struct mbuf *)uma_zalloc_arg(zone, m, how));
>>  }
>>
>>  static __inline void
>> @@ -736,12 +736,13 @@ m_cljset(struct mbuf *m, void *cl, int type)
>>                 break;
>>         }
>>
>> -       m->m_data = m->m_ext.ext_buf = cl;
>> -       m->m_ext.ext_free = m->m_ext.ext_arg1 = m->m_ext.ext_arg2 = NULL;
>> +       m->m_data = m->m_ext.ext_buf = (caddr_t)cl;
>> +       m->m_ext.ext_free = NULL;
>> +       m->m_ext.ext_arg1 = m->m_ext.ext_arg2 = NULL;
>>         m->m_ext.ext_size = size;
>>         m->m_ext.ext_type = type;
>>         m->m_ext.ext_flags = 0;
>> -       m->m_ext.ext_cnt = uma_find_refcnt(zone, cl);
>> +       m->m_ext.ext_cnt = (u_int *)uma_find_refcnt(zone, cl);
>>         m->m_flags |= M_EXT;
>>
>>  }
>> --
>> 1.8.4.5
>>
>> _______________________________________________
>> freebsd-hackers at freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
>> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>



More information about the freebsd-hackers mailing list