Changeset 79ae36dd in mainline for uspace/lib/c/generic/loader.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loader.c

    r764d71e r79ae36dd  
    3535#include <ipc/loader.h>
    3636#include <ipc/services.h>
    37 #include <ipc/ns.h>
     37#include <ns.h>
    3838#include <libc.h>
    3939#include <task.h>
     
    4444#include <vfs/vfs.h>
    4545#include <loader/loader.h>
     46#include "private/loader.h"
    4647
    4748/** Connect to a new program loader.
     
    6364loader_t *loader_connect(void)
    6465{
    65         int phone_id = service_connect_blocking(SERVICE_LOAD, 0, 0);
    66         if (phone_id < 0)
    67                 return NULL;
    68        
    6966        loader_t *ldr = malloc(sizeof(loader_t));
    7067        if (ldr == NULL)
    7168                return NULL;
    7269       
    73         ldr->phone_id = phone_id;
     70        async_sess_t *sess =
     71            service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOAD, 0, 0);
     72        if (sess == NULL) {
     73                free(ldr);
     74                return NULL;
     75        }
     76       
     77        ldr->sess = sess;
    7478        return ldr;
    7579}
     
    8892{
    8993        /* Get task ID. */
    90         ipc_call_t answer;
    91         aid_t req = async_send_0(ldr->phone_id, LOADER_GET_TASKID, &answer);
    92         int rc = async_data_read_start(ldr->phone_id, task_id, sizeof(task_id_t));
    93         if (rc != EOK) {
    94                 async_wait_for(req, NULL);
    95                 return rc;
    96         }
    97        
    98         sysarg_t retval;
    99         async_wait_for(req, &retval);
    100         return (int) retval;
     94        async_exch_t *exch = async_exchange_begin(ldr->sess);
     95       
     96        ipc_call_t answer;
     97        aid_t req = async_send_0(exch, LOADER_GET_TASKID, &answer);
     98        sysarg_t rc = async_data_read_start(exch, task_id, sizeof(task_id_t));
     99       
     100        async_exchange_end(exch);
     101       
     102        if (rc != EOK) {
     103                async_wait_for(req, NULL);
     104                return (int) rc;
     105        }
     106       
     107        async_wait_for(req, &rc);
     108        return (int) rc;
    101109}
    102110
     
    112120int loader_set_cwd(loader_t *ldr)
    113121{
    114         char *cwd;
    115         size_t len;
    116 
    117         cwd = (char *) malloc(MAX_PATH_LEN + 1);
     122        char *cwd = (char *) malloc(MAX_PATH_LEN + 1);
    118123        if (!cwd)
    119124                return ENOMEM;
     125       
    120126        if (!getcwd(cwd, MAX_PATH_LEN + 1))
    121                 str_cpy(cwd, MAX_PATH_LEN + 1, "/");
    122         len = str_length(cwd);
    123        
    124         ipc_call_t answer;
    125         aid_t req = async_send_0(ldr->phone_id, LOADER_SET_CWD, &answer);
    126         int rc = async_data_write_start(ldr->phone_id, cwd, len);
     127                str_cpy(cwd, MAX_PATH_LEN + 1, "/");
     128       
     129        size_t len = str_length(cwd);
     130       
     131        async_exch_t *exch = async_exchange_begin(ldr->sess);
     132       
     133        ipc_call_t answer;
     134        aid_t req = async_send_0(exch, LOADER_SET_CWD, &answer);
     135        sysarg_t rc = async_data_write_start(exch, cwd, len);
     136       
     137        async_exchange_end(exch);
    127138        free(cwd);
    128         if (rc != EOK) {
    129                 async_wait_for(req, NULL);
    130                 return rc;
    131         }
    132        
    133         sysarg_t retval;
    134         async_wait_for(req, &retval);
    135         return (int) retval;
     139       
     140        if (rc != EOK) {
     141                async_wait_for(req, NULL);
     142                return (int) rc;
     143        }
     144       
     145        async_wait_for(req, &rc);
     146        return (int) rc;
    136147}
    137148
     
    153164        char *pa = absolutize(path, &pa_len);
    154165        if (!pa)
    155                 return 0;
     166                return ENOMEM;
    156167       
    157168        /* Send program pathname */
    158         ipc_call_t answer;
    159         aid_t req = async_send_0(ldr->phone_id, LOADER_SET_PATHNAME, &answer);
    160         int rc = async_data_write_start(ldr->phone_id, (void *) pa, pa_len);
    161         if (rc != EOK) {
    162                 free(pa);
    163                 async_wait_for(req, NULL);
    164                 return rc;
    165         }
    166        
     169        async_exch_t *exch = async_exchange_begin(ldr->sess);
     170       
     171        ipc_call_t answer;
     172        aid_t req = async_send_0(exch, LOADER_SET_PATHNAME, &answer);
     173        sysarg_t rc = async_data_write_start(exch, (void *) pa, pa_len);
     174       
     175        async_exchange_end(exch);
    167176        free(pa);
    168177       
    169         sysarg_t retval;
    170         async_wait_for(req, &retval);
    171         return (int) retval;
     178        if (rc != EOK) {
     179                async_wait_for(req, NULL);
     180                return (int) rc;
     181        }
     182       
     183        async_wait_for(req, &rc);
     184        return (int) rc;
    172185}
    173186
     
    212225       
    213226        /* Send serialized arguments to the loader */
    214         ipc_call_t answer;
    215         aid_t req = async_send_0(ldr->phone_id, LOADER_SET_ARGS, &answer);
    216         sysarg_t rc = async_data_write_start(ldr->phone_id, (void *) arg_buf, buffer_size);
    217         if (rc != EOK) {
    218                 async_wait_for(req, NULL);
    219                 return rc;
    220         }
    221        
    222         async_wait_for(req, &rc);
    223         if (rc != EOK)
    224                 return rc;
    225        
    226         /* Free temporary buffer */
     227        async_exch_t *exch = async_exchange_begin(ldr->sess);
     228       
     229        ipc_call_t answer;
     230        aid_t req = async_send_0(exch, LOADER_SET_ARGS, &answer);
     231        sysarg_t rc = async_data_write_start(exch, (void *) arg_buf,
     232            buffer_size);
     233       
     234        async_exchange_end(exch);
    227235        free(arg_buf);
    228236       
    229         return EOK;
     237        if (rc != EOK) {
     238                async_wait_for(req, NULL);
     239                return (int) rc;
     240        }
     241       
     242        async_wait_for(req, &rc);
     243        return (int) rc;
    230244}
    231245
     
    266280       
    267281        /* Send serialized files to the loader */
    268         ipc_call_t answer;
    269         aid_t req = async_send_0(ldr->phone_id, LOADER_SET_FILES, &answer);
    270         sysarg_t rc = async_data_write_start(ldr->phone_id, (void *) files_buf,
     282        async_exch_t *exch = async_exchange_begin(ldr->sess);
     283       
     284        ipc_call_t answer;
     285        aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer);
     286        sysarg_t rc = async_data_write_start(exch, (void *) files_buf,
    271287            count * sizeof(fdi_node_t));
    272         if (rc != EOK) {
    273                 async_wait_for(req, NULL);
    274                 return rc;
    275         }
    276        
    277         async_wait_for(req, &rc);
    278         if (rc != EOK)
    279                 return rc;
    280        
    281         /* Free temporary buffer */
     288       
     289        async_exchange_end(exch);
    282290        free(files_buf);
    283291       
    284         return EOK;
     292        if (rc != EOK) {
     293                async_wait_for(req, NULL);
     294                return (int) rc;
     295        }
     296       
     297        async_wait_for(req, &rc);
     298        return (int) rc;
    285299}
    286300
     
    297311int loader_load_program(loader_t *ldr)
    298312{
    299         return (int) async_req_0_0(ldr->phone_id, LOADER_LOAD);
     313        async_exch_t *exch = async_exchange_begin(ldr->sess);
     314        int rc = async_req_0_0(exch, LOADER_LOAD);
     315        async_exchange_end(exch);
     316       
     317        return rc;
    300318}
    301319
     
    306324 * the task and its thread is stopped.
    307325 *
    308  * After using this function, no further operations must be performed
    309  * on the loader structure. It should be de-allocated using free().
     326 * After using this function, no further operations can be performed
     327 * on the loader structure and it is deallocated.
    310328 *
    311329 * @param ldr Loader connection structure.
     
    316334int loader_run(loader_t *ldr)
    317335{
    318         int rc = async_req_0_0(ldr->phone_id, LOADER_RUN);
     336        async_exch_t *exch = async_exchange_begin(ldr->sess);
     337        int rc = async_req_0_0(exch, LOADER_RUN);
     338        async_exchange_end(exch);
     339       
    319340        if (rc != EOK)
    320341                return rc;
    321342       
    322         async_hangup(ldr->phone_id);
    323         ldr->phone_id = 0;
     343        async_hangup(ldr->sess);
     344        free(ldr);
     345       
    324346        return EOK;
    325347}
     
    327349/** Cancel the loader session.
    328350 *
    329  * Tells the loader not to load any program and terminate.
    330  * After using this function, no further operations must be performed
    331  * on the loader structure. It should be de-allocated using free().
     351 * Tell the loader not to load any program and terminate.
     352 * After using this function, no further operations can be performed
     353 * on the loader structure and it is deallocated.
    332354 *
    333355 * @param ldr Loader connection structure.
     
    338360void loader_abort(loader_t *ldr)
    339361{
    340         async_hangup(ldr->phone_id);
    341         ldr->phone_id = 0;
     362        async_hangup(ldr->sess);
     363        free(ldr);
    342364}
    343365
Note: See TracChangeset for help on using the changeset viewer.