Changeset 827d73f in mainline for uspace/srv/loader/main.c


Ignore:
Timestamp:
2010-02-12T14:09:22Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a70bda4
Parents:
918e9910 (diff), e70edd1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged the actual head

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loader/main.c

    r918e9910 r827d73f  
    125125static void ldr_set_cwd(ipc_callid_t rid, ipc_call_t *request)
    126126{
    127         ipc_callid_t callid;
    128         size_t len;
    129        
    130         if (!async_data_write_receive(&callid, &len)) {
    131                 ipc_answer_0(callid, EINVAL);
    132                 ipc_answer_0(rid, EINVAL);
    133                 return;
    134         }
    135        
    136         cwd = malloc(len + 1);
    137         if (!cwd) {
    138                 ipc_answer_0(callid, ENOMEM);
    139                 ipc_answer_0(rid, ENOMEM);
    140                 return;
    141         }
    142        
    143         async_data_write_finalize(callid, cwd, len);
    144         cwd[len] = '\0';
    145        
    146         ipc_answer_0(rid, EOK);
     127        char *buf;
     128        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
     129       
     130        if (rc == EOK) {
     131                if (cwd != NULL)
     132                        free(cwd);
     133               
     134                cwd = buf;
     135        }
     136       
     137        ipc_answer_0(rid, rc);
    147138}
    148139
     
    154145static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request)
    155146{
    156         ipc_callid_t callid;
    157         size_t len;
    158         char *name_buf;
    159        
    160         if (!async_data_write_receive(&callid, &len)) {
    161                 ipc_answer_0(callid, EINVAL);
    162                 ipc_answer_0(rid, EINVAL);
    163                 return;
    164         }
    165        
    166         name_buf = malloc(len + 1);
    167         if (!name_buf) {
    168                 ipc_answer_0(callid, ENOMEM);
    169                 ipc_answer_0(rid, ENOMEM);
    170                 return;
    171         }
    172        
    173         async_data_write_finalize(callid, name_buf, len);
    174         ipc_answer_0(rid, EOK);
    175        
    176         if (pathname != NULL) {
    177                 free(pathname);
    178                 pathname = NULL;
    179         }
    180        
    181         name_buf[len] = '\0';
    182         pathname = name_buf;
     147        char *buf;
     148        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
     149       
     150        if (rc == EOK) {
     151                if (pathname != NULL)
     152                        free(pathname);
     153               
     154                pathname = buf;
     155        }
     156       
     157        ipc_answer_0(rid, rc);
    183158}
    184159
     
    190165static void ldr_set_args(ipc_callid_t rid, ipc_call_t *request)
    191166{
    192         ipc_callid_t callid;
    193         size_t buf_size, arg_size;
    194         char *p;
    195         int n;
    196        
    197         if (!async_data_write_receive(&callid, &buf_size)) {
    198                 ipc_answer_0(callid, EINVAL);
    199                 ipc_answer_0(rid, EINVAL);
    200                 return;
    201         }
    202        
    203         if (arg_buf != NULL) {
    204                 free(arg_buf);
    205                 arg_buf = NULL;
    206         }
    207        
    208         if (argv != NULL) {
    209                 free(argv);
    210                 argv = NULL;
    211         }
    212        
    213         arg_buf = malloc(buf_size + 1);
    214         if (!arg_buf) {
    215                 ipc_answer_0(callid, ENOMEM);
    216                 ipc_answer_0(rid, ENOMEM);
    217                 return;
    218         }
    219        
    220         async_data_write_finalize(callid, arg_buf, buf_size);
    221        
    222         arg_buf[buf_size] = '\0';
    223        
    224         /*
    225          * Count number of arguments
    226          */
    227         p = arg_buf;
    228         n = 0;
    229         while (p < arg_buf + buf_size) {
    230                 arg_size = str_size(p);
    231                 p = p + arg_size + 1;
    232                 ++n;
    233         }
    234        
    235         /* Allocate argv */
    236         argv = malloc((n + 1) * sizeof(char *));
    237        
    238         if (argv == NULL) {
    239                 free(arg_buf);
    240                 ipc_answer_0(rid, ENOMEM);
    241                 return;
    242         }
    243 
    244         /*
    245          * Fill argv with argument pointers
    246          */
    247         p = arg_buf;
    248         n = 0;
    249         while (p < arg_buf + buf_size) {
    250                 argv[n] = p;
    251                
    252                 arg_size = str_size(p);
    253                 p = p + arg_size + 1;
    254                 ++n;
    255         }
    256        
    257         argc = n;
    258         argv[n] = NULL;
    259 
    260         ipc_answer_0(rid, EOK);
     167        char *buf;
     168        size_t buf_size;
     169        int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, &buf_size);
     170       
     171        if (rc == EOK) {
     172                /*
     173                 * Count number of arguments
     174                 */
     175                char *cur = buf;
     176                int count = 0;
     177               
     178                while (cur < buf + buf_size) {
     179                        size_t arg_size = str_size(cur);
     180                        cur += arg_size + 1;
     181                        count++;
     182                }
     183               
     184                /*
     185                 * Allocate new argv
     186                 */
     187                char **_argv = (char **) malloc((count + 1) * sizeof(char *));
     188                if (_argv == NULL) {
     189                        free(buf);
     190                        ipc_answer_0(rid, ENOMEM);
     191                        return;
     192                }
     193               
     194                /*
     195                 * Fill the new argv with argument pointers
     196                 */
     197                cur = buf;
     198                count = 0;
     199                while (cur < buf + buf_size) {
     200                        _argv[count] = cur;
     201                       
     202                        size_t arg_size = str_size(cur);
     203                        cur += arg_size + 1;
     204                        count++;
     205                }
     206                _argv[count] = NULL;
     207               
     208                /*
     209                 * Copy temporary data to global variables
     210                 */
     211                if (arg_buf != NULL)
     212                        free(arg_buf);
     213               
     214                if (argv != NULL)
     215                        free(argv);
     216               
     217                argc = count;
     218                arg_buf = buf;
     219                argv = _argv;
     220        }
     221       
     222        ipc_answer_0(rid, rc);
    261223}
    262224
     
    268230static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    269231{
    270         ipc_callid_t callid;
     232        fdi_node_t *buf;
    271233        size_t buf_size;
    272         if (!async_data_write_receive(&callid, &buf_size)) {
    273                 ipc_answer_0(callid, EINVAL);
    274                 ipc_answer_0(rid, EINVAL);
    275                 return;
    276         }
    277        
    278         if ((buf_size % sizeof(fdi_node_t)) != 0) {
    279                 ipc_answer_0(callid, EINVAL);
    280                 ipc_answer_0(rid, EINVAL);
    281                 return;
    282         }
    283        
    284         if (fil_buf != NULL) {
    285                 free(fil_buf);
    286                 fil_buf = NULL;
    287         }
    288        
    289         if (filv != NULL) {
    290                 free(filv);
    291                 filv = NULL;
    292         }
    293        
    294         fil_buf = malloc(buf_size);
    295         if (!fil_buf) {
    296                 ipc_answer_0(callid, ENOMEM);
    297                 ipc_answer_0(rid, ENOMEM);
    298                 return;
    299         }
    300        
    301         async_data_write_finalize(callid, fil_buf, buf_size);
    302        
    303         int count = buf_size / sizeof(fdi_node_t);
    304        
    305         /* Allocate filvv */
    306         filv = malloc((count + 1) * sizeof(fdi_node_t *));
    307        
    308         if (filv == NULL) {
    309                 free(fil_buf);
    310                 ipc_answer_0(rid, ENOMEM);
    311                 return;
    312         }
    313        
    314         /*
    315          * Fill filv with argument pointers
    316          */
    317         int i;
    318         for (i = 0; i < count; i++)
    319                 filv[i] = &fil_buf[i];
    320        
    321         filc = count;
    322         filv[count] = NULL;
     234        int rc = async_data_write_accept((void **) &buf, false, 0, 0,
     235            sizeof(fdi_node_t), &buf_size);
     236       
     237        if (rc == EOK) {
     238                int count = buf_size / sizeof(fdi_node_t);
     239               
     240                /*
     241                 * Allocate new filv
     242                 */
     243                fdi_node_t **_filv = (fdi_node_t **) calloc(count + 1, sizeof(fdi_node_t *));
     244                if (_filv == NULL) {
     245                        free(buf);
     246                        ipc_answer_0(rid, ENOMEM);
     247                        return;
     248                }
     249               
     250                /*
     251                 * Fill the new filv with argument pointers
     252                 */
     253                int i;
     254                for (i = 0; i < count; i++)
     255                        _filv[i] = &buf[i];
     256               
     257                _filv[count] = NULL;
     258               
     259                /*
     260                 * Copy temporary data to global variables
     261                 */
     262                if (fil_buf != NULL)
     263                        free(fil_buf);
     264               
     265                if (filv != NULL)
     266                        free(filv);
     267               
     268                filc = count;
     269                fil_buf = buf;
     270                filv = _filv;
     271        }
    323272       
    324273        ipc_answer_0(rid, EOK);
     
    392341                /* Dynamically linked program */
    393342                DPRINTF("Run ELF interpreter.\n");
    394                 DPRINTF("Entry point: 0x%lx\n", interp_info.entry);
     343                DPRINTF("Entry point: %p\n", interp_info.entry);
    395344               
    396345                ipc_answer_0(rid, EOK);
Note: See TracChangeset for help on using the changeset viewer.