Changeset b4cbef1 in mainline for uspace/srv


Ignore:
Timestamp:
2010-02-03T16:52:37Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3b3e776, eda925a
Parents:
472c09d
Message:

add minimal data size check into async_data_receive
introduce more convenience wrappers for common IPC patterns:

async_data_read_forward_fast
async_data_void
async_data_forward_fast

Location:
uspace/srv
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/clip/clip.c

    r472c09d rb4cbef1  
    6565                break;
    6666        case CLIPBOARD_TAG_DATA:
    67                 rc = async_data_receive(&data, 0, 0, &size);
     67                rc = async_data_receive(&data, 0, 0, 0, &size);
    6868                if (rc != EOK) {
    6969                        ipc_answer_0(rid, rc);
  • uspace/srv/hid/console/console.c

    r472c09d rb4cbef1  
    477477        void *buf;
    478478        size_t size;
    479         int rc = async_data_receive(&buf, 0, 0, &size);
     479        int rc = async_data_receive(&buf, 0, 0, 0, &size);
    480480       
    481481        if (rc != EOK) {
  • uspace/srv/loader/main.c

    r472c09d rb4cbef1  
    230230static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    231231{
    232         void *buf;
     232        fdi_node_t *buf;
    233233        size_t buf_size;
    234         int rc = async_data_receive(&buf, 0, sizeof(fdi_node_t), &buf_size);
     234        int rc = async_data_receive(&buf, 0, 0, sizeof(fdi_node_t), &buf_size);
    235235       
    236236        if (rc == EOK) {
     
    252252                int i;
    253253                for (i = 0; i < count; i++)
    254                         _filv[i] = &((fdi_node_t *) buf)[i];
     254                        _filv[i] = &buf[i];
    255255               
    256256                _filv[count] = NULL;
     
    266266               
    267267                filc = count;
    268                 fil_buf = (fdi_node_t *) buf;
     268                fil_buf = buf;
    269269                filv = _filv;
    270270        }
  • uspace/srv/vfs/vfs_ops.c

    r472c09d rb4cbef1  
    794794       
    795795        /*
    796          * Now we need to receive a call with client's
    797          * IPC_M_DATA_READ/IPC_M_DATA_WRITE request.
    798          */
    799         ipc_callid_t callid;
    800         int res;
    801         if (read)
    802                 res = async_data_read_receive(&callid, NULL);
    803         else
    804                 res = async_data_write_receive(&callid, NULL);
    805         if (!res) {
    806                 ipc_answer_0(callid, EINVAL);
    807                 ipc_answer_0(rid, EINVAL);
    808                 return;
    809         }
    810        
    811         /*
    812796         * Lock the open file structure so that no other thread can manipulate
    813797         * the same open file at a time.
     
    833817        }
    834818       
    835         int fs_phone = vfs_grab_phone(file->node->fs_handle);   
    836        
    837         /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
    838         aid_t msg;
    839         ipc_call_t answer;
    840         if (!read && file->append)
    841                 file->pos = file->node->size;
    842         msg = async_send_3(fs_phone, read ? VFS_OUT_READ : VFS_OUT_WRITE,
    843             file->node->dev_handle, file->node->index, file->pos, &answer);
    844        
    845         /*
    846          * Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
     819        int fs_phone = vfs_grab_phone(file->node->fs_handle);
     820       
     821        /*
     822         * Make a VFS_READ/VFS_WRITE request at the destination FS server
     823         * and forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
    847824         * destination FS server. The call will be routed as if sent by
    848825         * ourselves. Note that call arguments are immutable in this case so we
    849826         * don't have to bother.
    850827         */
    851         ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    852 
    853         /* Wait for reply from the FS server. */
    854828        ipcarg_t rc;
    855         async_wait_for(msg, &rc);
     829        ipc_call_t answer;
     830        if (read) {
     831                if (file->append)
     832                        file->pos = file->node->size;
     833               
     834                rc = async_data_read_forward_3_1(fs_phone, VFS_OUT_READ,
     835                    file->node->dev_handle, file->node->index, file->pos,
     836                    &answer);
     837        } else {
     838                rc = async_data_forward_3_1(fs_phone, VFS_OUT_WRITE,
     839                    file->node->dev_handle, file->node->index, file->pos,
     840                    &answer);
     841        }
    856842       
    857843        vfs_release_phone(fs_phone);
    858844       
    859845        size_t bytes = IPC_GET_ARG1(answer);
    860 
     846       
    861847        if (file->node->type == VFS_NODE_DIRECTORY)
    862848                fibril_rwlock_read_unlock(&namespace_rwlock);
  • uspace/srv/vfs/vfs_register.c

    r472c09d rb4cbef1  
    110110void vfs_register(ipc_callid_t rid, ipc_call_t *request)
    111111{
    112         ipc_callid_t callid;
    113         ipc_call_t call;
    114         int rc;
    115         size_t size;
    116 
    117112        dprintf("Processing VFS_REGISTER request received from %p.\n",
    118113            request->in_phone_hash);
    119 
    120         /*
    121          * The first call has to be IPC_M_DATA_SEND in which we receive the
    122          * VFS info structure from the client FS.
    123          */
    124         if (!async_data_write_receive(&callid, &size)) {
    125                 /*
    126                  * The client doesn't obey the same protocol as we do.
    127                  */
    128                 dprintf("Receiving of VFS info failed.\n");
    129                 ipc_answer_0(callid, EINVAL);
    130                 ipc_answer_0(rid, EINVAL);
    131                 return;
    132         }
    133        
    134         dprintf("VFS info received, size = %d\n", size);
    135        
    136         /*
    137          * We know the size of the VFS info structure. See if the client
    138          * understands this easy concept too.
    139          */
    140         if (size != sizeof(vfs_info_t)) {
    141                 /*
    142                  * The client is sending us something, which cannot be
    143                  * the info structure.
    144                  */
    145                 dprintf("Received VFS info has bad size.\n");
    146                 ipc_answer_0(callid, EINVAL);
    147                 ipc_answer_0(rid, EINVAL);
    148                 return;
    149         }
    150 
    151         /*
    152          * Allocate and initialize a buffer for the fs_info structure.
    153          */
    154         fs_info_t *fs_info;
    155         fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
    156         if (!fs_info) {
    157                 dprintf("Could not allocate memory for FS info.\n");
    158                 ipc_answer_0(callid, ENOMEM);
    159                 ipc_answer_0(rid, ENOMEM);
    160                 return;
    161         }
    162         link_initialize(&fs_info->fs_link);
    163         fibril_mutex_initialize(&fs_info->phone_lock);
    164                
    165         rc = async_data_write_finalize(callid, &fs_info->vfs_info, size);
     114       
     115        vfs_info_t *vfs_info;
     116        int rc = async_data_receive(&vfs_info, sizeof(vfs_info_t),
     117            sizeof(vfs_info_t), 0, NULL);
     118       
    166119        if (rc != EOK) {
    167120                dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
    168121                    rc);
    169                 free(fs_info);
    170                 ipc_answer_0(callid, rc);
    171122                ipc_answer_0(rid, rc);
    172123                return;
    173124        }
    174 
     125       
     126        /*
     127         * Allocate and initialize a buffer for the fs_info structure.
     128         */
     129        fs_info_t *fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
     130        if (!fs_info) {
     131                dprintf("Could not allocate memory for FS info.\n");
     132                ipc_answer_0(rid, ENOMEM);
     133                return;
     134        }
     135       
     136        link_initialize(&fs_info->fs_link);
     137        fibril_mutex_initialize(&fs_info->phone_lock);
     138        fs_info->vfs_info = *vfs_info;
     139        free(vfs_info);
     140       
    175141        dprintf("VFS info delivered.\n");
    176                
     142       
    177143        if (!vfs_info_sane(&fs_info->vfs_info)) {
    178144                free(fs_info);
    179                 ipc_answer_0(callid, EINVAL);
    180145                ipc_answer_0(rid, EINVAL);
    181146                return;
    182147        }
    183                
     148       
    184149        fibril_mutex_lock(&fs_head_lock);
    185 
     150       
    186151        /*
    187152         * Check for duplicit registrations.
     
    194159                fibril_mutex_unlock(&fs_head_lock);
    195160                free(fs_info);
    196                 ipc_answer_0(callid, EEXISTS);
    197161                ipc_answer_0(rid, EEXISTS);
    198162                return;
    199163        }
    200 
     164       
    201165        /*
    202166         * Add fs_info to the list of registered FS's.
     
    210174         * which to forward VFS requests to it.
    211175         */
    212         callid = async_get_call(&call);
     176        ipc_call_t call;
     177        ipc_callid_t callid = async_get_call(&call);
    213178        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    214179                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    222187        fs_info->phone = IPC_GET_ARG5(call);
    223188        ipc_answer_0(callid, EOK);
    224 
     189       
    225190        dprintf("Callback connection to FS created.\n");
    226 
     191       
    227192        /*
    228193         * The client will want us to send him the address space area with PLB.
    229194         */
    230 
     195       
     196        size_t size;
    231197        if (!async_share_in_receive(&callid, &size)) {
    232198                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    253219                return;
    254220        }
    255 
     221       
    256222        /*
    257223         * Commit to read-only sharing the PLB with the client.
     
    259225        (void) async_share_in_finalize(callid, plb,
    260226            AS_AREA_READ | AS_AREA_CACHEABLE);
    261 
     227       
    262228        dprintf("Sharing PLB.\n");
    263 
     229       
    264230        /*
    265231         * That was it. The FS has been registered.
Note: See TracChangeset for help on using the changeset viewer.