>>> libhardware/include/hardware/hardware.h /* * The current HAL API version. * * All module implementations must set the hw_module_t.hal_api_version field * to this value when declaring the module with HAL_MODULE_INFO_SYM. * * Note that previous implementations have always set this field to 0. * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0 * to be 100% binary compatible. * */ #define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
/** * Name of the hal_module_info */ #define HAL_MODULE_INFO_SYM HMI
/** * Name of the hal_module_info as a string */ #define HAL_MODULE_INFO_SYM_AS_STR "HMI"
/** * Get the module info associated with a module by id. * * @return: 0 == success, <0 == error and *module == NULL */ inthw_get_module(constchar *id, conststructhw_module_t **module);
/** Base path of the hal modules */ #if defined(__LP64__) #define HAL_LIBRARY_PATH1 "/system/lib64/hw" #define HAL_LIBRARY_PATH2 "/vendor/lib64/hw" #define HAL_LIBRARY_PATH3 "/odm/lib64/hw" #else #define HAL_LIBRARY_PATH1 "/system/lib/hw" #define HAL_LIBRARY_PATH2 "/vendor/lib/hw" #define HAL_LIBRARY_PATH3 "/odm/lib/hw" #endif
staticconstchar *variant_keys[] = { "ro.hardware", /* This goes first so that it can pick up a different file on the emulator. */ "ro.product.board", "ro.board.platform", "ro.arch" };
/** * Load the file defined by the variant and if successful * return the dlopen handle and the hmi. * @return 0 = success, !0 = failure. */ staticintload(constchar *id, constchar *path, conststructhw_module_t **pHmi) { int status = -EINVAL; void *handle = NULL; structhw_module_t *hmi = NULL;
handle = dlopen(path, RTLD_NOW);
/* Get the address of the struct hal_module_info. */ constchar *sym = HAL_MODULE_INFO_SYM_AS_STR; hmi = (structhw_module_t *)dlsym(handle, sym);
/* Check that the id matches */ if (strcmp(id, hmi->id) != 0) { ALOGE("load: id=%s != hmi->id=%s", id, hmi->id); status = -EINVAL; goto done; }
/** * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM * and the fields of this data structure must begin with hw_module_t * followed by module specific information. */ typedefstructgralloc_module_t { structhw_module_t common; ...