MCPcopy Create free account
hub / github.com/coreboot/coreboot / do_alloc

Function do_alloc

src/lib/cbfs.c:464–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464static void *do_alloc(union cbfs_mdata *mdata, struct region_device *rdev,
465 cbfs_allocator_t allocator, void *arg, size_t *size_out,
466 bool skip_verification)
467{
468 size_t size = region_device_sz(rdev);
469 void *loc = NULL;
470
471 uint32_t compression = CBFS_COMPRESS_NONE;
472 const struct cbfs_file_attr_compression *cattr = cbfs_find_attr(mdata,
473 CBFS_FILE_ATTR_TAG_COMPRESSION, sizeof(*cattr));
474 if (cattr) {
475 compression = be32toh(cattr->compression);
476 size = be32toh(cattr->decompressed_size);
477 }
478
479 if (size_out)
480 *size_out = size;
481
482 /* allocator == NULL means do a cbfs_map() */
483 if (allocator) {
484 loc = allocator(arg, size, mdata);
485 } else if (compression == CBFS_COMPRESS_NONE) {
486 void *mapping = rdev_mmap_full(rdev);
487 if (!mapping)
488 return NULL;
489 if (cbfs_file_hash_mismatch(mapping, size, mdata, skip_verification)) {
490 rdev_munmap(rdev, mapping);
491 return NULL;
492 }
493 return mapping;
494 } else if (!cbfs_cache.size) {
495 /* In order to use the cbfs_cache you need to add a CBFS_CACHE to your
496 * memlayout. */
497 ERROR("Cannot map compressed file %s without cbfs_cache\n", mdata->h.filename);
498 return NULL;
499 } else {
500 loc = mem_pool_alloc(&cbfs_cache, size);
501 }
502
503 if (!loc) {
504 ERROR("'%s' allocation failure\n", mdata->h.filename);
505 return NULL;
506 }
507
508 size = cbfs_load_and_decompress(rdev, loc, size, compression, mdata, skip_verification);
509 if (!size)
510 return NULL;
511
512 return loc;
513}
514
515static enum cb_err check_or_query_type(const union cbfs_mdata *mdata, enum cbfs_type *type)
516{

Callers 2

_cbfs_allocFunction · 0.85

Calls 7

region_device_szFunction · 0.85
rdev_mmap_fullFunction · 0.85
rdev_munmapFunction · 0.85
cbfs_file_hash_mismatchFunction · 0.70
cbfs_load_and_decompressFunction · 0.70
cbfs_find_attrFunction · 0.50
mem_pool_allocFunction · 0.50

Tested by

no test coverage detected