Пример #1
0
process_t* load(char* executable)
{
	FILE* binary;
	process_t* process;
	binary_header_t header;
	int bytes_read;
	
	binary = open_binary(executable);
	ensure_valid_binary(binary, executable);
	header = read_header(binary);
	
	process = (process_t*)calloc(1, sizeof(process_t));
	bytes_read = fread(process->ram.bytes, sizeof(char), header.size, binary);
	
	if (bytes_read != header.size)
	{
		fprintf(stderr, "Executable header reports an invalid size.\n");
		free(process);
		exit(ERROR_INVALID_HEADER);
	}
	
	process->entry_point = header.entry_point;
	process->size = header.size;
	
	fclose(binary);
	return process;
}
Пример #2
0
/* Search 'filename' for an embedded core.  An SBCL core has, at the
 * end of the file, a trailer containing optional saved runtime
 * options, the start of the core (an os_vm_offset_t), and a final
 * signature word (the lispobj CORE_MAGIC).  If this trailer is found
 * at the end of the file, the start of the core can be determined
 * from the core size.
 *
 * If an embedded core is present, this returns the offset into the
 * file to load the core from, or -1 if no core is present. */
os_vm_offset_t
search_for_embedded_core(char *filename)
{
    lispobj header;
    os_vm_offset_t lispobj_size = sizeof(lispobj);
    os_vm_offset_t trailer_size = lispobj_size + sizeof(os_vm_offset_t);
    os_vm_offset_t core_start, pos;
    int fd = -1;

    if ((fd = open_binary(filename, O_RDONLY)) < 0)
        goto lose;

    if (read(fd, &header, (size_t)lispobj_size) < lispobj_size)
        goto lose;
    if (header == CORE_MAGIC) {
        /* This file is a real core, not an embedded core.  Return 0 to
         * indicate where the core starts, and do not look for runtime
         * options in this case. */
        return 0;
    }

    if (lseek(fd, -lispobj_size, SEEK_END) < 0)
        goto lose;
    if (read(fd, &header, (size_t)lispobj_size) < lispobj_size)
        goto lose;

    if (header == CORE_MAGIC) {
        if (lseek(fd, -trailer_size, SEEK_END) < 0)
            goto lose;
        if (read(fd, &core_start, sizeof(os_vm_offset_t)) < 0)
            goto lose;

        if (lseek(fd, core_start, SEEK_SET) < 0)
            goto lose;
        pos = lseek(fd, 0, SEEK_CUR);

        if (read(fd, &header, (size_t)lispobj_size) < lispobj_size)
            goto lose;

        if (header != CORE_MAGIC)
            goto lose;

        maybe_initialize_runtime_options(fd);

        close(fd);
        return pos;
    }

lose:
    if (fd != -1)
        close(fd);

    return -1;
}
Пример #3
0
int			main(int ac, char **av)
{
	t_bin			binary;
	t_arg_nm		options;
	t_filelst		*file;
	size_t			count;

	if (get_args_nm(ac, av, &options))
		return (1);
	file = options.files;
	count = files_list_count(options.files);
	while (file)
	{
		if (!open_binary(file->name, &binary))
		{
			nm(file->name, &options, &binary, count);
			if (close_binary(file->name, &binary))
				return (2);
		}
		file = file->next;
	}
	files_list_del(&options.files);
	return (0);
}