Changeset 984a9ba in mainline for uspace/srv/loader/main.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/srv/loader/main.c

    r76f566d r984a9ba  
    9090static bool connected = false;
    9191
    92 static void ldr_get_taskid(cap_call_handle_t req_handle, ipc_call_t *request)
    93 {
    94         cap_call_handle_t chandle;
     92static void ldr_get_taskid(ipc_call_t *req)
     93{
     94        ipc_call_t call;
    9595        task_id_t task_id;
    9696        size_t len;
     
    9898        task_id = task_get_id();
    9999
    100         if (!async_data_read_receive(&chandle, &len)) {
    101                 async_answer_0(chandle, EINVAL);
    102                 async_answer_0(req_handle, EINVAL);
     100        if (!async_data_read_receive(&call, &len)) {
     101                async_answer_0(&call, EINVAL);
     102                async_answer_0(req, EINVAL);
    103103                return;
    104104        }
     
    107107                len = sizeof(task_id);
    108108
    109         async_data_read_finalize(chandle, &task_id, len);
    110         async_answer_0(req_handle, EOK);
     109        async_data_read_finalize(&call, &task_id, len);
     110        async_answer_0(req, EOK);
    111111}
    112112
    113113/** Receive a call setting the current working directory.
    114114 *
    115  * @param req_handle
    116  * @param request
    117  */
    118 static void ldr_set_cwd(cap_call_handle_t req_handle, ipc_call_t *request)
     115 */
     116static void ldr_set_cwd(ipc_call_t *req)
    119117{
    120118        char *buf;
     
    128126        }
    129127
    130         async_answer_0(req_handle, rc);
     128        async_answer_0(req, rc);
    131129}
    132130
    133131/** Receive a call setting the program to execute.
    134132 *
    135  * @param req_handle
    136  * @param request
    137  */
    138 static void ldr_set_program(cap_call_handle_t req_handle, ipc_call_t *request)
    139 {
    140         cap_call_handle_t write_chandle;
     133 */
     134static void ldr_set_program(ipc_call_t *req)
     135{
     136        ipc_call_t call;
    141137        size_t namesize;
    142         if (!async_data_write_receive(&write_chandle, &namesize)) {
    143                 async_answer_0(req_handle, EINVAL);
     138        if (!async_data_write_receive(&call, &namesize)) {
     139                async_answer_0(req, EINVAL);
    144140                return;
    145141        }
    146142
    147143        char *name = malloc(namesize);
    148         errno_t rc = async_data_write_finalize(write_chandle, name, namesize);
     144        // FIXME: check return value
     145
     146        errno_t rc = async_data_write_finalize(&call, name, namesize);
    149147        if (rc != EOK) {
    150                 async_answer_0(req_handle, EINVAL);
     148                async_answer_0(req, EINVAL);
    151149                return;
    152150        }
     
    155153        rc = vfs_receive_handle(true, &file);
    156154        if (rc != EOK) {
    157                 async_answer_0(req_handle, EINVAL);
     155                async_answer_0(req, EINVAL);
    158156                return;
    159157        }
     
    161159        progname = name;
    162160        program_fd = file;
    163         async_answer_0(req_handle, EOK);
     161        async_answer_0(req, EOK);
    164162}
    165163
    166164/** Receive a call setting arguments of the program to execute.
    167165 *
    168  * @param req_handle
    169  * @param request
    170  */
    171 static void ldr_set_args(cap_call_handle_t req_handle, ipc_call_t *request)
     166 */
     167static void ldr_set_args(ipc_call_t *req)
    172168{
    173169        char *buf;
     
    194190                if (_argv == NULL) {
    195191                        free(buf);
    196                         async_answer_0(req_handle, ENOMEM);
     192                        async_answer_0(req, ENOMEM);
    197193                        return;
    198194                }
     
    226222        }
    227223
    228         async_answer_0(req_handle, rc);
     224        async_answer_0(req, rc);
    229225}
    230226
    231227/** Receive a call setting inbox files of the program to execute.
    232228 *
    233  * @param req_handle
    234  * @param request
    235  */
    236 static void ldr_add_inbox(cap_call_handle_t req_handle, ipc_call_t *request)
     229 */
     230static void ldr_add_inbox(ipc_call_t *req)
    237231{
    238232        if (inbox_entries == INBOX_MAX_ENTRIES) {
    239                 async_answer_0(req_handle, ERANGE);
    240                 return;
    241         }
    242 
    243         cap_call_handle_t write_chandle;
     233                async_answer_0(req, ERANGE);
     234                return;
     235        }
     236
     237        ipc_call_t call;
    244238        size_t namesize;
    245         if (!async_data_write_receive(&write_chandle, &namesize)) {
    246                 async_answer_0(req_handle, EINVAL);
     239        if (!async_data_write_receive(&call, &namesize)) {
     240                async_answer_0(req, EINVAL);
    247241                return;
    248242        }
    249243
    250244        char *name = malloc(namesize);
    251         errno_t rc = async_data_write_finalize(write_chandle, name, namesize);
     245        errno_t rc = async_data_write_finalize(&call, name, namesize);
    252246        if (rc != EOK) {
    253                 async_answer_0(req_handle, EINVAL);
     247                async_answer_0(req, EINVAL);
    254248                return;
    255249        }
     
    258252        rc = vfs_receive_handle(true, &file);
    259253        if (rc != EOK) {
    260                 async_answer_0(req_handle, EINVAL);
     254                async_answer_0(req, EINVAL);
    261255                return;
    262256        }
     
    272266        inbox[inbox_entries].file = file;
    273267        inbox_entries++;
    274         async_answer_0(req_handle, EOK);
     268        async_answer_0(req, EOK);
    275269}
    276270
    277271/** Load the previously selected program.
    278272 *
    279  * @param req_handle
    280  * @param request
    281273 * @return 0 on success, !0 on error.
    282  */
    283 static int ldr_load(cap_call_handle_t req_handle, ipc_call_t *request)
     274 *
     275 */
     276static int ldr_load(ipc_call_t *req)
    284277{
    285278        int rc = elf_load(program_fd, &prog_info);
    286279        if (rc != EE_OK) {
    287280                DPRINTF("Failed to load executable for '%s'.\n", progname);
    288                 async_answer_0(req_handle, EINVAL);
     281                async_answer_0(req, EINVAL);
    289282                return 1;
    290283        }
     
    300293        pcb.inbox_entries = inbox_entries;
    301294
    302         async_answer_0(req_handle, EOK);
     295        async_answer_0(req, EOK);
    303296        return 0;
    304297}
     
    306299/** Run the previously loaded program.
    307300 *
    308  * @param req_handle
    309  * @param request
    310301 * @return 0 on success, !0 on error.
    311  */
    312 static __attribute__((noreturn)) void ldr_run(cap_call_handle_t req_handle,
    313     ipc_call_t *request)
     302 *
     303 */
     304static __attribute__((noreturn)) void ldr_run(ipc_call_t *req)
    314305{
    315306        DPRINTF("Set task name\n");
     
    320311        /* Run program */
    321312        DPRINTF("Reply OK\n");
    322         async_answer_0(req_handle, EOK);
     313        async_answer_0(req, EOK);
    323314        DPRINTF("Jump to entry point at %p\n", pcb.entry);
    324315        entry_point_jmp(prog_info.finfo.entry, &pcb);
     
    331322 * Receive and carry out commands (of which the last one should be
    332323 * to execute the loaded program).
    333  */
    334 static void ldr_connection(cap_call_handle_t icall_handle, ipc_call_t *icall,
    335     void *arg)
     324 *
     325 */
     326static void ldr_connection(ipc_call_t *icall, void *arg)
    336327{
    337328        /* Already have a connection? */
    338329        if (connected) {
    339                 async_answer_0(icall_handle, ELIMIT);
     330                async_answer_0(icall, ELIMIT);
    340331                return;
    341332        }
     
    344335
    345336        /* Accept the connection */
    346         async_answer_0(icall_handle, EOK);
     337        async_answer_0(icall, EOK);
    347338
    348339        /* Ignore parameters, the connection is already open */
     
    352343                errno_t retval;
    353344                ipc_call_t call;
    354                 cap_call_handle_t chandle = async_get_call(&call);
     345                async_get_call(&call);
    355346
    356347                if (!IPC_GET_IMETHOD(call))
     
    359350                switch (IPC_GET_IMETHOD(call)) {
    360351                case LOADER_GET_TASKID:
    361                         ldr_get_taskid(chandle, &call);
     352                        ldr_get_taskid(&call);
    362353                        continue;
    363354                case LOADER_SET_CWD:
    364                         ldr_set_cwd(chandle, &call);
     355                        ldr_set_cwd(&call);
    365356                        continue;
    366357                case LOADER_SET_PROGRAM:
    367                         ldr_set_program(chandle, &call);
     358                        ldr_set_program(&call);
    368359                        continue;
    369360                case LOADER_SET_ARGS:
    370                         ldr_set_args(chandle, &call);
     361                        ldr_set_args(&call);
    371362                        continue;
    372363                case LOADER_ADD_INBOX:
    373                         ldr_add_inbox(chandle, &call);
     364                        ldr_add_inbox(&call);
    374365                        continue;
    375366                case LOADER_LOAD:
    376                         ldr_load(chandle, &call);
     367                        ldr_load(&call);
    377368                        continue;
    378369                case LOADER_RUN:
    379                         ldr_run(chandle, &call);
     370                        ldr_run(&call);
    380371                        /* Not reached */
    381372                default:
     
    384375                }
    385376
    386                 async_answer_0(chandle, retval);
     377                async_answer_0(&call, retval);
    387378        }
    388379}
Note: See TracChangeset for help on using the changeset viewer.