Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/packet/generic/packet_server.c

    rdd5046dd r88b127b  
    3636
    3737#include <packet_server.h>
     38#include <packet_local.h>
    3839
    3940#include <align.h>
     
    6869        fibril_mutex_t lock;
    6970        /** Free packet queues. */
    70         packet_t *free[FREE_QUEUES_COUNT];
     71        packet_t free[FREE_QUEUES_COUNT];
    7172       
    7273        /**
     
    102103};
    103104
     105int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id)
     106{
     107        if (!packet)
     108                return EINVAL;
     109       
     110        *packet = pm_find(packet_id);
     111        return (*packet) ? EOK : ENOENT;
     112}
     113
    104114/** Clears and initializes the packet according to the given dimensions.
    105115 *
     
    112122 */
    113123static void
    114 packet_init(packet_t *packet, size_t addr_len, size_t max_prefix,
     124packet_init(packet_t packet, size_t addr_len, size_t max_prefix,
    115125    size_t max_content, size_t max_suffix)
    116126{
    117127        // clear the packet content
    118         bzero(((void *) packet) + sizeof(packet_t),
    119             packet->length - sizeof(packet_t));
     128        bzero(((void *) packet) + sizeof(struct packet),
     129            packet->length - sizeof(struct packet));
    120130       
    121131        // clear the packet header
     
    125135        packet->next = 0;
    126136        packet->addr_len = 0;
    127         packet->src_addr = sizeof(packet_t);
     137        packet->src_addr = sizeof(struct packet);
    128138        packet->dest_addr = packet->src_addr + addr_len;
    129139        packet->max_prefix = max_prefix;
     
    144154 * @param[in] max_content The maximal content length in bytes.
    145155 * @param[in] max_suffix The maximal suffix length in bytes.
    146  * @return              The packet of dimensions at least as given.
    147  * @return              NULL if there is not enough memory left.
    148  */
    149 static packet_t *
     156 * @returns             The packet of dimensions at least as given.
     157 * @returns             NULL if there is not enough memory left.
     158 */
     159static packet_t
    150160packet_create(size_t length, size_t addr_len, size_t max_prefix,
    151161    size_t max_content, size_t max_suffix)
    152162{
    153         packet_t *packet;
     163        packet_t packet;
    154164        int rc;
    155165
    156166        // already locked
    157         packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE,
     167        packet = (packet_t) mmap(NULL, length, PROTO_READ | PROTO_WRITE,
    158168            MAP_SHARED | MAP_ANONYMOUS, 0, 0);
    159169        if (packet == MAP_FAILED)
     
    188198 * @return              NULL if there is not enough memory left.
    189199 */
    190 static packet_t *
     200static packet_t
    191201packet_get_local(size_t addr_len, size_t max_prefix, size_t max_content,
    192202    size_t max_suffix)
    193203{
    194         size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len +
     204        size_t length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len +
    195205            max_prefix + max_content + max_suffix, PAGE_SIZE);
    196206       
    197207        fibril_mutex_lock(&ps_globals.lock);
    198208       
    199         packet_t *packet;
     209        packet_t packet;
    200210        unsigned int index;
    201211       
     
    231241}
    232242
     243packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len,
     244    size_t max_prefix, size_t max_suffix)
     245{
     246        return packet_get_local(addr_len, max_prefix, max_content, max_suffix);
     247}
     248
     249packet_t packet_get_1_local(int phone, size_t content)
     250{
     251        return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content,
     252            DEFAULT_SUFFIX);
     253}
     254
    233255/** Release the packet and returns it to the appropriate free packet queue.
    234256 *
     
    238260 *
    239261 */
    240 static void packet_release(packet_t *packet)
     262static void packet_release(packet_t packet)
    241263{
    242264        int index;
     
    256278 *
    257279 * @param[in] packet_id The first packet identifier.
    258  * @return              EOK on success.
    259  * @return              ENOENT if there is no such packet.
     280 * @returns             EOK on success.
     281 * @returns             ENOENT if there is no such packet.
    260282 */
    261283static int packet_release_wrapper(packet_id_t packet_id)
    262284{
    263         packet_t *packet;
     285        packet_t packet;
    264286
    265287        packet = pm_find(packet_id);
     
    274296}
    275297
     298void pq_release_local(int phone, packet_id_t packet_id)
     299{
     300        (void) packet_release_wrapper(packet_id);
     301}
     302
    276303/** Shares the packet memory block.
    277304 * @param[in] packet    The packet to be shared.
    278  * @return              EOK on success.
    279  * @return              EINVAL if the packet is not valid.
    280  * @return              EINVAL if the calling module does not accept the memory.
    281  * @return              ENOMEM if the desired and actual sizes differ.
    282  * @return              Other error codes as defined for the
     305 * @returns             EOK on success.
     306 * @returns             EINVAL if the packet is not valid.
     307 * @returns             EINVAL if the calling module does not accept the memory.
     308 * @returns             ENOMEM if the desired and actual sizes differ.
     309 * @returns             Other error codes as defined for the
    283310 *                      async_share_in_finalize() function.
    284311 */
    285 static int packet_reply(packet_t *packet)
     312static int packet_reply(const packet_t packet)
    286313{
    287314        ipc_callid_t callid;
     
    312339 * @param[out] answer_count The last parameter for the actual answer in the
    313340 *                      answer parameter.
    314  * @return              EOK on success.
    315  * @return              ENOMEM if there is not enough memory left.
    316  * @return              ENOENT if there is no such packet as in the packet
     341 * @returns             EOK on success.
     342 * @returns             ENOMEM if there is not enough memory left.
     343 * @returns             ENOENT if there is no such packet as in the packet
    317344 *                      message parameter.
    318  * @return              ENOTSUP if the message is not known.
    319  * @return              Other error codes as defined for the
     345 * @returns             ENOTSUP if the message is not known.
     346 * @returns             Other error codes as defined for the
    320347 *                      packet_release_wrapper() function.
    321348 */
     
    324351    int *answer_count)
    325352{
    326         packet_t *packet;
     353        packet_t packet;
    327354
    328355        *answer_count = 0;
Note: See TracChangeset for help on using the changeset viewer.