int FAST_FUNC bb_init_module(const char *filename, const char *options) { size_t len; char *image; int rc; if (!options) options = ""; #if ENABLE_FEATURE_2_4_MODULES if (get_linux_version_code() < KERNEL_VERSION(2,6,0)) return bb_init_module_24(filename, options); #endif /* Use the 2.6 way */ len = INT_MAX - 4095; rc = ENOENT; image = xmalloc_open_zipped_read_close(filename, &len); if (image) { rc = 0; if (init_module(image, len, options) != 0) rc = errno; free(image); } return rc; }
/* Return: * 0 on success, * -errno on open/read error, * errno on init_module() error */ int FAST_FUNC bb_init_module(const char *filename, const char *options) { size_t image_size; char *image; int rc; bool mmaped; if (!options) options = ""; //TODO: audit bb_init_module_24 to match error code convention #if ENABLE_FEATURE_2_4_MODULES if (get_linux_version_code() < KERNEL_VERSION(2,6,0)) return bb_init_module_24(filename, options); #endif image_size = INT_MAX - 4095; mmaped = 0; image = try_to_mmap_module(filename, &image_size); if (image) { mmaped = 1; } else { errno = ENOMEM; /* may be changed by e.g. open errors below */ image = xmalloc_open_zipped_read_close(filename, &image_size); if (!image) return -errno; } errno = 0; init_module(image, image_size, options); rc = errno; if (mmaped) munmap(image, image_size); else free(image); return rc; }