Changeset 984a9ba in mainline for uspace/lib/usbvirt/src/ipc_dev.c


Ignore:
Timestamp:
2018-07-05T09:34:09Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63d46341
Parents:
76f566d
Message:

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/src/ipc_dev.c

    r76f566d r984a9ba  
    4444/** Handle VHC request for device name.
    4545 *
    46  * @param dev Target virtual device.
    47  * @param iid Caller id.
    48  * @param icall The call with the request.
    49  */
    50 static void ipc_get_name(usbvirt_device_t *dev,
    51     cap_call_handle_t icall_handle, ipc_call_t *icall)
     46 * @param dev   Target virtual device.
     47 * @param icall The call with the request.
     48 *
     49 */
     50static void ipc_get_name(usbvirt_device_t *dev, ipc_call_t *icall)
    5251{
    5352        if (dev->name == NULL) {
    54                 async_answer_0(icall_handle, ENOENT);
     53                async_answer_0(icall, ENOENT);
    5554        }
    5655
    5756        size_t size = str_size(dev->name);
    5857
    59         cap_call_handle_t chandle;
     58        ipc_call_t call;
    6059        size_t accepted_size;
    61         if (!async_data_read_receive(&chandle, &accepted_size)) {
    62                 async_answer_0(icall_handle, EINVAL);
     60        if (!async_data_read_receive(&call, &accepted_size)) {
     61                async_answer_0(icall, EINVAL);
    6362                return;
    6463        }
     
    6766                accepted_size = size;
    6867        }
    69         async_data_read_finalize(chandle, dev->name, accepted_size);
    70 
    71         async_answer_1(icall_handle, EOK, accepted_size);
     68        async_data_read_finalize(&call, dev->name, accepted_size);
     69
     70        async_answer_1(icall, EOK, accepted_size);
    7271}
    7372
    7473/** Handle VHC request for control read from the device.
    7574 *
    76  * @param dev Target virtual device.
    77  * @param iid Caller id.
    78  * @param icall The call with the request.
    79  */
    80 static void ipc_control_read(usbvirt_device_t *dev,
    81     cap_call_handle_t icall_handle, ipc_call_t *icall)
     75 * @param dev   Target virtual device.
     76 * @param icall The call with the request.
     77 *
     78 */
     79static void ipc_control_read(usbvirt_device_t *dev, ipc_call_t *icall)
    8280{
    8381        errno_t rc;
     
    9088            1, 1024, 0, &setup_packet_len);
    9189        if (rc != EOK) {
    92                 async_answer_0(icall_handle, rc);
    93                 return;
    94         }
    95 
    96         cap_call_handle_t data_chandle;
    97         if (!async_data_read_receive(&data_chandle, &data_len)) {
    98                 async_answer_0(icall_handle, EPARTY);
     90                async_answer_0(icall, rc);
     91                return;
     92        }
     93
     94        ipc_call_t data;
     95        if (!async_data_read_receive(&data, &data_len)) {
     96                async_answer_0(icall, EPARTY);
    9997                free(setup_packet);
    10098                return;
     
    103101        void *buffer = malloc(data_len);
    104102        if (buffer == NULL) {
    105                 async_answer_0(icall_handle, ENOMEM);
     103                async_answer_0(icall, ENOMEM);
    106104                free(setup_packet);
    107105                return;
     
    113111
    114112        if (rc != EOK) {
    115                 async_answer_0(data_chandle, rc);
    116                 async_answer_0(icall_handle, rc);
     113                async_answer_0(&data, rc);
     114                async_answer_0(icall, rc);
    117115                free(setup_packet);
    118116                free(buffer);
     
    120118        }
    121119
    122         async_data_read_finalize(data_chandle, buffer, actual_len);
    123         async_answer_0(icall_handle, EOK);
     120        async_data_read_finalize(&data, buffer, actual_len);
     121        async_answer_0(icall, EOK);
    124122
    125123        free(setup_packet);
     
    129127/** Handle VHC request for control write to the device.
    130128 *
    131  * @param dev Target virtual device.
    132  * @param iid Caller id.
    133  * @param icall The call with the request.
    134  */
    135 static void ipc_control_write(usbvirt_device_t *dev,
    136     cap_call_handle_t icall_handle, ipc_call_t *icall)
     129 * @param dev   Target virtual device.
     130 * @param icall The call with the request.
     131 *
     132 */
     133static void ipc_control_write(usbvirt_device_t *dev, ipc_call_t *icall)
    137134{
    138135        size_t data_buffer_len = IPC_GET_ARG1(*icall);
     
    146143            1, 0, 0, &setup_packet_len);
    147144        if (rc != EOK) {
    148                 async_answer_0(icall_handle, rc);
     145                async_answer_0(icall, rc);
    149146                return;
    150147        }
     
    154151                    1, 0, 0, &data_buffer_len);
    155152                if (rc != EOK) {
    156                         async_answer_0(icall_handle, rc);
     153                        async_answer_0(icall, rc);
    157154                        free(setup_packet);
    158155                        return;
     
    163160            data_buffer, data_buffer_len);
    164161
    165         async_answer_0(icall_handle, rc);
     162        async_answer_0(icall, rc);
    166163
    167164        free(setup_packet);
     
    173170/** Handle VHC request for data read from the device (in transfer).
    174171 *
    175  * @param dev Target virtual device.
    176  * @param iid Caller id.
    177  * @param icall The call with the request.
     172 * @param dev   Target virtual device.
     173 * @param icall The call with the request.
     174 *
    178175 */
    179176static void ipc_data_in(usbvirt_device_t *dev,
    180     usb_transfer_type_t transfer_type,
    181     cap_call_handle_t icall_handle, ipc_call_t *icall)
     177    usb_transfer_type_t transfer_type, ipc_call_t *icall)
    182178{
    183179        usb_endpoint_t endpoint = IPC_GET_ARG1(*icall);
     
    186182
    187183        size_t data_len = 0;
    188         cap_call_handle_t data_chandle;
    189         if (!async_data_read_receive(&data_chandle, &data_len)) {
    190                 async_answer_0(icall_handle, EPARTY);
     184        ipc_call_t data;
     185        if (!async_data_read_receive(&data, &data_len)) {
     186                async_answer_0(icall, EPARTY);
    191187                return;
    192188        }
     
    194190        void *buffer = malloc(data_len);
    195191        if (buffer == NULL) {
    196                 async_answer_0(icall_handle, ENOMEM);
     192                async_answer_0(icall, ENOMEM);
    197193                return;
    198194        }
     
    203199
    204200        if (rc != EOK) {
    205                 async_answer_0(data_chandle, rc);
    206                 async_answer_0(icall_handle, rc);
     201                async_answer_0(&data, rc);
     202                async_answer_0(icall, rc);
    207203                free(buffer);
    208204                return;
    209205        }
    210206
    211         async_data_read_finalize(data_chandle, buffer, actual_len);
    212         async_answer_0(icall_handle, EOK);
     207        async_data_read_finalize(&data, buffer, actual_len);
     208        async_answer_0(icall, EOK);
    213209
    214210        free(buffer);
     
    217213/** Handle VHC request for data write to the device (out transfer).
    218214 *
    219  * @param dev Target virtual device.
    220  * @param iid Caller id.
    221  * @param icall The call with the request.
     215 * @param dev   Target virtual device.
     216 * @param icall The call with the request.
     217 *
    222218 */
    223219static void ipc_data_out(usbvirt_device_t *dev,
    224     usb_transfer_type_t transfer_type,
    225     cap_call_handle_t icall_handle, ipc_call_t *icall)
     220    usb_transfer_type_t transfer_type, ipc_call_t *icall)
    226221{
    227222        usb_endpoint_t endpoint = IPC_GET_ARG1(*icall);
     
    233228            1, 0, 0, &data_buffer_size);
    234229        if (rc != EOK) {
    235                 async_answer_0(icall_handle, rc);
     230                async_answer_0(icall, rc);
    236231                return;
    237232        }
     
    240235            data_buffer, data_buffer_size);
    241236
    242         async_answer_0(icall_handle, rc);
     237        async_answer_0(icall, rc);
    243238
    244239        free(data_buffer);
     
    247242/** Handle incoming IPC call for virtual USB device.
    248243 *
    249  * @param dev Target USB device.
    250  * @param chandle Caller id.
     244 * @param dev  Target USB device.
    251245 * @param call Incoming call.
     246 *
    252247 * @return Whether the call was handled.
    253  */
    254 bool usbvirt_ipc_handle_call(usbvirt_device_t *dev,
    255     cap_call_handle_t chandle, ipc_call_t *call)
     248 *
     249 */
     250bool usbvirt_ipc_handle_call(usbvirt_device_t *dev, ipc_call_t *call)
    256251{
    257252        switch (IPC_GET_IMETHOD(*call)) {
    258253        case IPC_M_USBVIRT_GET_NAME:
    259                 ipc_get_name(dev, chandle, call);
     254                ipc_get_name(dev, call);
    260255                break;
    261256
    262257        case IPC_M_USBVIRT_CONTROL_READ:
    263                 ipc_control_read(dev, chandle, call);
     258                ipc_control_read(dev, call);
    264259                break;
    265260
    266261        case IPC_M_USBVIRT_CONTROL_WRITE:
    267                 ipc_control_write(dev, chandle, call);
     262                ipc_control_write(dev, call);
    268263                break;
    269264
    270265        case IPC_M_USBVIRT_INTERRUPT_IN:
    271                 ipc_data_in(dev, USB_TRANSFER_INTERRUPT, chandle, call);
     266                ipc_data_in(dev, USB_TRANSFER_INTERRUPT, call);
    272267                break;
    273268
    274269        case IPC_M_USBVIRT_BULK_IN:
    275                 ipc_data_in(dev, USB_TRANSFER_BULK, chandle, call);
     270                ipc_data_in(dev, USB_TRANSFER_BULK, call);
    276271                break;
    277272
    278273        case IPC_M_USBVIRT_INTERRUPT_OUT:
    279                 ipc_data_out(dev, USB_TRANSFER_INTERRUPT, chandle, call);
     274                ipc_data_out(dev, USB_TRANSFER_INTERRUPT, call);
    280275                break;
    281276
    282277        case IPC_M_USBVIRT_BULK_OUT:
    283                 ipc_data_out(dev, USB_TRANSFER_BULK, chandle, call);
    284                 break;
    285 
     278                ipc_data_out(dev, USB_TRANSFER_BULK, call);
     279                break;
    286280
    287281        default:
Note: See TracChangeset for help on using the changeset viewer.