VirtualBox

Changeset 1039 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Feb 23, 2007 4:00:08 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
18914
Message:

Attempt to fix slirp build for 64 bit (also eliminated global variables)

Location:
trunk/src/VBox/Devices/Network
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r1033 r1039  
    288288    LogFlow(("drvNATDestruct:\n"));
    289289
    290 #if ARCH_BITS == 64
    291     LogRel(("NAT: g_cpvHashUsed=%RU32 g_cpvHashCollisions=%RU32 g_cpvHashInserts=%RU64 g_cpvHashDone=%RU64\n",
    292             g_cpvHashUsed, g_cpvHashCollisions, g_cpvHashInserts, g_cpvHashDone));
    293 #endif
    294290    int rc = RTCritSectEnter(&pData->CritSect);
    295291    AssertReleaseRC(rc);
     
    410406    pData->INetworkConnector.pfnNotifyLinkChanged  = drvNATNotifyLinkChanged;
    411407    pData->INetworkConnector.pfnNotifyCanReceive   = drvNATNotifyCanReceive;
    412    
     408
    413409    pData->pNATState                    = NULL;
    414410
  • trunk/src/VBox/Devices/Network/slirp/ip_input.c

    r1033 r1039  
    6363#endif /* !VBOX */
    6464{
    65         ipq.next = ipq.prev = ptr_to_u32(&ipq);
     65        ipq.next = ipq.prev = ptr_to_u32(pData, &ipq);
    6666#ifdef VBOX
    6767        ip_currid = tt.tv_sec & 0xffff;
     
    186186                 * of this datagram.
    187187                 */
    188                 for (fp = u32_to_ptr(ipq.next, struct ipq_t *); fp != &ipq;
    189                      fp = u32_to_ptr(fp->next, struct ipq_t *))
     188                for (fp = u32_to_ptr(pData, ipq.next, struct ipq_t *); fp != &ipq;
     189                     fp = u32_to_ptr(pData, fp->next, struct ipq_t *))
    190190                  if (ip->ip_id == fp->ipq_id &&
    191191                      ip->ip_src.s_addr == fp->ipq_src.s_addr &&
     
    336336          fp->ipq_p = ip->ip_p;
    337337          fp->ipq_id = ip->ip_id;
    338           fp->ipq_next = fp->ipq_prev = ptr_to_u32((struct ipasfrag *)fp);
     338          fp->ipq_next = fp->ipq_prev = ptr_to_u32(pData, (struct ipasfrag *)fp);
    339339          fp->ipq_src = ((struct ip *)ip)->ip_src;
    340340          fp->ipq_dst = ((struct ip *)ip)->ip_dst;
     
    346346         * Find a segment which begins after this one does.
    347347         */
    348         for (q = u32_to_ptr(fp->ipq_next, struct ipasfrag *); q != (struct ipasfrag *)fp;
    349             q = u32_to_ptr(q->ipf_next, struct ipasfrag *))
     348        for (q = u32_to_ptr(pData, fp->ipq_next, struct ipasfrag *); q != (struct ipasfrag *)fp;
     349            q = u32_to_ptr(pData, q->ipf_next, struct ipasfrag *))
    350350                if (q->ip_off > ip->ip_off)
    351351                        break;
     
    356356         * segment.  If it provides all of our data, drop us.
    357357         */
    358         if (u32_to_ptr(q->ipf_prev, struct ipq_t *) != fp) {
    359                 i = (u32_to_ptr(q->ipf_prev, struct ipasfrag *))->ip_off +
    360                   (u32_to_ptr(q->ipf_prev, struct ipasfrag *))->ip_len - ip->ip_off;
     358        if (u32_to_ptr(pData, q->ipf_prev, struct ipq_t *) != fp) {
     359                i = (u32_to_ptr(pData, q->ipf_prev, struct ipasfrag *))->ip_off +
     360                  (u32_to_ptr(pData, q->ipf_prev, struct ipasfrag *))->ip_len - ip->ip_off;
    361361                if (i > 0) {
    362362                        if (i >= ip->ip_len)
     
    388388                        break;
    389389                }
    390                 q = u32_to_ptr(q->ipf_next, struct ipasfrag *);
    391                 m_freem(pData, dtom(pData, u32_to_ptr(q->ipf_prev, struct ipasfrag *)));
    392                 ip_deq(u32_to_ptr(q->ipf_prev, struct ipasfrag *));
     390                q = u32_to_ptr(pData, q->ipf_next, struct ipasfrag *);
     391                m_freem(pData, dtom(pData, u32_to_ptr(pData, q->ipf_prev, struct ipasfrag *)));
     392                ip_deq(pData, u32_to_ptr(pData, q->ipf_prev, struct ipasfrag *));
    393393        }
    394394
     
    398398         * check for complete reassembly.
    399399         */
    400         ip_enq(ip, u32_to_ptr(q->ipf_prev, struct ipasfrag *));
     400        ip_enq(pData, ip, u32_to_ptr(pData, q->ipf_prev, struct ipasfrag *));
    401401        next = 0;
    402         for (q = u32_to_ptr(fp->ipq_next, struct ipasfrag *); q != (struct ipasfrag *)fp;
    403              q = u32_to_ptr(q->ipf_next, struct ipasfrag *)) {
     402        for (q = u32_to_ptr(pData, fp->ipq_next, struct ipasfrag *); q != (struct ipasfrag *)fp;
     403             q = u32_to_ptr(pData, q->ipf_next, struct ipasfrag *)) {
    404404                if (q->ip_off != next)
    405405                        return (0);
    406406                next += q->ip_len;
    407407        }
    408         if (u32_to_ptr(q->ipf_prev, struct ipasfrag *)->ipf_mff & 1)
     408        if (u32_to_ptr(pData, q->ipf_prev, struct ipasfrag *)->ipf_mff & 1)
    409409                return (0);
    410410
     
    412412         * Reassembly is complete; concatenate fragments.
    413413         */
    414         q = u32_to_ptr(fp->ipq_next, struct ipasfrag *);
     414        q = u32_to_ptr(pData, fp->ipq_next, struct ipasfrag *);
    415415#ifdef VBOX
    416416        m = dtom(pData, q);
     
    419419#endif /* !VBOX */
    420420
    421         q = u32_to_ptr(q->ipf_next, struct ipasfrag *);
     421        q = u32_to_ptr(pData, q->ipf_next, struct ipasfrag *);
    422422        while (q != (struct ipasfrag *)fp) {
    423423          struct mbuf *t;
     
    427427          t = dtom(q);
    428428#endif /* !VBOX */
    429           q = u32_to_ptr(q->ipf_next, struct ipasfrag *);
     429          q = u32_to_ptr(pData, q->ipf_next, struct ipasfrag *);
    430430#ifdef VBOX
    431431          m_cat(pData, m, t);
     
    441441         * Make header visible.
    442442         */
    443         ip = u32_to_ptr(fp->ipq_next, struct ipasfrag *);
     443        ip = u32_to_ptr(pData, fp->ipq_next, struct ipasfrag *);
    444444
    445445        /*
     
    500500        register struct ipasfrag *q, *p;
    501501
    502         for (q = u32_to_ptr(fp->ipq_next, struct ipasfrag *); q != (struct ipasfrag *)fp;
     502        for (q = u32_to_ptr(pData, fp->ipq_next, struct ipasfrag *); q != (struct ipasfrag *)fp;
    503503            q = p) {
    504                 p = u32_to_ptr(q->ipf_next, struct ipasfrag *);
    505                 ip_deq(q);
     504                p = u32_to_ptr(pData, q->ipf_next, struct ipasfrag *);
     505                ip_deq(pData, q);
    506506#ifdef VBOX
    507507                m_freem(pData, dtom(pData, q));
     
    523523 */
    524524void
    525 ip_enq(p, prev)
    526         register struct ipasfrag *p, *prev;
     525ip_enq(PNATState pData, register struct ipasfrag *p, register struct ipasfrag *prev)
    527526{
    528527        DEBUG_CALL("ip_enq");
    529528        DEBUG_ARG("prev = %lx", (long)prev);
    530         p->ipf_prev = ptr_to_u32(prev);
     529        p->ipf_prev = ptr_to_u32(pData, prev);
    531530        p->ipf_next = prev->ipf_next;
    532         u32_to_ptr(prev->ipf_next, struct ipasfrag *)->ipf_prev = ptr_to_u32(p);
    533         prev->ipf_next = ptr_to_u32(p);
     531        u32_to_ptr(pData, prev->ipf_next, struct ipasfrag *)->ipf_prev = ptr_to_u32(pData, p);
     532        prev->ipf_next = ptr_to_u32(pData, p);
    534533}
    535534
     
    538537 */
    539538void
    540 ip_deq(p)
    541         register struct ipasfrag *p;
     539ip_deq(PNATState pData, register struct ipasfrag *p)
    542540{
    543         struct ipasfrag *prev = u32_to_ptr(p->ipf_prev, struct ipasfrag *);
    544         struct ipasfrag *next = u32_to_ptr(p->ipf_next, struct ipasfrag *);
    545         u32ptr_done(prev->ipf_next, p);
     541        struct ipasfrag *prev = u32_to_ptr(pData, p->ipf_prev, struct ipasfrag *);
     542        struct ipasfrag *next = u32_to_ptr(pData, p->ipf_next, struct ipasfrag *);
     543        u32ptr_done(pData, prev->ipf_next, p);
    546544        prev->ipf_next = p->ipf_next;
    547545        next->ipf_prev = p->ipf_prev;
     
    564562        DEBUG_CALL("ip_slowtimo");
    565563
    566         fp = u32_to_ptr(ipq.next, struct ipq_t *);
     564        fp = u32_to_ptr(pData, ipq.next, struct ipq_t *);
    567565        if (fp == 0)
    568566           return;
     
    570568        while (fp != &ipq) {
    571569                --fp->ipq_ttl;
    572                 fp = u32_to_ptr(fp->next, struct ipq_t *);
    573                 if (u32_to_ptr(fp->prev, struct ipq_t *)->ipq_ttl == 0) {
     570                fp = u32_to_ptr(pData, fp->next, struct ipq_t *);
     571                if (u32_to_ptr(pData, fp->prev, struct ipq_t *)->ipq_ttl == 0) {
    574572                        ipstat.ips_fragtimeout++;
    575                         ip_freef(pData, u32_to_ptr(fp->prev, struct ipq_t *));
     573                        ip_freef(pData, u32_to_ptr(pData, fp->prev, struct ipq_t *));
    576574                }
    577575        }
  • trunk/src/VBox/Devices/Network/slirp/libslirp.h

    r1033 r1039  
    3636void slirp_link_up(PNATState);
    3737void slirp_link_down(PNATState);
    38 # if ARCH_BITS == 64
    39 error fix the last remaining global variables.....
    40 extern uint32_t g_cpvHashUsed;
    41 extern uint32_t g_cpvHashCollisions;
    42 extern uint64_t g_cpvHashInserts;
    43 extern uint64_t g_cpvHashDone;
    44 # endif
    4538#endif /* VBOX */
    4639
  • trunk/src/VBox/Devices/Network/slirp/mbuf.c

    r1033 r1039  
    133133         */
    134134        if (m->m_flags & M_DOFREE) {
    135                 u32ptr_done(ptr_to_u32(m), m);
     135                u32ptr_done(pData, ptr_to_u32(pData, m), m);
    136136                free(m);
    137137                mbuf_alloced--;
  • trunk/src/VBox/Devices/Network/slirp/misc.c

    r1036 r1039  
    116116#endif
    117117void
    118 insque_32(a, b)
    119         void *a;
    120         void *b;
     118insque_32(PNATState pData, void *a, void *b)
    121119{
    122120        register struct quehead_32 *element = (struct quehead_32 *) a;
    123121        register struct quehead_32 *head = (struct quehead_32 *) b;
    124         struct quehead_32 *link = u32_to_ptr(head->qh_link, struct quehead_32 *);
     122        struct quehead_32 *link = u32_to_ptr(pData, head->qh_link, struct quehead_32 *);
    125123
    126124        element->qh_link = head->qh_link;
    127         element->qh_rlink = ptr_to_u32(head);
     125        element->qh_rlink = ptr_to_u32(pData, head);
    128126        Assert(link->qh_rlink == element->qh_rlink);
    129         link->qh_rlink = head->qh_link = ptr_to_u32(element);
     127        link->qh_rlink = head->qh_link = ptr_to_u32(pData, element);
    130128}
    131129
     
    134132#endif
    135133void
    136 remque_32(a)
    137         void *a;
     134remque_32(PNATState *pData, void *a)
    138135{
    139136        register struct quehead_32 *element = (struct quehead_32 *) a;
    140         struct quehead_32 *link = u32_to_ptr(element->qh_link, struct quehead_32 *);
    141         struct quehead_32 *rlink = u32_to_ptr(element->qh_rlink, struct quehead_32 *);
    142 
    143         u32ptr_done(link->qh_rlink, element);
     137        struct quehead_32 *link = u32_to_ptr(pData, element->qh_link, struct quehead_32 *);
     138        struct quehead_32 *rlink = u32_to_ptr(pData, element->qh_rlink, struct quehead_32 *);
     139
     140        u32ptr_done(pData, link->qh_rlink, element);
    144141        link->qh_rlink = element->qh_rlink;
    145142        rlink->qh_link = element->qh_link;
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r1036 r1039  
    217217    memset(pData, '\0', sizeof(NATState));
    218218    pData->pvUser = pvUser;
     219#if ARCH_BITS == 64
     220    pData->cpvHashUsed = 1;
     221#endif
    219222#endif /* VBOX */
    220223
     
    314317void slirp_term(PNATState pData)
    315318{
     319#if ARCH_BITS == 64
     320    LogRel(("NAT: cpvHashUsed=%RU32 cpvHashCollisions=%RU32 cpvHashInserts=%RU64 cpvHashDone=%RU64\n",
     321            pData->cpvHashUsed, pData->cpvHashCollisions, pData->cpvHashInserts, pData->cpvHashDone));
     322#endif
     323
    316324    slirp_link_down(pData);
    317325#ifdef WIN32
     
    406414                 */
    407415                do_slowtimo = ((tcb.so_next != &tcb) ||
    408                                ((struct ipasfrag *)&ipq != u32_to_ptr(ipq.next, struct ipasfrag *)));
     416                               ((struct ipasfrag *)&ipq != u32_to_ptr(pData, ipq.next, struct ipasfrag *)));
    409417
    410418                for (so = tcb.so_next; so != &tcb; so = so_next) {
  • trunk/src/VBox/Devices/Network/slirp/slirp.h

    r1033 r1039  
    374374struct ip * ip_reass _P((PNATState, register struct ipasfrag *, register struct ipq_t *));
    375375void ip_freef _P((PNATState, struct ipq_t *));
     376void ip_enq _P((PNATState, register struct ipasfrag *, register struct ipasfrag *));
     377void ip_deq _P((PNATState, register struct ipasfrag *));
     378void ip_slowtimo _P((PNATState));
    376379#else /* !VBOX */
    377380void ip_init _P((void));
     
    379382struct ip * ip_reass _P((register struct ipasfrag *, register struct ipq *));
    380383void ip_freef _P((struct ipq *));
    381 #endif /* !VBOX */
    382384void ip_enq _P((register struct ipasfrag *, register struct ipasfrag *));
    383385void ip_deq _P((register struct ipasfrag *));
    384 #ifdef VBOX
    385 void ip_slowtimo _P((PNATState));
    386 #else /* !VBOX */
    387386void ip_slowtimo _P((void));
    388387#endif /* !VBOX */
     
    428427#ifdef VBOX
    429428void tcp_respond _P((PNATState, struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
     429struct tcpcb * tcp_newtcpcb _P((PNATState, struct socket *));
     430struct tcpcb * tcp_close _P((PNATState, register struct tcpcb *));
    430431#else /* !VBOX */
    431432void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
    432 #endif /* !VBOX */
    433433struct tcpcb * tcp_newtcpcb _P((struct socket *));
    434 #ifdef VBOX
    435 struct tcpcb * tcp_close _P((PNATState, register struct tcpcb *));
    436 #else /* !VBOX */
    437434struct tcpcb * tcp_close _P((register struct tcpcb *));
    438435#endif /* !VBOX */
  • trunk/src/VBox/Devices/Network/slirp/slirp_state.h

    r1034 r1039  
    9595    struct socket *tcp_last_so;
    9696    tcp_seq tcp_iss;
     97#if ARCH_BITS == 64
     98    /* Stuff from tcp_subr.c */
     99    void *apvHash[1024];
     100    uint32_t cpvHashUsed;
     101    uint32_t cpvHashCollisions;
     102    uint64_t cpvHashInserts;
     103    uint64_t cpvHashDone;
     104#endif
    97105    /* Stuff from tcp_timer.c */
    98106    struct tcpstat_t tcpstat;
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r1033 r1039  
    642642
    643643        /* Don't tcp_attach... we don't need so_snd nor so_rcv */
    644         if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {
     644        if ((so->so_tcpcb = tcp_newtcpcb(pData, so)) == NULL) {
    645645                free(so);
    646646                return NULL;
  • trunk/src/VBox/Devices/Network/slirp/tcp_input.c

    r1033 r1039  
    7575#define TCP_REASS(pData, tp, ti, m, so, flags) {\
    7676       if ((ti)->ti_seq == (tp)->rcv_nxt && \
    77            u32_to_ptr((tp)->seg_next, struct tcpcb *) == (tp) && \
     77           u32_to_ptr((pData), (tp)->seg_next, struct tcpcb *) == (tp) && \
    7878           (tp)->t_state == TCPS_ESTABLISHED) {\
    7979               if (ti->ti_flags & TH_PUSH) \
     
    9898#define TCP_REASS(pData, tp, ti, m, so, flags) { \
    9999        if ((ti)->ti_seq == (tp)->rcv_nxt && \
    100             u32_to_ptr((tp)->seg_next, struct tcpcb *) == (tp) && \
     100            u32_to_ptr((pData), (tp)->seg_next, struct tcpcb *) == (tp) && \
    101101            (tp)->t_state == TCPS_ESTABLISHED) { \
    102102                tp->t_flags |= TF_DELACK; \
     
    187187         * Find a segment which begins after this one does.
    188188         */
    189         for (q = u32_to_ptr(tp->seg_next, struct tcpiphdr *); q != (struct tcpiphdr *)tp;
    190             q = u32_to_ptr(q->ti_next, struct tcpiphdr *))
     189        for (q = u32_to_ptr(pData, tp->seg_next, struct tcpiphdr *); q != (struct tcpiphdr *)tp;
     190            q = u32_to_ptr(pData, q->ti_next, struct tcpiphdr *))
    191191                if (SEQ_GT(q->ti_seq, ti->ti_seq))
    192192                        break;
     
    197197         * segment.  If it provides all of our data, drop us.
    198198         */
    199         if (u32_to_ptr(q->ti_prev, struct tcpiphdr *) != (struct tcpiphdr *)tp) {
     199        if (u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *) != (struct tcpiphdr *)tp) {
    200200                register int i;
    201                 q = u32_to_ptr(q->ti_prev, struct tcpiphdr *);
     201                q = u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *);
    202202                /* conversion to int (in i) handles seq wraparound */
    203203                i = q->ti_seq + q->ti_len - ti->ti_seq;
     
    223223                        ti->ti_seq += i;
    224224                }
    225                 q = u32_to_ptr(q->ti_next, struct tcpiphdr *);
     225                q = u32_to_ptr(pData, q->ti_next, struct tcpiphdr *);
    226226        }
    227227        tcpstat.tcps_rcvoopack++;
     
    243243                        break;
    244244                }
    245                 q = u32_to_ptr(q->ti_next, struct tcpiphdr *);
    246                 m = REASS_MBUF_GET(u32_to_ptr(q->ti_prev, struct tcpiphdr *));
    247                 remque_32(u32_to_ptr(q->ti_prev, struct tcpiphdr *));
     245                q = u32_to_ptr(pData, q->ti_next, struct tcpiphdr *);
     246                m = REASS_MBUF_GET(u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *));
     247                remque_32(u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *));
    248248#ifdef VBOX
    249249                m_freem(pData, m);
     
    256256         * Stick new segment in its place.
    257257         */
    258         insque_32(ti, u32_to_ptr(q->ti_prev, struct tcpiphdr *));
     258        insque_32(ti, u32_to_ptr(pData, q->ti_prev, struct tcpiphdr *));
    259259
    260260present:
     
    265265        if (!TCPS_HAVEESTABLISHED(tp->t_state))
    266266                return (0);
    267         ti = u32_to_ptr(tp->seg_next, struct tcpiphdr *);
     267        ti = u32_to_ptr(pData, tp->seg_next, struct tcpiphdr *);
    268268        if (ti == (struct tcpiphdr *)tp || ti->ti_seq != tp->rcv_nxt)
    269269                return (0);
     
    275275                remque_32(ti);
    276276                m = REASS_MBUF_GET(ti); /* XXX */
    277                 ti = u32_to_ptr(ti->ti_next, struct tcpiphdr *);
     277                ti = u32_to_ptr(pData, ti->ti_next, struct tcpiphdr *);
    278278/*              if (so->so_state & SS_FCANTRCVMORE) */
    279279                if (so->so_state & SS_FCANTSENDMORE)
     
    647647                        }
    648648                } else if (ti->ti_ack == tp->snd_una &&
    649                     u32_to_ptr(tp->seg_next, struct tcpcb *) == tp &&
     649                    u32_to_ptr(pData, tp->seg_next, struct tcpcb *) == tp &&
    650650                    ti->ti_len <= sbspace(&so->so_rcv)) {
    651651                        /*
  • trunk/src/VBox/Devices/Network/slirp/tcp_subr.c

    r1033 r1039  
    221221 */
    222222struct tcpcb *
    223 tcp_newtcpcb(so)
    224         struct socket *so;
     223tcp_newtcpcb(PNATState pData, struct socket *so)
    225224{
    226225        register struct tcpcb *tp;
     
    231230
    232231        memset((char *) tp, 0, sizeof(struct tcpcb));
    233         tp->seg_next = tp->seg_prev = ptr_to_u32((struct tcpiphdr *)tp);
     232        tp->seg_next = tp->seg_prev = ptr_to_u32(pData, (struct tcpiphdr *)tp);
    234233        tp->t_maxseg = tcp_mssdflt;
    235234
     
    323322
    324323        /* free the reassembly queue, if any */
    325         t = u32_to_ptr(tp->seg_next, struct tcpiphdr *);
     324        t = u32_to_ptr(pData, tp->seg_next, struct tcpiphdr *);
    326325        while (t != (struct tcpiphdr *)tp) {
    327                 t = u32_to_ptr(t->ti_next, struct tcpiphdr *);
    328                 m = REASS_MBUF_GET(u32_to_ptr(t->ti_prev, struct tcpiphdr *));
    329                 remque_32(u32_to_ptr(t->ti_prev, struct tcpiphdr *));
     326                t = u32_to_ptr(pData, t->ti_next, struct tcpiphdr *);
     327                m = REASS_MBUF_GET(u32_to_ptr(pData, t->ti_prev, struct tcpiphdr *));
     328                remque_32(u32_to_ptr(pData, t->ti_prev, struct tcpiphdr *));
    330329#ifdef VBOX
    331330                m_freem(pData, m);
     
    339338 */
    340339/*      free(tp, M_PCB);  */
    341         u32ptr_done(ptr_to_u32(tp), tp);
     340        u32ptr_done(pData, ptr_to_u32(pData, tp), tp);
    342341        free(tp);
    343342        so->so_tcpcb = 0;
     
    638637#endif /* !VBOX */
    639638{
    640         if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL)
     639        if ((so->so_tcpcb = tcp_newtcpcb(pData, so)) == NULL)
    641640           return -1;
    642641
     
    14961495
    14971496#if defined(VBOX) && SIZEOF_CHAR_P != 4
    1498 /** Hash table used for translating pointers to unique uint32_t entries.
    1499 * The 0 entry is reserved for NULL pointers. */
    1500 void       *g_apvHash[16384];
    1501 /** The number of currently used pointer hash entries. */
    1502 uint32_t    g_cpvHashUsed = 1;
    1503 /** The number of insert collisions. */
    1504 uint32_t    g_cpvHashCollisions = 0;
    1505 /** The number of hash inserts. */
    1506 uint64_t    g_cpvHashInserts = 0;
    1507 /** The number of done calls. */
    1508 uint64_t    g_cpvHashDone = 0;
    1509 
    15101497/**
    15111498 * Slow pointer hashing that deals with automatic inserting and collisions.
    15121499 */
    1513 uint32_t VBoxU32PtrHashSlow(void *pv)
     1500uint32_t VBoxU32PtrHashSlow(PNATState pData, void *pv)
    15141501{
    15151502    uint32_t i;
     
    15181505    else
    15191506    {
    1520         const uint32_t i1 = ((uintptr_t)pv >> 3) % RT_ELEMENTS(g_apvHash);
    1521         if (g_apvHash[i1] == pv)
     1507        const uint32_t i1 = ((uintptr_t)pv >> 3) % RT_ELEMENTS(pData->apvHash);
     1508        if (pData->apvHash[i1] == pv)
    15221509            i = i1;
    15231510        else
     
    15291516             */
    15301517            const uint32_t  i2 = ((uintptr_t)pv >> 2) % 7867;
    1531             uint32_t        i1stFree = g_apvHash[i1] ? 0 : i1;
     1518            uint32_t        i1stFree = pData->apvHash[i1] ? 0 : i1;
    15321519            int             cTries = 10;
    15331520            int             cTries2 = 100;
     
    15421529                    {
    15431530                        i = i1stFree;
    1544                         g_apvHash[i] = pv;
    1545                         g_cpvHashUsed++;
     1531                        pData->apvHash[i] = pv;
     1532                        pData->cpvHashUsed++;
    15461533                        if (i != i1)
    1547                             g_cpvHashCollisions++;
    1548                         g_cpvHashInserts++;
     1534                            pData->cpvHashCollisions++;
     1535                        pData->cpvHashInserts++;
    15491536                        break;
    15501537                    }
    15511538                    if (!cTries2)
    15521539                    {
    1553                         AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%d g_cpvHashCollisions=%u\n",
    1554                                                 pv, g_cpvHashUsed, g_cpvHashCollisions));
     1540                        AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p cpvHashUsed=%d cpvHashCollisions=%u\n",
     1541                                                pv, pData->cpvHashUsed, pData->cpvHashCollisions));
    15551542                        i = 0;
    15561543                        break;
     
    15611548
    15621549                /* advance to the next hash entry and test it. */
    1563                 i = (i + i2) % RT_ELEMENTS(g_apvHash);
     1550                i = (i + i2) % RT_ELEMENTS(pData->apvHash);
    15641551                while (RT_UNLIKELY(!i))
    1565                     i = (i + i2) % RT_ELEMENTS(g_apvHash);
    1566                 if (g_apvHash[i] == pv)
     1552                    i = (i + i2) % RT_ELEMENTS(pData->apvHash);
     1553                if (pData->apvHash[i] == pv)
    15671554                    break;
    1568                 if (RT_UNLIKELY(!i1stFree && !g_apvHash[i]))
     1555                if (RT_UNLIKELY(!i1stFree && !pData->apvHash[i]))
    15691556                    i1stFree = i;
    15701557            }
     
    15781565 * Removes the pointer from the hash table.
    15791566 */
    1580 void VBoxU32PtrDone(void *pv, uint32_t iHint)
     1567void VBoxU32PtrDone(PNATSTate pData, void *pv, uint32_t iHint)
    15811568{
    15821569    /* We don't count NULL pointers. */
    15831570    if (pv == NULL)
    15841571        return;
    1585     g_cpvHashDone++;
     1572    pData->cpvHashDone++;
    15861573
    15871574    /* try the hint */
    15881575    if (    iHint
    1589         &&  iHint < RT_ELEMENTS(g_apvHash)
    1590         &&  g_apvHash[iHint] == pv)
     1576        &&  iHint < RT_ELEMENTS(pData->apvHash)
     1577        &&  pData->apvHash[iHint] == pv)
    15911578    {
    1592         g_apvHash[iHint] = NULL;
    1593         g_cpvHashUsed--;
     1579        pData->apvHash[iHint] = NULL;
     1580        pData->cpvHashUsed--;
    15941581        return;
    15951582    }
    15961583
    1597     iHint = ((uintptr_t)pv >> 3) % RT_ELEMENTS(g_apvHash);
    1598     if (RT_UNLIKELY(g_apvHash[iHint] != pv))
     1584    iHint = ((uintptr_t)pv >> 3) % RT_ELEMENTS(pData->apvHash);
     1585    if (RT_UNLIKELY(pData->apvHash[iHint] != pv))
    15991586    {
    16001587        /*
     
    16061593        {
    16071594            /* advance to the next hash entry and test it. */
    1608             iHint = (iHint + i2) % RT_ELEMENTS(g_apvHash);
     1595            iHint = (iHint + i2) % RT_ELEMENTS(pData->apvHash);
    16091596            while (RT_UNLIKELY(!iHint))
    1610                 iHint = (iHint + i2) % RT_ELEMENTS(g_apvHash);
    1611             if (g_apvHash[iHint] == pv)
     1597                iHint = (iHint + i2) % RT_ELEMENTS(pData->apvHash);
     1598            if (pData->apvHash[iHint] == pv)
    16121599                break;
    16131600
     
    16151602            if (--cTries > 0)
    16161603            {
    1617                 AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p g_cpvHashUsed=%u g_cpvHashCollisions=%u\n",
    1618                                         pv, g_cpvHashUsed, g_cpvHashCollisions));
     1604                AssertReleaseMsgFailed(("NAT pointer hash error. pv=%p cpvHashUsed=%u cpvHashCollisions=%u\n",
     1605                                        pv, pData->cpvHashUsed, pData->cpvHashCollisions));
    16191606                return;
    16201607            }
     
    16231610
    16241611    /* found it */
    1625     g_apvHash[iHint] = NULL;
    1626     g_cpvHashUsed--;
     1612    pData->apvHash[iHint] = NULL;
     1613    pData->cpvHashUsed--;
    16271614}
    16281615
  • trunk/src/VBox/Devices/Network/slirp/tcp_var.h

    r1033 r1039  
    4444 typedef struct tcpiphdr *tcpiphdrp_32;
    4545  /* VBox change that's to much bother to #ifdef. */
    46 # define u32ptr_done(u32, ptr)  do {} while (0)
    47 # define ptr_to_u32(ptr)        (ptr)
    48 # define u32_to_ptr(u32, type)  ((type)(u32))
     46# define u32ptr_done(pData, u32, ptr)  do {} while (0)
     47# define ptr_to_u32(pData, ptr)        (ptr)
     48# define u32_to_ptr(pData, u32, type)  ((type)(u32))
    4949#else
    5050 typedef u_int32_t tcpiphdrp_32;
     
    5454
    5555   /* VBox change that's to much bother to #ifdef. */
    56 #  define u32ptr_done(u32, ptr) VBoxU32PtrDone((ptr), (u32))
    57 #  define ptr_to_u32(ptr)       VBoxU32PtrHash((ptr))
    58 #  define u32_to_ptr(u32, type) ((type)VBoxU32PtrLookup(u32))
    59 
    60     extern void       *g_apvHash[16384];
    61 
    62     extern void     VBoxU32PtrDone(void *pv, uint32_t iHint);
    63     extern uint32_t VBoxU32PtrHashSlow(void *pv);
     56#  define u32ptr_done(u32, ptr) VBoxU32PtrDone((pData), (ptr), (u32))
     57#  define ptr_to_u32(ptr)       VBoxU32PtrHash((pData), (ptr))
     58#  define u32_to_ptr(u32, type) ((type)VBoxU32PtrLookup((pData), (u32)))
     59
     60    extern void     VBoxU32PtrDone(PNATSTate pData, void *pv, uint32_t iHint);
     61    extern uint32_t VBoxU32PtrHashSlow(PNATState pData, void *pv);
    6462
    6563    /** Hash the pointer, inserting it if need be. */
    66     DECLINLINE(uint32_t) VBoxU32PtrHash(void *pv)
     64    DECLINLINE(uint32_t) VBoxU32PtrHash(PNATState pData, void *pv)
    6765    {
    68         uint32_t i = ((uintptr_t)pv >> 3) % RT_ELEMENTS(g_apvHash);
    69         if (RT_LIKELY(g_apvHash[i] == pv && pv))
     66        uint32_t i = ((uintptr_t)pv >> 3) % RT_ELEMENTS(pData->apvHash);
     67        if (RT_LIKELY(pData->apvHash[i] == pv && pv))
    7068            return i;
    71         return VBoxU32PtrHashSlow(pv);
     69        return VBoxU32PtrHashSlow(pData, pv);
    7270    }
    7371    /** Lookup the hash value. */
    74     DECLINLINE(void *) VBoxU32PtrLookup(uint32_t i)
     72    DECLINLINE(void *) VBoxU32PtrLookup(PNATState pData, uint32_t i)
    7573    {
    7674        void *pv;
    77         Assert(i < RT_ELEMENTS(g_apvHash));
    78         pv = g_apvHash[i];
     75        Assert(i < RT_ELEMENTS(pData->apvHash));
     76        pv = pData->apvHash[i];
    7977        Assert(pv || !i);
    8078        return pv;
     
    229227/* VBox change which is too much bother to #ifdef */
    230228# define REASS_MBUF_SET(ti, p) (*(mbufp_32 *)&((ti)->ti_t)) = ptr_to_u32(p)
    231 # define REASS_MBUF_GET(ti)    u32_to_ptr((*(mbufp_32 *)&((ti)->ti_t)), struct mbuf *)
     229# define REASS_MBUF_GET(ti)    u32_to_ptr(pData, (*(mbufp_32 *)&((ti)->ti_t)), struct mbuf *)
    232230#endif
    233231/*#define REASS_MBUF(ti) (*(mbufp_32 *)&((ti)->ti_t)) - replaced by REASS_MBUF_GET/SET */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette