Changeset bb9ec2d in mainline for uspace/srv/loader/main.c


Ignore:
Timestamp:
2017-03-07T20:47:35Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a737667e
Parents:
e796dc8
git-author:
Jiri Zarevucky <zarevucky.jiri@…> (2017-03-07 20:47:35)
git-committer:
Jakub Jermar <jakub@…> (2017-03-07 20:47:35)
Message:

Merge from lp:~zarevucky-jiri/helenos/vfs-2.5/ revision 1941-1944

Original commit messages:

1944: Jiri Zarevucky 2013-08-06 Replace legacy file descriptor presetting with inbox.
1943: Jiri Zarevucky 2013-08-06 Do not preserve open state when passing file descriptor to another task. Allow receiver to specify, whether the descriptor is low or high.
1942: Jiri Zarevucky 2013-08-06 C style.
1941: Jiri Zarevucky 2013-08-06 Make loader accept file reference instead of a pathname.

Modifications:

  • Keep version of elf_load_file() that accepts file name
  • Changes required for loading dynamically linked executables
  • Update to newer list_foreach
File:
1 edited

Legend:

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

    re796dc8 rbb9ec2d  
    6262#include <elf/elf_load.h>
    6363#include <vfs/vfs.h>
     64#include <vfs/inbox.h>
    6465
    6566#define DPRINTF(...)
    6667
    67 /** Pathname of the file that will be loaded */
    68 static char *pathname = NULL;
     68/** File that will be loaded */
     69static char *progname = NULL;
     70static int program_fd = -1;
    6971
    7072/** The Program control block */
     
    8183static char *arg_buf = NULL;
    8284
    83 /** Number of preset files */
    84 static unsigned int filc = 0;
     85/** Inbox entries. */
     86static struct pcb_inbox_entry inbox[INBOX_MAX_ENTRIES];
     87static int inbox_entries = 0;
    8588
    8689static elf_info_t prog_info;
     
    130133}
    131134
    132 /** Receive a call setting pathname of the program to execute.
    133  *
    134  * @param rid
    135  * @param request
    136  */
    137 static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request)
    138 {
    139         char *buf;
    140         int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
    141        
    142         if (rc == EOK) {
    143                 if (pathname != NULL)
    144                         free(pathname);
    145                
    146                 pathname = buf;
    147         }
    148        
    149         async_answer_0(rid, rc);
     135/** Receive a call setting the program to execute.
     136 *
     137 * @param rid
     138 * @param request
     139 */
     140static void ldr_set_program(ipc_callid_t rid, ipc_call_t *request)
     141{
     142        ipc_callid_t writeid;
     143        size_t namesize;
     144        if (!async_data_write_receive(&writeid, &namesize)) {
     145                async_answer_0(rid, EINVAL);
     146                return;
     147        }
     148
     149        char* name = malloc(namesize);
     150        int rc = async_data_write_finalize(writeid, name, namesize);
     151        if (rc != EOK) {
     152                async_answer_0(rid, EINVAL);
     153                return;
     154        }
     155
     156        int file = vfs_receive_handle(true);
     157        if (file < 0) {
     158                async_answer_0(rid, EINVAL);
     159                return;
     160        }
     161       
     162        progname = name;
     163        program_fd = file;
     164        async_answer_0(rid, EOK);
    150165}
    151166
     
    215230}
    216231
    217 /** Receive a call setting preset files of the program to execute.
    218  *
    219  * @param rid
    220  * @param request
    221  */
    222 static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    223 {
    224         size_t count = IPC_GET_ARG1(*request);
    225 
    226         for (filc = 0; filc < count; filc++) {
    227                 int fd = vfs_receive_handle();
    228                 if (fd < 0) {
    229                         break;
    230                 }
    231                 assert(fd == (int) filc);
    232         }
    233 
     232/** Receive a call setting inbox files of the program to execute.
     233 *
     234 * @param rid
     235 * @param request
     236 */
     237static void ldr_add_inbox(ipc_callid_t rid, ipc_call_t *request)
     238{
     239        if (inbox_entries == INBOX_MAX_ENTRIES) {
     240                async_answer_0(rid, ERANGE);
     241        }
     242
     243        ipc_callid_t writeid;
     244        size_t namesize;
     245        if (!async_data_write_receive(&writeid, &namesize)) {
     246                async_answer_0(rid, EINVAL);
     247                return;
     248        }
     249
     250        char* name = malloc(namesize);
     251        int rc = async_data_write_finalize(writeid, name, namesize);
     252        if (rc != EOK) {
     253                async_answer_0(rid, EINVAL);
     254                return;
     255        }
     256
     257        int file = vfs_receive_handle(true);
     258        if (file < 0) {
     259                async_answer_0(rid, EINVAL);
     260                return;
     261        }
     262
     263        inbox[inbox_entries].name = name;
     264        inbox[inbox_entries].file = file;
     265        inbox_entries++;
    234266        async_answer_0(rid, EOK);
    235267}
     
    243275static int ldr_load(ipc_callid_t rid, ipc_call_t *request)
    244276{
    245         int rc;
    246        
    247         rc = elf_load(pathname, &prog_info);
     277        int rc = elf_load(program_fd, &prog_info);
    248278        if (rc != EE_OK) {
    249                 DPRINTF("Failed to load executable '%s'.\n", pathname);
     279                DPRINTF("Failed to load executable for '%s'.\n", progname);
    250280                async_answer_0(rid, EINVAL);
    251281                return 1;
     
    259289        pcb.argv = argv;
    260290       
    261         pcb.filc = filc;
     291        pcb.inbox = inbox;
     292        pcb.inbox_entries = inbox_entries;
    262293       
    263294        async_answer_0(rid, rc);
     
    273304static void ldr_run(ipc_callid_t rid, ipc_call_t *request)
    274305{
    275         const char *cp;
    276        
    277306        DPRINTF("Set task name\n");
    278307
    279308        /* Set the task name. */
    280         cp = str_rchr(pathname, '/');
    281         cp = (cp == NULL) ? pathname : (cp + 1);
    282         task_set_name(cp);
     309        task_set_name(progname);
    283310       
    284311        /* Run program */
     
    327354                        ldr_set_cwd(callid, &call);
    328355                        continue;
    329                 case LOADER_SET_PATHNAME:
    330                         ldr_set_pathname(callid, &call);
     356                case LOADER_SET_PROGRAM:
     357                        ldr_set_program(callid, &call);
    331358                        continue;
    332359                case LOADER_SET_ARGS:
    333360                        ldr_set_args(callid, &call);
    334361                        continue;
    335                 case LOADER_SET_FILES:
    336                         ldr_set_files(callid, &call);
     362                case LOADER_ADD_INBOX:
     363                        ldr_add_inbox(callid, &call);
    337364                        continue;
    338365                case LOADER_LOAD:
Note: See TracChangeset for help on using the changeset viewer.