diff --git a/hipamd/src/hip_code_object.cpp b/hipamd/src/hip_code_object.cpp index 54cf533547..e9b41d316b 100644 --- a/hipamd/src/hip_code_object.cpp +++ b/hipamd/src/hip_code_object.cpp @@ -440,7 +440,7 @@ hipError_t CodeObject::ExtractCodeObjectFromFile( std::vector>& code_objs) { hipError_t hip_error = hipSuccess; - if (fdesc < 0) { + if (!amd::Os::isValidFileDesc(fdesc)) { return hipErrorFileNotFound; } diff --git a/hipamd/src/hip_fatbin.cpp b/hipamd/src/hip_fatbin.cpp index 57c0c718c2..c75e9110b9 100644 --- a/hipamd/src/hip_fatbin.cpp +++ b/hipamd/src/hip_fatbin.cpp @@ -78,7 +78,7 @@ FatBinaryInfo::~FatBinaryInfo() { } else { // Using Runtime Unbundler - if (fdesc_ > 0) { + if (amd::Os::isValidFileDesc(fdesc_)) { if (fsize_ && !amd::Os::MemoryUnmapFile(image_, fsize_)) { LogPrintfError("Cannot unmap file for fdesc: %d fsize: %d", fdesc_, fsize_); assert(false); @@ -183,7 +183,7 @@ hipError_t FatBinaryInfo::ExtractFatBinaryUsingCOMGR(const std::vector 0) { + if (amd::Os::isValidFileDesc(fdesc_)) { guarantee(fsize_ > 0, "Cannot have a file size of 0, fdesc: %d fname: %s \n", fdesc_, fname_.c_str()); if ((comgr_status = amd_comgr_set_data_from_file_slice(data_object, fdesc_, foffset_, diff --git a/rocclr/os/os.cpp b/rocclr/os/os.cpp index 0437f7f1d6..e15800a7f7 100644 --- a/rocclr/os/os.cpp +++ b/rocclr/os/os.cpp @@ -37,6 +37,16 @@ namespace amd { +bool Os::isValidFileDesc(const amd::Os::FileDesc& desc) { + #if defined(_WIN32) + return reinterpret_cast(desc) > 0; + #else + return static_cast(desc) > 0; + #endif + return false; +} + + void* Os::loadLibrary(const char* libraryname) { void* handle; diff --git a/rocclr/os/os.hpp b/rocclr/os/os.hpp index b4649846b5..c9bd0b99e5 100644 --- a/rocclr/os/os.hpp +++ b/rocclr/os/os.hpp @@ -292,6 +292,8 @@ class Os : AllStatic { // typedef bool (*SymbolCallback)(std::string, const void*, void*); + //! checks if file descriptor is valid + static bool isValidFileDesc(const amd::Os::FileDesc& desc); //! Load the shared library named by \a filename static void* loadLibrary(const char* filename); //! Unload the shared library. diff --git a/rocclr/platform/interop_d3d10.hpp b/rocclr/platform/interop_d3d10.hpp index 0d7b230849..0fdba3e492 100644 --- a/rocclr/platform/interop_d3d10.hpp +++ b/rocclr/platform/interop_d3d10.hpp @@ -123,7 +123,7 @@ public: if(pQuery_) pQuery_->Release(); // Check if this resource has already been used for interop if(resources_.size()) { - for(auto& it = resources_.cbegin(); it != resources_.cend(); it++) { + for(auto it = resources_.cbegin(); it != resources_.cend(); it++) { if(((pD3D10ResOrig_ && (*it).first == (void*) pD3D10ResOrig_) || ((*it).first == (void*) pD3D10Res_)) && (*it).second == subRes_) { diff --git a/rocclr/platform/interop_d3d11.hpp b/rocclr/platform/interop_d3d11.hpp index 2d82bbd36c..bfca17d04d 100644 --- a/rocclr/platform/interop_d3d11.hpp +++ b/rocclr/platform/interop_d3d11.hpp @@ -122,7 +122,7 @@ public: if(pQuery_) pQuery_->Release(); // Check if this resource has already been used for interop if(resources_.size()) { - for(auto& it = resources_.cbegin(); it != resources_.cend(); it++) { + for(auto it = resources_.cbegin(); it != resources_.cend(); it++) { if(((pD3D11ResOrig_ && (*it).first == (void*) pD3D11ResOrig_) || ((*it).first == (void*) pD3D11Res_)) && (*it).second.first == subRes_ diff --git a/rocclr/platform/interop_d3d9.hpp b/rocclr/platform/interop_d3d9.hpp index d53fe9466d..828bc9190a 100644 --- a/rocclr/platform/interop_d3d9.hpp +++ b/rocclr/platform/interop_d3d9.hpp @@ -119,7 +119,7 @@ public: if(pQuery_) pQuery_->Release(); //if the resouce is being used if(resources_.size()) { - for(auto& it = resources_.cbegin(); it != resources_.cend(); it++) { + for(auto it = resources_.cbegin(); it != resources_.cend(); it++) { if( surfInfo_.resource && ((*it).first.surfInfo.resource == surfInfo_.resource) && ((*it).first.surfPlane == surfPlane_)) {