Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/generic/packet_remote.c

    rfbcdeb8 rab9378b4  
    3838#include <async.h>
    3939#include <errno.h>
     40#include <fibril_synch.h>
    4041#include <ipc/packet.h>
    4142#include <sys/mman.h>
     
    4647#include <net/packet.h>
    4748#include <net/packet_header.h>
     49
     50static FIBRIL_MUTEX_INITIALIZE(packet_return_lock);
    4851
    4952/** Obtain the packet from the packet server as the shared memory block.
     
    6669    packet_id_t packet_id, size_t size)
    6770{
     71        /*
     72         * Prevent racing for address space with other invocations
     73         * of packet_return().
     74         *
     75         * XXX This of course does not prevent us racing with other
     76         * competitors for address space mapping.
     77         */
     78        fibril_mutex_lock(&packet_return_lock);
     79        *packet = (packet_t *) as_get_mappable_page(size);
     80       
    6881        async_exch_t *exch = async_exchange_begin(sess);
    6982        ipc_call_t answer;
    7083        aid_t message = async_send_1(exch, NET_PACKET_GET, packet_id, &answer);
    71         int rc = async_share_in_start_0_0(exch, size, (void *) packet);
     84        int rc = async_share_in_start_0_0(exch, *packet, size);
    7285        async_exchange_end(exch);
    7386       
     
    7588        async_wait_for(message, &result);
    7689       
    77         if (rc != EOK)
     90        if (rc != EOK) {
     91                munmap(*packet, size);
     92                fibril_mutex_unlock(&packet_return_lock);
    7893                return rc;
    79        
    80         if (packet == (void *) -1)
    81                 return ENOMEM;
     94        }
    8295       
    8396        rc = pm_add(*packet);
    8497        if (rc != EOK) {
    8598                munmap(*packet, size);
     99                fibril_mutex_unlock(&packet_return_lock);
    86100                return rc;
    87101        }
    88102       
     103        fibril_mutex_unlock(&packet_return_lock);
    89104        return result;
    90105}
Note: See TracChangeset for help on using the changeset viewer.