Пример #1
0
int main( int argc, char** argv )
{
  struct cell *cells_local[N];
  int arg;
  size_t i;
  struct pool *p      = allocate_pool();
  struct cell **cells = static_roots ? cells_static : cells_local;

  assert(argc == 2);
  assert(argv[1]);
  assert(strlen(argv[1]) == 1);
  assert(argv[1][0] >= '0' && argv[1][0] <= '5');
  arg = atoi( argv[1] );
  set_flags( arg );

  memset(cells_static, 0, sizeof(cells_static));
  memset(cells_local,  0, sizeof(cells_local));

  for (i = 0; i < N; ++i) {
    cells[i] = allocate_from_pool(p, sizeof(struct cell));  
  }

  if (trim_pool)
  VALGRIND_MEMPOOL_TRIM(p, 
			p->buf+(10 * sizeof(struct cell)), 
			20 * sizeof(struct cell) + 2);

  if (destroy_pool)
  VALGRIND_DESTROY_MEMPOOL(p);

  return 0;
}
Пример #2
0
struct pool *get_pool(size_t size)
{
	static char allocation_log[numpools];
	char hit = allocation_log[size];

	debug("GET", "fetching pool for size %d (%s)", size, hit ? "found" : "not allocated");

	// allocate new pool if necessary
	if (!hit)
	{
		struct pool *p = allocate_pool(size);
		pools[size] = p;
		allocation_log[size] = 1;
	}

	return pools[size];
}
/**
 * memory_map - Allocate and fill out an array of memory descriptors
 * @map_buf: buffer containing the memory map
 * @map_size: size of the buffer containing the memory map
 * @map_key: key for the current memory map
 * @desc_size: size of the desc
 * @desc_version: memory descriptor version
 *
 * On success, @map_size contains the size of the memory map pointed
 * to by @map_buf and @map_key, @desc_size and @desc_version are
 * updated.
 */
EFI_STATUS
memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size,
           UINTN *map_key, UINTN *desc_size, UINT32 *desc_version)
{
        EFI_STATUS err;

        *map_size = sizeof(**map_buf) * 31;
get_map:

        /*
         * Because we're about to allocate memory, we may
         * potentially create a new memory descriptor, thereby
         * increasing the size of the memory map. So increase
         * the buffer size by the size of one memory
         * descriptor, just in case.
         */
        *map_size += sizeof(**map_buf);

        err = allocate_pool(EfiLoaderData, *map_size,
                            (void **)map_buf);
        if (err != EFI_SUCCESS) {
                error(L"Failed to allocate pool for memory map");
                goto failed;
        }

        err = get_memory_map(map_size, *map_buf, map_key,
                             desc_size, desc_version);
        if (err != EFI_SUCCESS) {
                if (err == EFI_BUFFER_TOO_SMALL) {
                        /*
                         * 'map_size' has been updated to reflect the
                         * required size of a map buffer.
                         */
                        free_pool((void *)*map_buf);
                        goto get_map;
                }

                error(L"Failed to get memory map");
                goto failed;
        }

failed:
        return err;
}
Пример #4
0
/**
 * efi_main - The entry point for the OS loader image.
 * @image: firmware-allocated handle that identifies the image
 * @sys_table: EFI system table
 */
EFI_STATUS
efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
{
	WCHAR *error_buf;
	EFI_STATUS err;
	EFI_LOADED_IMAGE *info;
	CHAR16 *name, *options;
	UINT32 options_size;
	char *cmdline;

	InitializeLib(image, _table);
	sys_table = _table;
	boot = sys_table->BootServices;
	runtime = sys_table->RuntimeServices;

	if (CheckCrc(sys_table->Hdr.HeaderSize, &sys_table->Hdr) != TRUE)
		return EFI_LOAD_ERROR;

	Print(banner, EFILINUX_VERSION_MAJOR, EFILINUX_VERSION_MINOR);

	err = fs_init();
	if (err != EFI_SUCCESS)
		goto failed;

	err = handle_protocol(image, &LoadedImageProtocol, (void **)&info);
	if (err != EFI_SUCCESS)
		goto fs_deinit;

	if (!read_config_file(info, &options, &options_size)) {
		int i;

		options = info->LoadOptions;
		options_size = info->LoadOptionsSize;

		/*
		 * Skip the first word, that's probably our name. Stop
		 * when we hit a word delimiter (' ') or the start of an
		 * efilinux argument ('-').
		 */
		i = 0;
		while (i < options_size) {
			if (options[i] == ' ' || options[i] == '-')
				break;
			i++;
		}

		options = &options[i];
		options_size -= i;
	}

	if (options && options_size != 0) {
		err = parse_args(options, options_size, &name, &cmdline);

		/* We print the usage message in case of invalid args */
		if (err == EFI_INVALID_PARAMETER) {
			fs_exit();
			return EFI_SUCCESS;
		}

		if (err != EFI_SUCCESS)
			goto fs_deinit;
	}

	err = load_image(image, name, cmdline);
	if (err != EFI_SUCCESS)
		goto free_args;

	return EFI_SUCCESS;

free_args:
	free(cmdline);
	free(name);
fs_deinit:
	fs_exit();
failed:
	/*
	 * We need to be careful not to trash 'err' here. If we fail
	 * to allocate enough memory to hold the error string fallback
	 * to returning 'err'.
	 */
	if (allocate_pool(EfiLoaderData, ERROR_STRING_LENGTH,
			  (void **)&error_buf) != EFI_SUCCESS) {
		Print(L"Couldn't allocate pages for error string\n");
		return err;
	}

	StatusToString(error_buf, err);
	Print(L": %s\n", error_buf);
	return exit(image, err, ERROR_STRING_LENGTH, error_buf);
}