SWDEV-251091: Added null checks and empty file check in hip_module and hip_platform

Change-Id: Iad99f996dcf90ffb86f62e79bf4cbd53b35b7e3b
Dieser Commit ist enthalten in:
Sourabh Betigeri
2020-10-13 01:19:47 -07:00
committet von Sourabh Betigeri
Ursprung 4e96bfecd5
Commit b65314d168
4 geänderte Dateien mit 23 neuen und 4 gelöschten Zeilen
+5 -1
Datei anzeigen
@@ -11,7 +11,7 @@
namespace hip {
uint64_t CodeObject::ElfSize(const void *emi) {
return amd::Elf::getElfSize(emi);
return amd::Elf::getElfSize(emi);
}
bool CodeObject::isCompatibleCodeObject(const std::string& codeobj_target_id,
@@ -180,6 +180,10 @@ hipError_t DynCO::getDynFunc(hipFunction_t* hfunc, std::string func_name) {
CheckDeviceIdMatch();
if(hfunc == nullptr) {
return hipErrorInvalidValue;
}
auto it = functions_.find(func_name);
if (it == functions_.end()) {
DevLogPrintfError("Cannot find the function: %s ", func_name.c_str());
+2 -3
Datei anzeigen
@@ -13,7 +13,6 @@ FatBinaryDeviceInfo::~FatBinaryDeviceInfo() {
FatBinaryInfo::FatBinaryInfo(const char* fname, const void* image)
: fdesc_(amd::Os::FDescInit()), fsize_(0), image_(image), uri_(std::string()) {
guarantee(fname || image);
if (fname != nullptr) {
fname_ = std::string(fname);
@@ -35,7 +34,7 @@ FatBinaryInfo::~FatBinaryInfo() {
guarantee(false && "Cannot close file");
}
if (!amd::Os::MemoryUnmapFile(image_, fsize_)) {
if (fsize_ && !amd::Os::MemoryUnmapFile(image_, fsize_)) {
guarantee(false && "Cannot unmap file");
}
}
@@ -82,7 +81,7 @@ hipError_t FatBinaryInfo::ExtractFatBinary(const std::vector<hip::Device*>& devi
hip_error = CodeObject::ExtractCodeObjectFromMemory(image_,
device_names, code_objs, uri_);
} else {
return hipErrorMissingConfiguration;
return hipErrorInvalidValue;
}
if (hip_error == hipErrorNoBinaryForGpu) {
+8
Datei anzeigen
@@ -84,6 +84,10 @@ extern hipError_t __hipExtractCodeObjectFromFatBinary(const void* data,
hipError_t hipModuleGetFunction(hipFunction_t *hfunc, hipModule_t hmod, const char *name) {
HIP_INIT_API(hipModuleGetFunction, hfunc, hmod, name);
if(hfunc == nullptr || name == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
if (hipSuccess != PlatformState::instance().getDynFunc(hfunc, hmod, name)) {
DevLogPrintfError("Cannot find the function: %s for module: 0x%x \n",
name, hmod);
@@ -97,6 +101,10 @@ hipError_t hipModuleGetGlobal(hipDeviceptr_t* dptr, size_t* bytes, hipModule_t h
{
HIP_INIT_API(hipModuleGetGlobal, dptr, bytes, hmod, name);
if(dptr == nullptr || bytes == nullptr || name == nullptr) {
return hipErrorInvalidValue;
}
/* Get address and size for the global symbol */
if (hipSuccess != PlatformState::instance().getDynGlobalVar(name, hmod, dptr, bytes)) {
DevLogPrintfError("Cannot find global Var: %s for module: 0x%x at device: %d \n",
+8
Datei anzeigen
@@ -702,6 +702,10 @@ void PlatformState::init()
hipError_t PlatformState::loadModule(hipModule_t *module, const char* fname, const void* image) {
amd::ScopedLock lock(lock_);
if(module == nullptr) {
return hipErrorInvalidValue;
}
hip::DynCO* dynCo = new hip::DynCO();
hipError_t hip_error = dynCo->loadCodeObject(fname, image);
if (hip_error != hipSuccess) {
@@ -763,6 +767,10 @@ hipError_t PlatformState::getDynGlobalVar(const char* hostVar, hipModule_t hmod,
hipDeviceptr_t* dev_ptr, size_t* size_ptr) {
amd::ScopedLock lock(lock_);
if(hostVar == nullptr || dev_ptr == nullptr || size_ptr == nullptr) {
return hipErrorInvalidValue;
}
auto it = dynCO_map_.find(hmod);
if (it == dynCO_map_.end()) {
DevLogPrintfError("Cannot find the module: 0x%x", hmod);