Changeset 3457 in CLRX
- Timestamp:
- Oct 7, 2017, 12:21:39 PM (17 months ago)
- Location:
- CLRadeonExtender/trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
CLRadeonExtender/trunk/CLRX/amdasm/AsmDefs.h
r3195 r3457 38 38 namespace CLRX 39 39 { 40 41 /// Assembler exception class 42 class AsmException: public Exception 43 { 44 public: 45 /// empty constructor 46 AsmException() = default; 47 /// constructor with messasge 48 explicit AsmException(const std::string& message); 49 /// destructor 50 virtual ~AsmException() noexcept = default; 51 }; 40 52 41 53 enum: cxbyte { -
CLRadeonExtender/trunk/CLRX/amdasm/Disassembler.h
r3312 r3457 43 43 namespace CLRX 44 44 { 45 46 /// Disassembler exception class 47 class DisasmException: public Exception 48 { 49 public: 50 /// empty constructor 51 DisasmException() = default; 52 /// constructor with messasge 53 explicit DisasmException(const std::string& message); 54 /// destructor 55 virtual ~DisasmException() noexcept = default; 56 }; 45 57 46 58 class Disassembler; -
CLRadeonExtender/trunk/CLRX/amdbin/ElfBinaries.h
r3194 r3457 74 74 }; 75 75 76 /// Bin exception class 77 class BinException: public Exception 78 { 79 public: 80 /// empty constructor 81 BinException() = default; 82 /// constructor with messasge 83 explicit BinException(const std::string& message); 84 /// destructor 85 virtual ~BinException() noexcept = default; 86 }; 87 88 /// Binary generator exception class 89 class BinGenException: public Exception 90 { 91 public: 92 /// empty constructor 93 BinGenException() = default; 94 /// constructor with messasge 95 explicit BinGenException(const std::string& message); 96 /// destructor 97 virtual ~BinGenException() noexcept = default; 98 }; 99 76 100 /// ELF 32-bit types 77 101 struct Elf32Types … … 310 334 sectionIndexMap.begin(), sectionIndexMap.end(), name, CStringLess()); 311 335 if (it == sectionIndexMap.end()) 312 throw Exception(std::string("Can't find Elf")+Types::bitName+" Section");336 throw BinException(std::string("Can't find Elf")+Types::bitName+" Section"); 313 337 return it; 314 338 } … … 337 361 symbolIndexMap.begin(), symbolIndexMap.end(), name, CStringLess()); 338 362 if (it == symbolIndexMap.end()) 339 throw Exception(std::string("Can't find Elf")+Types::bitName+" Symbol");363 throw BinException(std::string("Can't find Elf")+Types::bitName+" Symbol"); 340 364 return it; 341 365 } … … 347 371 dynSymIndexMap.begin(), dynSymIndexMap.end(), name, CStringLess()); 348 372 if (it == dynSymIndexMap.end()) 349 throw Exception(std::string("Can't find Elf")+Types::bitName+" DynSymbol");373 throw BinException(std::string("Can't find Elf")+Types::bitName+" DynSymbol"); 350 374 return it; 351 375 } -
CLRadeonExtender/trunk/CLRX/utils/GPUId.h
r3444 r3457 31 31 namespace CLRX 32 32 { 33 34 /// GPUId exception class 35 class GPUIdException: public Exception 36 { 37 public: 38 /// empty constructor 39 GPUIdException() = default; 40 /// constructor with messasge 41 explicit GPUIdException(const std::string& message); 42 /// destructor 43 virtual ~GPUIdException() noexcept = default; 44 }; 45 33 46 /* 34 47 * GPU identification utilities -
CLRadeonExtender/trunk/amdasm/AsmExpression.cpp
r3436 r3457 117 117 { 118 118 if (symOccursNum != 0) 119 throw Exception("Expression can't be evaluated if symbols still are unresolved!"); 119 throw AsmException("Expression can't be evaluated if " 120 "symbols still are unresolved!"); 120 121 121 122 bool failed = false; -
CLRadeonExtender/trunk/amdasm/AsmRegAlloc.cpp
r3398 r3457 77 77 size_t defaultInstrSize = (!useRegMode ? this->defaultInstrSize : 0); 78 78 if (lastOffset > offset) 79 throw Exception("Offset before previous instruction");79 throw AsmException("Offset before previous instruction"); 80 80 if (!instrStruct.empty() && offset - lastOffset < defaultInstrSize) 81 throw Exception("Offset between previous instruction");81 throw AsmException("Offset between previous instruction"); 82 82 size_t toSkip = !instrStruct.empty() ? 83 83 offset - lastOffset - defaultInstrSize : offset; … … 170 170 { 171 171 if (!isNext) 172 throw Exception("No reg usage in this code");172 throw AsmException("No reg usage in this code"); 173 173 AsmRegVarUsage rvu; 174 174 // get regvarusage … … 1872 1872 { 1873 1873 if (colorsNum >= maxColorsNum) 1874 throw Exception("Too many register is needed");1874 throw AsmException("Too many register is needed"); 1875 1875 colorsNum++; 1876 1876 } -
CLRadeonExtender/trunk/amdasm/AsmSource.cpp
r3424 r3457 161 161 stream = new std::ifstream(filename.c_str(), std::ios::binary); 162 162 if (!*stream) 163 throw Exception(std::string("Can't open source file '")+filename.c_str()+"'"); 163 throw AsmException(std::string("Can't open source file '")+ 164 filename.c_str()+"'"); 164 165 stream->exceptions(std::ios::badbit); 165 166 buffer.reserve(AsmParserLineMaxSize); … … 199 200 stream = new std::ifstream(filename.c_str(), std::ios::binary); 200 201 if (!*stream) 201 throw Exception(std::string("Can't open source file '")+filename.c_str()+"'"); 202 throw AsmException(std::string("Can't open source file '")+ 203 filename.c_str()+"'"); 202 204 stream->exceptions(std::ios::badbit); 203 205 buffer.reserve(AsmParserLineMaxSize); -
CLRadeonExtender/trunk/amdasm/Assembler.cpp
r3423 r3457 46 46 47 47 using namespace CLRX; 48 49 // Assembler Exception costuctor 50 AsmException::AsmException(const std::string& message) : Exception(message) 51 { } 48 52 49 53 // copy constructor - includes usageHandler copying … … 2707 2711 formatHandler->writeBinary(ofs); 2708 2712 else 2709 throw Exception(std::string("Can't open output file '")+filename+"'");2713 throw AsmException(std::string("Can't open output file '")+filename+"'"); 2710 2714 } 2711 2715 else 2712 throw Exception("No output binary");2716 throw AsmException("No output binary"); 2713 2717 } 2714 2718 else // failed 2715 throw Exception("Assembler failed!");2719 throw AsmException("Assembler failed!"); 2716 2720 } 2717 2721 … … 2724 2728 formatHandler->writeBinary(outStream); 2725 2729 else 2726 throw Exception("No output binary");2730 throw AsmException("No output binary"); 2727 2731 } 2728 2732 else // failed 2729 throw Exception("Assembler failed!");2733 throw AsmException("Assembler failed!"); 2730 2734 } 2731 2735 … … 2738 2742 formatHandler->writeBinary(array); 2739 2743 else 2740 throw Exception("No output binary");2744 throw AsmException("No output binary"); 2741 2745 } 2742 2746 else // failed 2743 throw Exception("Assembler failed!");2744 } 2747 throw AsmException("Assembler failed!"); 2748 } -
CLRadeonExtender/trunk/amdasm/DisasmAmd.cpp
r3429 r3457 733 733 cxuint argNo = cstrtovCStyle<cxuint>(linePtr+12, lineEnd, outEnd); 734 734 if (argNo >= config.args.size()) 735 throw Exception("ArgNo out of range");735 throw DisasmException("ArgNo out of range"); 736 736 const char* ptr = strechr(linePtr+12, lineEnd, ':'); 737 737 if (ptr==nullptr) … … 791 791 config.args[argIdx].argType = KernelArgType::SAMPLER; 792 792 else 793 throw Exception("Sampler arg index out of range");793 throw DisasmException("Sampler arg index out of range"); 794 794 795 795 // apply const qualifier to some pointer arguments … … 798 798 config.args[argIdx].ptrAccess |= KARG_PTR_CONST; 799 799 else 800 throw Exception("Const arg index out of range");800 throw DisasmException("Const arg index out of range"); 801 801 802 802 /* from ATI CAL NOTES */ -
CLRadeonExtender/trunk/amdasm/DisasmAmdCL2.cpp
r3430 r3457 145 145 // check symbol type, section and value 146 146 if (ELF64_ST_TYPE(sym.st_info) != 12) 147 throw Exception("Wrong sampler symbol");147 throw DisasmException("Wrong sampler symbol"); 148 148 uint64_t value = ULEV(sym.st_value); 149 149 if (ULEV(sym.st_shndx) != samplerInitSecIndex) 150 throw Exception("Wrong section for sampler symbol");150 throw DisasmException("Wrong section for sampler symbol"); 151 151 if ((value&7) != 0) 152 throw Exception("Wrong value of sampler symbol");152 throw DisasmException("Wrong value of sampler symbol"); 153 153 input->samplerRelocs.push_back({ size_t(ULEV(rel.r_offset)), 154 154 size_t(value>>3) }); … … 238 238 if (sortedRelocIter != sortedRelocs.end() && 239 239 sortedRelocIter->first < size_t(kinput.code-textPtr)) 240 throw Exception("Code relocation offset outside kernel code");240 throw DisasmException("Code relocation offset outside kernel code"); 241 241 242 242 if (sortedRelocIter != sortedRelocs.end()) … … 257 257 if (symShndx!=gDataSectionIdx && symShndx!=rwDataSectionIdx && 258 258 symShndx!=bssDataSectionIdx) 259 throw Exception("Symbol is not placed in global or "259 throw DisasmException("Symbol is not placed in global or " 260 260 "rwdata data or bss is illegal"); 261 261 addend += ULEV(sym.st_value); … … 270 270 relocType = RELTYPE_HIGH_32BIT; 271 271 else 272 throw Exception("Unknown relocation type");272 throw DisasmException("Unknown relocation type"); 273 273 // put text relocs. compute offset by subtracting current code offset 274 274 kinput.textRelocs.push_back(AmdCL2RelaEntry{sortedRelocIter->first- … … 279 279 } 280 280 if (sortedRelocIter != sortedRelocs.end()) 281 throw Exception("Code relocation offset outside kernel code");281 throw DisasmException("Code relocation offset outside kernel code"); 282 282 return input.release(); 283 283 } … … 474 474 case 0: 475 475 if (kindOfType!=1) // not sampler 476 throw Exception("Wrong kernel argument type");476 throw DisasmException("Wrong kernel argument type"); 477 477 arg.argType = KernelArgType::SAMPLER; 478 478 break; … … 490 490 { 491 491 if (kindOfType!=4) // not scalar 492 throw Exception("Wrong kernel argument type");492 throw DisasmException("Wrong kernel argument type"); 493 493 arg.argType = (argType==3) ? 494 494 KernelArgType::SHORT : KernelArgType::CHAR; 495 495 } 496 496 else 497 throw Exception("Wrong kernel argument type");497 throw DisasmException("Wrong kernel argument type"); 498 498 break; 499 499 case 4: // int 500 500 case 5: // long 501 501 if (kindOfType!=4) // not scalar 502 throw Exception("Wrong kernel argument type");502 throw DisasmException("Wrong kernel argument type"); 503 503 arg.argType = (argType==5) ? 504 504 KernelArgType::LONG : KernelArgType::INT; … … 512 512 { 513 513 if (kindOfType!=4) // not scalar 514 throw Exception("Wrong kernel argument type");514 throw DisasmException("Wrong kernel argument type"); 515 515 const cxuint vectorId = vectorIdTable[vectorSize]; 516 516 if (vectorId == UINT_MAX) 517 throw Exception("Wrong vector size");517 throw DisasmException("Wrong vector size"); 518 518 arg.argType = cl20ArgTypeVectorTable[(argType-6)*6 + vectorId]; 519 519 break; … … 521 521 case 15: 522 522 if (kindOfType!=4) // not scalar 523 throw Exception("Wrong kernel argument type");523 throw DisasmException("Wrong kernel argument type"); 524 524 arg.argType = KernelArgType::STRUCTURE; 525 525 break; 526 526 case 18: 527 527 if (kindOfType!=7) // not scalar 528 throw Exception("Wrong kernel argument type");528 throw DisasmException("Wrong kernel argument type"); 529 529 arg.argType = KernelArgType::CMDQUEUE; 530 530 break; 531 531 default: 532 throw Exception("Wrong kernel argument type");532 throw DisasmException("Wrong kernel argument type"); 533 533 break; 534 534 } … … 569 569 arg.ptrSpace = KernelPtrSpace::CONSTANT; 570 570 else 571 throw Exception("Illegal pointer space");571 throw DisasmException("Illegal pointer space"); 572 572 // set access qualifiers (volatile, restrict, const) 573 573 arg.ptrAccess |= KARG_PTR_NORMAL; … … 581 581 // pointer space for pipe 582 582 if (ptrSpace!=4) 583 throw Exception("Illegal pipe space");583 throw DisasmException("Illegal pipe space"); 584 584 arg.ptrSpace = KernelPtrSpace::GLOBAL; 585 585 } -
CLRadeonExtender/trunk/amdasm/Disassembler.cpp
r3429 r3457 35 35 36 36 using namespace CLRX; 37 38 DisasmException::DisasmException(const std::string& message) : Exception(message) 39 { } 37 40 38 41 ISADisassembler::ISADisassembler(Disassembler& _disassembler, cxuint outBufSize) -
CLRadeonExtender/trunk/amdasm/GCNAssembler.cpp
r3434 r3457 301 301 break; 302 302 default: 303 throw Exception("Unknown GCNField");303 throw AsmException("Unknown GCNField"); 304 304 } 305 305 return { rstart, rstart+regSize }; -
CLRadeonExtender/trunk/amdbin/AmdBinGen.cpp
r3417 r3457 689 689 { 690 690 if (kinput.metadata == nullptr || kinput.metadataSize == 0) 691 throw Exception("No metadata for kernel");691 throw BinGenException("No metadata for kernel"); 692 692 if (kinput.header == nullptr || kinput.headerSize == 0) 693 throw Exception("No header for kernel");693 throw BinGenException("No header for kernel"); 694 694 if (kinput.code == nullptr) 695 throw Exception("No code for kernel");695 throw BinGenException("No code for kernel"); 696 696 continue; // and skip 697 697 } … … 700 700 TempAmdKernelConfig& tempConfig = tempAmdKernelConfigs[i]; 701 701 if (config.userDatas.size() > 16) 702 throw Exception("UserDataElemsNum must not be greater than 16");702 throw BinGenException("UserDataElemsNum must not be greater than 16"); 703 703 if (config.usedVGPRsNum > maxVGPRSNum) 704 throw Exception("Used VGPRs number out of range");704 throw BinGenException("Used VGPRs number out of range"); 705 705 if (config.usedSGPRsNum > maxSGPRSNum) 706 throw Exception("Used SGPRs number out of range");706 throw BinGenException("Used SGPRs number out of range"); 707 707 if (config.hwLocalSize > 32768) 708 throw Exception("HWLocalSize out of range");708 throw BinGenException("HWLocalSize out of range"); 709 709 if (config.floatMode >= 256) 710 throw Exception("FloatMode out of range");710 throw BinGenException("FloatMode out of range"); 711 711 712 712 /* filling input */ … … 719 719 for (const AmdKernelArgInput& arg: config.args) 720 720 if (arg.argType > KernelArgType::MAX_VALUE) 721 throw Exception("Unknown argument type");721 throw BinGenException("Unknown argument type"); 722 722 else if (arg.argType == KernelArgType::POINTER) 723 723 { 724 724 if (arg.pointerType > KernelArgType::MAX_VALUE) 725 throw Exception("Unknown argument's pointer type");725 throw BinGenException("Unknown argument's pointer type"); 726 726 if (arg.ptrSpace > KernelPtrSpace::MAX_VALUE || 727 727 arg.ptrSpace == KernelPtrSpace::NONE) 728 throw Exception("Wrong pointer space type");728 throw BinGenException("Wrong pointer space type"); 729 729 } 730 730 else if (isKernelArgImage(arg.argType)) 731 731 { 732 732 if ((arg.ptrAccess & KARG_PTR_ACCESS_MASK) == 0) 733 throw Exception("Invalid access qualifier for image");733 throw BinGenException("Invalid access qualifier for image"); 734 734 } 735 735 … … 806 806 807 807 if (tempConfig.uavId != BINGEN_NOTSUPPLIED && tempConfig.uavId >= 1024) 808 throw Exception("UavId out of range");808 throw BinGenException("UavId out of range"); 809 809 if (tempConfig.constBufferId != BINGEN_NOTSUPPLIED && 810 810 tempConfig.constBufferId >= 1024) 811 throw Exception("ConstBufferId out of range");811 throw BinGenException("ConstBufferId out of range"); 812 812 if (tempConfig.printfId != BINGEN_NOTSUPPLIED && tempConfig.printfId >= 1024) 813 throw Exception("PrintfId out of range");813 throw BinGenException("PrintfId out of range"); 814 814 if (tempConfig.privateId != BINGEN_NOTSUPPLIED && tempConfig.privateId >= 1024) 815 throw Exception("PrivateId out of range");815 throw BinGenException("PrivateId out of range"); 816 816 817 817 /* fill argUavIds for global/constant pointers */ … … 838 838 if ((arg.resId < 9 && arg.used) || 839 839 (!arg.used && arg.resId != tempConfig.uavId) || arg.resId >= 1024) 840 throw Exception("UavId out of range!");840 throw BinGenException("UavId out of range!"); 841 841 if (puavMask[arg.resId] && arg.resId != tempConfig.uavId) 842 throw Exception("UavId already used!");842 throw BinGenException("UavId already used!"); 843 843 puavMask.set(arg.resId); 844 844 tempConfig.argResIds[k] = arg.resId; … … 849 849 // old constant buffers 850 850 if (arg.resId < 2 || arg.resId >= 160) 851 throw Exception("CbId out of range!");851 throw BinGenException("CbId out of range!"); 852 852 if (cbIdMask[arg.resId]) 853 throw Exception("CbId already used!");853 throw BinGenException("CbId already used!"); 854 854 cbIdMask.set(arg.resId); 855 855 tempConfig.argResIds[k] = arg.resId; … … 861 861 { 862 862 if (arg.resId >= 128) 863 throw Exception("RdImgId out of range!");863 throw BinGenException("RdImgId out of range!"); 864 864 if (rdImgMask[arg.resId]) 865 throw Exception("RdImgId already used!");865 throw BinGenException("RdImgId already used!"); 866 866 rdImgMask.set(arg.resId); 867 867 tempConfig.argResIds[k] = arg.resId; … … 870 870 { 871 871 if (arg.resId >= 8) 872 throw Exception("WrImgId out of range!");872 throw BinGenException("WrImgId out of range!"); 873 873 if (wrImgMask[arg.resId]) 874 throw Exception("WrImgId already used!");874 throw BinGenException("WrImgId already used!"); 875 875 wrImgMask.set(arg.resId); 876 876 tempConfig.argResIds[k] = arg.resId; … … 880 880 { 881 881 if (arg.resId >= 8) 882 throw Exception("CounterId out of range!");882 throw BinGenException("CounterId out of range!"); 883 883 if (cntIdMask[arg.resId]) 884 throw Exception("CounterId already used!");884 throw BinGenException("CounterId already used!"); 885 885 cntIdMask.set(arg.resId); 886 886 tempConfig.argResIds[k] = arg.resId; … … 902 902 puavIdsCount++); 903 903 if (puavIdsCount == 1024) 904 throw Exception("UavId out of range!");904 throw BinGenException("UavId out of range!"); 905 905 tempConfig.argResIds[k] = puavIdsCount++; 906 906 } … … 914 914 for (; cbIdsCount < 160 && cbIdMask[cbIdsCount]; cbIdsCount++); 915 915 if (cbIdsCount == 160) 916 throw Exception("CbId out of range!");916 throw BinGenException("CbId out of range!"); 917 917 tempConfig.argResIds[k] = cbIdsCount++; 918 918 } … … 924 924 for (; rdImgsCount < 128 && rdImgMask[rdImgsCount]; rdImgsCount++); 925 925 if (rdImgsCount == 128) 926 throw Exception("RdImgId out of range!");926 throw BinGenException("RdImgId out of range!"); 927 927 tempConfig.argResIds[k] = rdImgsCount++; 928 928 } … … 931 931 for (; wrImgsCount < 8 && wrImgMask[wrImgsCount]; wrImgsCount++); 932 932 if (wrImgsCount == 8) 933 throw Exception("WrImgId out of range!");933 throw BinGenException("WrImgId out of range!"); 934 934 tempConfig.argResIds[k] = wrImgsCount++; 935 935 } … … 939 939 for (; cntIdsCount < 8 && cntIdMask[cntIdsCount]; cntIdsCount++); 940 940 if (cntIdsCount == 8) 941 throw Exception("CounterId out of range!");941 throw BinGenException("CounterId out of range!"); 942 942 tempConfig.argResIds[k] = cntIdsCount++; 943 943 } … … 1026 1026 const TypeNameVecSize& tp = argTypeNamesTable[cxuint(arg.pointerType)]; 1027 1027 if (tp.kindOfType == KT_UNKNOWN) 1028 throw Exception("Type not supported!");1028 throw BinGenException("Type not supported!"); 1029 1029 const cxuint typeSize = 1030 1030 cxuint((tp.vecSize==3) ? 4 : tp.vecSize)*tp.elemSize; … … 1054 1054 } 1055 1055 else 1056 throw Exception("Other memory spaces are not supported");1056 throw BinGenException("Other memory spaces are not supported"); 1057 1057 metadata += ':'; 1058 1058 const size_t elemSize = (arg.pointerType==KernelArgType::STRUCTURE)? … … 1087 1087 metadata += "RW"; 1088 1088 else 1089 throw Exception("Invalid image access qualifier!");1089 throw BinGenException("Invalid image access qualifier!"); 1090 1090 metadata += ':'; 1091 1091 itocstrCStyle(tempConfig.argResIds[k], numBuf, 21); … … 1119 1119 const TypeNameVecSize& tp = argTypeNamesTable[cxuint(arg.argType)]; 1120 1120 if (tp.kindOfType == KT_UNKNOWN) 1121 throw Exception("Type not supported!");1121 throw BinGenException("Type not supported!"); 1122 1122 // type size is aligned (fix for 3 length vectors) 1123 1123 const cxuint typeSize = … … 1600 1600 /* checking input */ 1601 1601 if (input->deviceType > GPUDeviceType::GPUDEVICE_MAX) 1602 throw Exception("Unknown GPU device type");1602 throw BinGenException("Unknown GPU device type"); 1603 1603 1604 1604 Array<TempAmdKernelConfig> tempAmdKernelConfigs(kernelsNum); … … 1609 1609 1610 1610 if (gpuDeviceCodeTable[cxuint(input->deviceType)] == 0xffff) 1611 throw Exception("Unsupported GPU device type by OpenCL 1.2 binary format");1611 throw BinGenException("Unsupported GPU device type by OpenCL 1.2 binary format"); 1612 1612 1613 1613 if (input->is64Bit) … … 1658 1658 writeOnlyImages++; 1659 1659 if (writeOnlyImages > 8) 1660 throw Exception("Too many write only images");1660 throw BinGenException("Too many write only images"); 1661 1661 } 1662 1662 } … … 1760 1760 const uint64_t innerBinSize = kelfBinGen.countSize(); 1761 1761 if (innerBinSize > UINT32_MAX) 1762 throw Exception("Inner binary size is too big!");1762 throw BinGenException("Inner binary size is too big!"); 1763 1763 allInnerBinSize += tempAmdKernelDatas[i].innerBinSize = innerBinSize; 1764 1764 … … 1794 1794 #endif 1795 1795 binarySize > UINT32_MAX) 1796 throw Exception("Binary size is too big!");1796 throw BinGenException("Binary size is too big!"); 1797 1797 /**** 1798 1798 * prepare for write binary to output -
CLRadeonExtender/trunk/amdbin/AmdBinaries.cpp
r3417 r3457 176 176 const size_t encTableSize = ULEV(ephdr.p_filesz); 177 177 if (ULEV(ephdr.p_type) != 0x70000002) 178 throw Exception("Missing encodings table");178 throw BinException("Missing encodings table"); 179 179 if (encTableSize%sizeof(CALEncodingEntry) != 0) 180 throw Exception("Wrong size of encodings table");180 throw BinException("Wrong size of encodings table"); 181 181 if (usumGt(encTableOffset, encTableSize, binaryCodeSize)) 182 throw Exception("Offset+Size of encodings table out of range");182 throw BinException("Offset+Size of encodings table out of range"); 183 183 184 184 encodingEntriesNum = encTableSize/sizeof(CALEncodingEntry); … … 192 192 const size_t size = ULEV(entry.size); 193 193 if (offset >= binaryCodeSize) 194 throw Exception("Encoding entry offset out of range");194 throw BinException("Encoding entry offset out of range"); 195 195 if (usumGt(offset, size, binaryCodeSize)) 196 throw Exception("Encoding entry offset+size out of range");196 throw BinException("Encoding entry offset+size out of range"); 197 197 } 198 198 … … 211 211 // check offset and ranges of program header 212 212 if (offset < encEntryOffset) 213 throw Exception("Kernel program offset out of encoding");213 throw BinException("Kernel program offset out of encoding"); 214 214 if (usumGt(offset, size, encEntryOffset+encEntrySize)) 215 throw Exception("Kernel program offset+size out of encoding");215 throw BinException("Kernel program offset+size out of encoding"); 216 216 217 217 if ((creationFlags & AMDBIN_CREATE_CALNOTES) != 0 && … … 226 226 *reinterpret_cast<const CALNoteHeader*>(binaryCode+offset+pos); 227 227 if (ULEV(nhdr.nameSize) != 8) 228 throw Exception("Wrong name size in Note header!");228 throw BinException("Wrong name size in Note header!"); 229 229 if (::memcmp(nhdr.name, "ATI CAL", 8) != 0) 230 throw Exception("Wrong name in Note header!");230 throw BinException("Wrong name in Note header!"); 231 231 if (usumGt(uint32_t(pos + sizeof(CALNoteHeader)), 232 232 ULEV(nhdr.descSize), size)) 233 throw Exception("CAL Note desc size out of range");233 throw BinException("CAL Note desc size out of range"); 234 234 pos += sizeof(CALNoteHeader) + ULEV(nhdr.descSize); 235 235 } … … 254 254 // if program headers table is not exhausted, but no encoding entries 255 255 if (i+1 < getProgramHeadersNum() && encodingIndex >= encodingEntriesNum) 256 throw Exception("ProgramHeaders out of encodings!");256 throw BinException("ProgramHeaders out of encodings!"); 257 257 } 258 258 } … … 311 311 } 312 312 if (encEntryIndex == encodingEntriesNum) 313 throw Exception("Can't find suitable CALEncodingEntry!");313 throw BinException("Can't find suitable CALEncodingEntry!"); 314 314 return encEntryIndex; 315 315 } … … 329 329 } while (nestedLevel != 0 && pos < argDescsNum); 330 330 if (nestedLevel != 0) 331 throw Exception("Unfinished kernel argument structure");331 throw BinException("Unfinished kernel argument structure"); 332 332 return pos; 333 333 } … … 419 419 index = cstrtovCStyle<size_t>(symName+4, nullptr, outend); 420 420 if (*outend != 0) 421 throw Exception("Garbages in .str symbol name!");421 throw BinException("Garbages in .str symbol name!"); 422 422 } 423 423 if (argTypeNamesSyms.size() <= index) … … 426 426 const typename Types::Sym& sym = elf.getSymbol(i); 427 427 if (ULEV(sym.st_shndx) >= elf.getSectionHeadersNum()) 428 throw Exception("ArgTypeNameSymStr section index out of range");428 throw BinException("ArgTypeNameSymStr section index out of range"); 429 429 const typename Types::Shdr& secHdr = 430 430 elf.getSectionHeader(ULEV(sym.st_shndx)); // from symbol 431 431 432 432 if (ULEV(sym.st_value) >= ULEV(secHdr.sh_size)) 433 throw Exception("ArgTypeNameSymStr value out of range");433 throw BinException("ArgTypeNameSymStr value out of range"); 434 434 if (usumGt(ULEV(sym.st_value), ULEV(sym.st_size), ULEV(secHdr.sh_size))) 435 throw Exception("ArgTypeNameSymStr value+size out of range");435 throw BinException("ArgTypeNameSymStr value+size out of range"); 436 436 437 437 argTypeNamesSyms[index] = ULEV(secHdr.sh_offset) + ULEV(sym.st_value); … … 439 439 { 440 440 if (ULEV(sym.st_value) >= unfinishedRegion) 441 throw Exception("Arg name/type is unfinished!");441 throw BinException("Arg name/type is unfinished!"); 442 442 } 443 443 else // is not roData … … 448 448 449 449 if (ULEV(sym.st_value) >= unfinishedRegionArgNameSym) 450 throw Exception("Arg name/type is unfinished!");450 throw BinException("Arg name/type is unfinished!"); 451 451 } 452 452 continue; … … 469 469 elf.getSymbol(i); 470 470 if (ULEV(sym.st_shndx) >= elf.getSectionHeadersNum()) 471 throw Exception("Metadata section index out of range");471 throw BinException("Metadata section index out of range"); 472 472 473 473 const typename Types::Shdr& dataHdr = … … 479 479 if (fileOffset < ULEV(dataHdr.sh_offset) || 480 480 fileOffset >= ULEV(dataHdr.sh_offset) + ULEV(dataHdr.sh_size)) 481 throw Exception("File offset of kernelMetadata out of range!");481 throw BinException("File offset of kernelMetadata out of range!"); 482 482 const cxbyte* data = binaryCode + fileOffset; 483 483 … … 514 514 515 515 if (realArgsNum >= kernelInfo.argInfos.size()) 516 throw Exception("Kernel ArgInfo index out of range");516 throw BinException("Kernel ArgInfo index out of range"); 517 517 AmdKernelArg& karg = kernelInfo.argInfos[realArgsNum++]; 518 518 const size_t rodataHdrOffset = ULEV(rodataHdr.sh_offset); … … 525 525 if (argNameSym.getNameOffset() < rodataHdrOffset || 526 526 argNameSym.getNameOffset() >= rodataHdrOffset+rodataHdrSize) 527 throw Exception("Kernel arg name offset out of range!");527 throw BinException("Kernel arg name offset out of range!"); 528 528 529 529 if (argNameSym.getNameOffset()-rodataHdrOffset >= unfinishedRegion) 530 throw Exception("Arg name is unfinished!");530 throw BinException("Arg name is unfinished!"); 531 531 532 532 karg.argName = reinterpret_cast<const char*>( … … 536 536 { 537 537 if (argNameTypeNameIdx >= argTypeNamesSyms.size()) 538 throw Exception("ArgName sym index out of range");538 throw BinException("ArgName sym index out of range"); 539 539 const typename Types::Size value = argTypeNamesSyms[argNameTypeNameIdx++]; 540 540 if (value >= elf.getSize()) 541 throw Exception("ArgName sym offset out of range");541 throw BinException("ArgName sym offset out of range"); 542 542 543 543 karg.argName = reinterpret_cast<const char*>(binaryCode + value); … … 549 549 if (argTypeSym.getNameOffset() < rodataHdrOffset || 550 550 argTypeSym.getNameOffset() >= rodataHdrOffset+rodataHdrSize) 551 throw Exception("Kernel arg type offset out of range!");551 throw BinException("Kernel arg type offset out of range!"); 552 552 553 553 if (argTypeSym.getNameOffset()-rodataHdrOffset >= unfinishedRegion) 554 throw Exception("Type name is unfinished!");554 throw BinException("Type name is unfinished!"); 555 555 556 556 karg.typeName = reinterpret_cast<const char*>( … … 560 560 { 561 561 if (argNameTypeNameIdx >= argTypeNamesSyms.size()) 562 throw Exception("ArgType sym index out of range");562 throw BinException("ArgType sym index out of range"); 563 563 const typename Types::Size value = argTypeNamesSyms[argNameTypeNameIdx++]; 564 564 if (value >= elf.getSize()) 565 throw Exception("ArgType sym offset out of range");565 throw BinException("ArgType sym offset out of range"); 566 566 567 567 karg.typeName = reinterpret_cast<const char*>(binaryCode + value); … … 571 571 { 572 572 if (argType > 0x26) 573 throw Exception("Unknown kernel arg type");573 throw BinException("Unknown kernel arg type"); 574 574 karg.argType = x86ArgTypeTable[argType]; 575 575 if (karg.argType == KernelArgType::POINTER && … … 622 622 kernelInfosMap.begin(), kernelInfosMap.end(), name); 623 623 if (it == kernelInfosMap.end()) 624 throw Exception("Can't find kernel name");624 throw BinException("Can't find kernel name"); 625 625 return kernelInfos[it->second]; 626 626 } … … 1140 1140 compileOptionShIndex = ULEV(sym.st_shndx); 1141 1141 if (compileOptionShIndex >= mainElf.getSectionHeadersNum()) 1142 throw Exception("CompileOptions section index out of range");1142 throw BinException("CompileOptions section index out of range"); 1143 1143 const typename Types::Shdr& shdr = 1144 1144 mainElf.getSectionHeader(compileOptionShIndex); … … 1147 1147 mainElf.getSectionContent(compileOptionShIndex)); 1148 1148 if (ULEV(sym.st_value) >= ULEV(shdr.sh_size)) 1149 throw Exception("CompileOptions value out of range");1149 throw BinException("CompileOptions value out of range"); 1150 1150 // compileOptionsEnd used later for setting offset for driver info 1151 1151 // compile options precedes driver info 1152 1152 compileOptionsEnd = ULEV(sym.st_value) + ULEV(sym.st_size); 1153 1153 if (usumGt(ULEV(sym.st_value), ULEV(sym.st_size), ULEV(shdr.sh_size))) 1154 throw Exception("CompileOptions value+size out of range");1154 throw BinException("CompileOptions value+size out of range"); 1155 1155 compileOptions.assign(sectionContent + ULEV(sym.st_value), ULEV(sym.st_size)); 1156 1156 } … … 1163 1163 const typename Types::Shdr& shdr = mainElf.getSectionHeader(shindex); 1164 1164 if (ULEV(sym.st_value) >= ULEV(shdr.sh_size)) 1165 throw Exception("globalData value out of range");1165 throw BinException("globalData value out of range"); 1166 1166 if (usumGt(ULEV(sym.st_value), ULEV(sym.st_size), ULEV(shdr.sh_size))) 1167 throw Exception("globalData value+size out of range");1167 throw BinException("globalData value+size out of range"); 1168 1168 globalDataSize = ULEV(sym.st_size); 1169 1169 globalData = mainElf.getSectionContent(shindex) + ULEV(sym.st_value); … … 1214 1214 const typename Types::Word symsize = ULEV(sym.st_size); 1215 1215 if (symvalue > ULEV(textHdr.sh_size)) 1216 throw Exception("Inner binary offset out of range!");1216 throw BinException("Inner binary offset out of range!"); 1217 1217 if (usumGt(symvalue, symsize, ULEV(textHdr.sh_size))) 1218 throw Exception("Inner binary offset+size out of range!");1218 throw BinException("Inner binary offset+size out of range!"); 1219 1219 1220 1220 innerBinaries[ki++] = AmdInnerGPUBinary32(CString(symName+9, len-16), … … 1243 1243 const char* symName = mainElf.getSymbolName(it); 1244 1244 if (ULEV(sym.st_shndx) >= mainElf.getSectionHeadersNum()) 1245 throw Exception("Metadata section index out of range");1245 throw BinException("Metadata section index out of range"); 1246 1246 1247 1247 const typename Types::Shdr& rodataHdr = … … 1252 1252 const typename Types::Word symsize = ULEV(sym.st_size); 1253 1253 if (symvalue > ULEV(rodataHdr.sh_size)) 1254 throw Exception("Metadata offset out of range");1254 throw BinException("Metadata offset out of range"); 1255 1255 if (usumGt(symvalue, symsize, ULEV(rodataHdr.sh_size))) 1256 throw Exception("Metadata offset+size out of range");1256 throw BinException("Metadata offset+size out of range"); 1257 1257 1258 1258 // parse AMDGPU kernel metadata … … 1285 1285 const size_t symNameLen = ::strlen(symName); 1286 1286 if (ULEV(sym.st_shndx) >= mainElf.getSectionHeadersNum()) 1287 throw Exception("KernelHeader section index out of range");1287 throw BinException("KernelHeader section index out of range"); 1288 1288 1289 1289 const typename Types::Shdr& rodataHdr = … … 1294 1294 const typename Types::Word symsize = ULEV(sym.st_size); 1295 1295 if (symvalue > ULEV(rodataHdr.sh_size)) 1296 throw Exception("KernelHeader offset out of range");1296 throw BinException("KernelHeader offset out of range"); 1297 1297 if (usumGt(symvalue, symsize, ULEV(rodataHdr.sh_size))) 1298 throw Exception("KernelHeader offset+size out of range");1298 throw BinException("KernelHeader offset+size out of range"); 1299 1299 1300 1300 // kernel name preceded by '__OpenCL_' and precedes '_kernel' … … 1320 1320 innerBinaryMap.end(), name); 1321 1321 if (it == innerBinaryMap.end()) 1322 throw Exception("Can't find inner binary");1322 throw BinException("Can't find inner binary"); 1323 1323 return innerBinaries[it->second]; 1324 1324 } … … 1330 1330 kernelHeaderMap.end(), name); 1331 1331 if (it == kernelHeaderMap.end()) 1332 throw Exception("Can't find kernel header");1332 throw BinException("Can't find kernel header"); 1333 1333 return kernelHeaders[it->second]; 1334 1334 } … … 1383 1383 { return l.elfMachine < r.elfMachine;}) - gpuDeviceCodeTable; 1384 1384 if (gpuDeviceCodeTableSize == index) 1385 throw Exception("Can't determine GPU device type");1385 throw BinException("Can't determine GPU device type"); 1386 1386 return gpuDeviceCodeTable[index].deviceType; 1387 1387 } … … 1453 1453 compileOptionShIndex = ULEV(sym.st_shndx); 1454 1454 if (compileOptionShIndex >= getSectionHeadersNum()) 1455 throw Exception("CompileOptions section index out of range");1455 throw BinException("CompileOptions section index out of range"); 1456 1456 const Elf32_Shdr& shdr = getSectionHeader(compileOptionShIndex); 1457 1457 const char* sectionContent = reinterpret_cast<char*>( 1458 1458 getSectionContent(compileOptionShIndex)); 1459 1459 if (ULEV(sym.st_value) >= ULEV(shdr.sh_size)) 1460 throw Exception("CompileOptions value out of range");1460 throw BinException("CompileOptions value out of range"); 1461 1461 // compileOptionsEnd used later for setting offset for driver info 1462 1462 // compile options precedes driver info 1463 1463 compileOptionsEnd = ULEV(sym.st_value) + ULEV(sym.st_size); 1464 1464 if (usumGt(ULEV(sym.st_value), ULEV(sym.st_size), ULEV(shdr.sh_size))) 1465 throw Exception("CompileOptions value+size out of range");1465 throw BinException("CompileOptions value+size out of range"); 1466 1466 compileOptions.assign(sectionContent + ULEV(sym.st_value), 1467 1467 ULEV(sym.st_size)); … … 1537 1537 compileOptionShIndex = ULEV(sym.st_shndx); 1538 1538 if (compileOptionShIndex >= getSectionHeadersNum()) 1539 throw Exception("CompileOptions section index out of range");1539 throw BinException("CompileOptions section index out of range"); 1540 1540 const Elf64_Shdr& shdr = getSectionHeader(compileOptionShIndex); 1541 1541 const char* sectionContent = reinterpret_cast<char*>( 1542 1542 getSectionContent(compileOptionShIndex)); 1543 1543 if (ULEV(sym.st_value) >= ULEV(shdr.sh_size)) 1544 throw Exception("CompileOptions value out of range");1544 throw BinException("CompileOptions value out of range"); 1545 1545 // compileOptionsEnd used later for setting offset for driver info 1546 1546 // compile options precedes driver info 1547 1547 compileOptionsEnd = ULEV(sym.st_value) + ULEV(sym.st_size); 1548 1548 if (usumGt(ULEV(sym.st_value), ULEV(sym.st_size), ULEV(shdr.sh_size))) 1549 throw Exception("CompileOptions value+size out of range");1549 throw BinException("CompileOptions value+size out of range"); 1550 1550 compileOptions.assign(sectionContent + ULEV(sym.st_value), 1551 1551 ULEV(sym.st_size)); … … 1607 1607 if (binaryCodeSize < sizeof(Elf32_Ehdr) || 1608 1608 ULEV(*reinterpret_cast<const uint32_t*>(binaryCode)) != elfMagicValue) 1609 throw Exception("This is not ELF binary");1609 throw BinException("This is not ELF binary"); 1610 1610 if (binaryCode[EI_DATA] != ELFDATA2LSB) 1611 throw Exception("Other than little-endian binaries are not supported!");1611 throw BinException("Other than little-endian binaries are not supported!"); 1612 1612 1613 1613 // checking binary class … … 1627 1627 } 1628 1628 else // fatal error 1629 throw Exception("Unsupported ELF class");1630 } 1629 throw BinException("Unsupported ELF class"); 1630 } -
CLRadeonExtender/trunk/amdbin/AmdCL2BinGen.cpp
r3444 r3457 427 427 TempAmdCL2KernelData& tempData = tempDatas[i]; 428 428 if (newBinaries && (kernel.isaMetadataSize!=0 || kernel.isaMetadata!=nullptr)) 429 throw Exception("ISA metadata allowed for old driver binaries");429 throw BinGenException("ISA metadata allowed for old driver binaries"); 430 430 if (newBinaries && (kernel.stubSize!=0 || kernel.stub!=nullptr)) 431 throw Exception("Kernel stub allowed for old driver binaries");431 throw BinGenException("Kernel stub allowed for old driver binaries"); 432 432 /* check relocations */ 433 433 if (newBinaries) … … 435 435 { 436 436 if (rel.type > RELTYPE_HIGH_32BIT || rel.symbol > 2) 437 throw Exception("Wrong relocation symbol or type");437 throw BinGenException("Wrong relocation symbol or type"); 438 438 if (rel.offset+4 > kernel.codeSize) 439 throw Exception("Relocation offset outside code size");439 throw BinGenException("Relocation offset outside code size"); 440 440 } 441 441 … … 505 505 { 506 506 if (inarg.resId >= 16) 507 throw Exception("SamplerId out of range!");507 throw BinGenException("SamplerId out of range!"); 508 508 if (samplerMask[inarg.resId]) 509 throw Exception("SamplerId already used!");509 throw BinGenException("SamplerId already used!"); 510 510 samplerMask.set(inarg.resId); 511 511 tempData.argResIds[k] = inarg.resId; … … 518 518 { 519 519 if (inarg.resId >= 128) 520 throw Exception("RdOnlyImgId out of range!");520 throw BinGenException("RdOnlyImgId out of range!"); 521 521 if (imgRoMask[inarg.resId]) 522 throw Exception("RdOnlyImgId already used!");522 throw BinGenException("RdOnlyImgId already used!"); 523 523 imgRoMask.set(inarg.resId); 524 524 tempData.argResIds[k] = inarg.resId; … … 527 527 { 528 528 if (inarg.resId >= 64) 529 throw Exception("WrOnlyImgId out of range!");529 throw BinGenException("WrOnlyImgId out of range!"); 530 530 if (imgWoMask[inarg.resId]) 531 throw Exception("WrOnlyImgId already used!");531 throw BinGenException("WrOnlyImgId already used!"); 532 532 imgWoMask.set(inarg.resId); 533 533 tempData.argResIds[k] = inarg.resId; … … 537 537 // read-write images 538 538 if (inarg.resId >= 64) 539 throw Exception("RdWrImgId out of range!");539 throw BinGenException("RdWrImgId out of range!"); 540 540 if (imgRWMask[inarg.resId]) 541 throw Exception("RdWrImgId already used!");541 throw BinGenException("RdWrImgId already used!"); 542 542 imgRWMask.set(inarg.resId); 543 543 tempData.argResIds[k] = inarg.resId; … … 562 562 samplerCount++); 563 563 if (samplerCount == 16) 564 throw Exception("SamplerId out of range!");564 throw BinGenException("SamplerId out of range!"); 565 565 tempData.argResIds[k] = samplerCount++; 566 566 } … … 573 573 for (; imgRoCount < 128 && imgRoMask[imgRoCount]; imgRoCount++); 574 574 if (imgRoCount == 128) 575 throw Exception("RdOnlyImgId out of range!");575 throw BinGenException("RdOnlyImgId out of range!"); 576 576 tempData.argResIds[k] = imgRoCount++; 577 577 } … … 580 580 for (; imgWoCount < 64 && imgWoMask[imgWoCount]; imgWoCount++); 581 581 if (imgWoCount == 64) 582 throw Exception("WrOnlyImgId out of range!");582 throw BinGenException("WrOnlyImgId out of range!"); 583 583 tempData.argResIds[k] = imgWoCount++; 584 584 } … … 587 587 for (; imgRWCount < 64 && imgRWMask[imgRWCount]; imgRWCount++); 588 588 if (imgRWCount == 128) 589 throw Exception("RdWrImgId out of range!");589 throw BinGenException("RdWrImgId out of range!"); 590 590 tempData.argResIds[k] = imgRWCount++; 591 591 } … … 597 597 for (cxuint sampler: kernel.config.samplers) 598 598 if (sampler >= samplersNum) 599 throw Exception("SamplerId out of range");599 throw BinGenException("SamplerId out of range"); 600 600 601 601 tempData.metadataSize = out; … … 2056 2056 const GPUArchitecture arch = getGPUArchitectureFromDeviceType(input->deviceType); 2057 2057 if (arch == GPUArchitecture::GCN1_0) 2058 throw Exception("OpenCL 2.0 supported only for GCN1.1 or later");2058 throw BinGenException("OpenCL 2.0 supported only for GCN1.1 or later"); 2059 2059 2060 2060 const bool is16_3Ver = (input->driverVersion>=200406); … … 2071 2071 2072 2072 if ((hasGlobalData || hasRWData || hasSamplers) && !newBinaries) 2073 throw Exception("Old driver binaries doesn't support "2073 throw BinGenException("Old driver binaries doesn't support " 2074 2074 "global/atomic data or samplers"); 2075 2075 … … 2077 2077 { 2078 2078 if (!hasGlobalData && hasSamplers) 2079 throw Exception("Global data must be defined if samplers present");2079 throw BinGenException("Global data must be defined if samplers present"); 2080 2080 // check sampler offset range 2081 2081 for (size_t sampOffset: input->samplerOffsets) 2082 2082 if (sampOffset+8 > input->globalDataSize) 2083 throw Exception("Sampler offset outside global data");2083 throw BinGenException("Sampler offset outside global data"); 2084 2084 } 2085 2085 /* check samplers */ … … 2087 2087 (input->samplerInitSize>>3); 2088 2088 if (!input->samplerOffsets.empty() && input->samplerOffsets.size() != samplersNum) 2089 throw Exception("SamplerOffset number doesn't match to samplers number");2089 throw BinGenException("SamplerOffset number doesn't match to samplers number"); 2090 2090 2091 2091 for (size_t sampOffset: input->samplerOffsets) 2092 2092 if ((sampOffset&7) != 0 && sampOffset >= input->globalDataSize) 2093 throw Exception("Wrong sampler offset (out of range of unaligned)");2093 throw BinGenException("Wrong sampler offset (out of range of unaligned)"); 2094 2094 2095 2095 const bool gpuProDriver = (input->driverVersion == 203603 || … … 2108 2108 // if GPU type is not supported by driver version 2109 2109 if (deviceCodeTable[cxuint(input->deviceType)] == UINT_MAX) 2110 throw Exception("Unsupported GPU device type by driver version");2110 throw BinGenException("Unsupported GPU device type by driver version"); 2111 2111 2112 2112 std::unique_ptr<ElfBinaryGen32> elfBinGen32; … … 2198 2198 for (const AmdCL2RelInput& rel: kernel.relocations) 2199 2199 if (rel.offset >= kernel.codeSize) 2200 throw Exception("Kernel text relocation offset outside kernel code");2200 throw BinGenException("Kernel text relocation offset outside kernel code"); 2201 2201 2202 2202 std::fill(innerBinSectionTable, … … 2462 2462 #endif 2463 2463 binarySize > UINT32_MAX) 2464 throw Exception("Binary size is too big!");2464 throw BinGenException("Binary size is too big!"); 2465 2465 /**** 2466 2466 * prepare for write binary to output -
CLRadeonExtender/trunk/amdbin/AmdCL2Binaries.cpp
r3419 r3457 43 43 kernelDataMap.begin(), kernelDataMap.end(), name); 44 44 if (it == kernelDataMap.end()) 45 throw Exception("Can't find kernel name");45 throw BinException("Can't find kernel name"); 46 46 return kernels[it->second]; 47 47 } … … 91 91 /// check conditions for symbol 92 92 if (textIndex != ULEV(sym.st_shndx)) 93 throw Exception("Kernel symbol outside text section");93 throw BinException("Kernel symbol outside text section"); 94 94 if (binOffset >= binaryCodeSize) 95 throw Exception("Kernel binary code offset out of range");95 throw BinException("Kernel binary code offset out of range"); 96 96 if (usumGt(binOffset, binSize, binaryCodeSize)) 97 throw Exception("Kernel binary code offset and size out of range");97 throw BinException("Kernel binary code offset and size out of range"); 98 98 if (binSize < 256+192) 99 throw Exception("Kernel binary code size is too short");99 throw BinException("Kernel binary code size is too short"); 100 100 101 101 AmdCL2GPUKernelStub kernelStub; … … 105 105 const size_t setupOffset = ULEV(*reinterpret_cast<uint32_t*>(kernelStub.data)); 106 106 if (setupOffset >= binSize) 107 throw Exception("Kernel setup offset out of range");107 throw BinException("Kernel setup offset out of range"); 108 108 // get size of setup (offset 16 of setup) 109 109 kernelStub.size = setupOffset; … … 112 112 const size_t textOffset = ULEV(*reinterpret_cast<uint32_t*>(kernelData.setup+16)); 113 113 if (usumGe(textOffset, setupOffset, binSize)) 114 throw Exception("Kernel text offset out of range");114 throw BinException("Kernel text offset out of range"); 115 115 kernelData.setupSize = textOffset; 116 116 kernelData.code = kernelData.setup + textOffset; … … 140 140 kernelDataMap.begin(), kernelDataMap.end(), name); 141 141 if (it == kernelDataMap.end()) 142 throw Exception("Can't find kernel name");142 throw BinException("Can't find kernel name"); 143 143 return kernelStubs[it->second]; 144 144 } … … 180 180 const Elf64_Shdr& dataShdr = getSectionHeader(ULEV(sym.st_shndx)); 181 181 if (ULEV(sym.st_shndx) >= getSectionHeadersNum()) 182 throw Exception("Kernel section index out of range");182 throw BinException("Kernel section index out of range"); 183 183 const char* symName = getSymbolName(index); 184 184 const size_t binOffset = ULEV(sym.st_value); … … 186 186 /// check conditions for symbol 187 187 if (binOffset >= ULEV(dataShdr.sh_size)) 188 throw Exception("Kernel binary code offset out of range");188 throw BinException("Kernel binary code offset out of range"); 189 189 if (usumGt(binOffset, binSize, ULEV(dataShdr.sh_size))) 190 throw Exception("Kernel binary code offset and size out of range");190 throw BinException("Kernel binary code offset and size out of range"); 191 191 if (binSize < 192) 192 throw Exception("Kernel binary code size is too short");192 throw BinException("Kernel binary code size is too short"); 193 193 194 194 kernels[ki].setup = binaryCode + ULEV(dataShdr.sh_offset) + binOffset; … … 198 198 199 199 if (textOffset >= binSize) 200 throw Exception("Kernel text offset out of range");200 throw BinException("Kernel text offset out of range"); 201 201 kernels[ki].setupSize = textOffset; 202 202 kernels[ki].code = kernels[ki].setup + textOffset; … … 339 339 crimson16 = false; 340 340 if (metadataSize < 8+32+32) 341 throw Exception("Kernel metadata is too short");341 throw BinException("Kernel metadata is too short"); 342 342 343 343 const typename Types::MetadataHeader* hdrStruc = … … 346 346 // checking kernel header size in metadata region 347 347 if (kernelHeader.size >= metadataSize) 348 throw Exception("Metadata header size out of range");348 throw BinException("Metadata header size out of range"); 349 349 if (kernelHeader.size < sizeof(typename Types::MetadataHeader)) 350 throw Exception("Metadata header is too short");350 throw BinException("Metadata header is too short"); 351 351 kernelHeader.data = metadata; 352 352 const uint32_t argsNum = ULEV(hdrStruc->argsNum); … … 354 354 if (usumGt(ULEV(hdrStruc->firstNameLength), ULEV(hdrStruc->secondNameLength), 355 355 metadataSize-kernelHeader.size-2)) 356 throw Exception("KernelArgEntries offset out of range");356 throw BinException("KernelArgEntries offset out of range"); 357 357 358 358 size_t argOffset = kernelHeader.size + … … 369 369 370 370 if(usumGt(argOffset, sizeof(typename Types::KernelArgEntry)*(argsNum+1), metadataSize)) 371 throw Exception("Number of arguments out of range");371 throw BinException("Number of arguments out of range"); 372 372 373 373 const char* strBase = (const char*)metadata; … … 379 379 AmdKernelArg& arg = kernelInfo.argInfos[i]; 380 380 if (ULEV(argPtr->size)!=sizeof(typename Types::KernelArgEntry)) 381 throw Exception("Kernel ArgEntry size doesn't match");381 throw BinException("Kernel ArgEntry size doesn't match"); 382 382 // get name of argument 383 383 size_t nameSize = ULEV(argPtr->argNameSize); 384 384 if (usumGt(strOffset, nameSize+1, metadataSize)) 385 throw Exception("Kernel ArgEntry name size out of range");385 throw BinException("Kernel ArgEntry name size out of range"); 386 386 arg.argName.assign(strBase+strOffset, nameSize); 387 387 // get name of type of argument … … 389 389 nameSize = ULEV(argPtr->typeNameSize); 390 390 if (usumGt(strOffset, nameSize+1, metadataSize)) 391 throw Exception("Kernel ArgEntry typename size out of range");391 throw BinException("Kernel ArgEntry typename size out of range"); 392 392 arg.typeName.assign(strBase+strOffset, nameSize); 393 393 strOffset += nameSize+1; … … 407 407 case 0: 408 408 if (kindOfType!=1) // not sampler 409 throw Exception("Wrong kernel argument type");409 throw BinException("Wrong kernel argument type"); 410 410 arg.argType = KernelArgType::SAMPLER; 411 411 break; … … 423 423 { 424 424 if (kindOfType!=4) // not scalar 425 throw Exception("Wrong kernel argument type");425 throw BinException("Wrong kernel argument type"); 426 426 arg.argType = (argType==3) ? 427 427 KernelArgType::SHORT : KernelArgType::CHAR; 428 428 } 429 429 else 430 throw Exception("Wrong kernel argument type");430 throw BinException("Wrong kernel argument type"); 431 431 break; 432 432 case 4: // int 433 433 case 5: // long 434 434 if (kindOfType!=4) // not scalar 435 throw Exception("Wrong kernel argument type");435 throw BinException("Wrong kernel argument type"); 436 436 arg.argType = (argType==5) ? 437 437 KernelArgType::LONG : KernelArgType::INT; … … 445 445 { 446 446 if (kindOfType!=4) // not scalar 447 throw Exception("Wrong kernel argument type");447 throw BinException("Wrong kernel argument type"); 448 448 const cxuint vectorId = vectorIdTable[vectorSize]; 449 449 if (vectorId == UINT_MAX) 450 throw Exception("Wrong vector size");450 throw BinException("Wrong vector size"); 451 451 arg.argType = cl20ArgTypeVectorTable[(argType-6)*6 + vectorId]; 452 452 break; … … 454 454 case 15: 455 455 if (kindOfType!=4) // not scalar 456 throw Exception("Wrong kernel argument type");456 throw BinException("Wrong kernel argument type"); 457 457 arg.argType = KernelArgType::STRUCTURE; 458 458 break; 459 459 case 18: 460 460 if (kindOfType!=7) // not scalar 461 throw Exception("Wrong kernel argument type");461 throw BinException("Wrong kernel argument type"); 462 462 arg.argType = KernelArgType::CMDQUEUE; 463 463 break; 464 464 default: 465 throw Exception("Wrong kernel argument type");465 throw BinException("Wrong kernel argument type"); 466 466 break; 467 467 } … … 484 484 arg.ptrSpace = KernelPtrSpace::CONSTANT; 485 485 else 486 throw Exception("Illegal pointer space");486 throw BinException("Illegal pointer space"); 487 487 // set access qualifiers (volatile, restrict, const) 488 488 arg.ptrAccess = KARG_PTR_NORMAL; … … 498 498 // global space for pipe 499 499 if (ptrSpace!=4) 500 throw Exception("Illegal pipe space");500 throw BinException("Illegal pipe space"); 501 501 arg.ptrSpace = KernelPtrSpace::GLOBAL; 502 502 } … … 531 531 auto it = binaryMapFind(kernelInfosMap.begin(), kernelInfosMap.end(), name); 532 532 if (it == kernelInfosMap.end()) 533 throw Exception("Can't find kernel metadata by name");533 throw BinException("Can't find kernel metadata by name"); 534 534 return metadatas[it->second]; 535 535 } … … 540 540 auto it = binaryMapFind(isaMetadataMap.begin(), isaMetadataMap.end(), name); 541 541 if (it == isaMetadataMap.end()) 542 throw Exception("Can't find kernel ISA metadata by name");542 throw BinException("Can't find kernel ISA metadata by name"); 543 543 return isaMetadatas[it->second]; 544 544 } … … 566 566 const typename Types::Sym& sym = elfBin.getSymbol(i); 567 567 if (ULEV(sym.st_shndx) >= elfBin.getSectionHeadersNum()) 568 throw Exception("Compiler options section header out of range");568 throw BinException("Compiler options section header out of range"); 569 569 const typename Types::Shdr& shdr = 570 570 elfBin.getSectionHeader(ULEV(sym.st_shndx)); … … 573 573 // checking compile options offset and size 574 574 if (coOffset >= ULEV(shdr.sh_size)) 575 throw Exception("Compiler options offset out of range");575 throw BinException("Compiler options offset out of range"); 576 576 if (usumGt(coOffset, coSize, ULEV(shdr.sh_size))) 577 throw Exception("Compiler options offset and size out of range");577 throw BinException("Compiler options offset and size out of range"); 578 578 579 579 const char* coData = reinterpret_cast<const char*>(binaryCode) + … … 586 586 const typename Types::Sym& sym = elfBin.getSymbol(i); 587 587 if (ULEV(sym.st_shndx) >= elfBin.getSectionHeadersNum()) 588 throw Exception("AclVersionString section header out of range");588 throw BinException("AclVersionString section header out of range"); 589 589 const typename Types::Shdr& shdr = 590 590 elfBin.getSectionHeader(ULEV(sym.st_shndx)); … … 593 593 // checking acl offset and acl size 594 594 if (aclOffset >= ULEV(shdr.sh_size)) 595 throw Exception("AclVersionString offset out of range");595 throw BinException("AclVersionString offset out of range"); 596 596 if (usumGt(aclOffset, aclSize, ULEV(shdr.sh_size))) 597 throw Exception("AclVersionString offset and size out of range");597 throw BinException("AclVersionString offset and size out of range"); 598 598 599 599 const char* aclVersionData = reinterpret_cast<const char*>(binaryCode) + … … 681 681 const char* mtName = elfBin.getSymbolName(index); 682 682 if (ULEV(mtsym.st_shndx) >= elfBin.getSectionHeadersNum()) 683 throw Exception("Kernel Metadata section header out of range");683 throw BinException("Kernel Metadata section header out of range"); 684 684 const typename Types::Shdr& shdr = 685 685 elfBin.getSectionHeader(ULEV(mtsym.st_shndx)); … … 688 688 /// offset and size verifying 689 689 if (mtOffset >= ULEV(shdr.sh_size)) 690 throw Exception("Kernel Metadata offset out of range");690 throw BinException("Kernel Metadata offset out of range"); 691 691 if (usumGt(mtOffset, mtSize, ULEV(shdr.sh_size))) 692 throw Exception("Kernel Metadata offset and size out of range");692 throw BinException("Kernel Metadata offset and size out of range"); 693 693 694 694 cxbyte* metadata = binaryCode + ULEV(shdr.sh_offset) + mtOffset; … … 715 715 const char* mtName = elfBin.getSymbolName(index); 716 716 if (ULEV(mtsym.st_shndx) >= elfBin.getSectionHeadersNum()) 717 throw Exception("Kernel ISAMetadata section header out of range");717 throw BinException("Kernel ISAMetadata section header out of range"); 718 718 const typename Types::Shdr& shdr = 719 719 elfBin.getSectionHeader(ULEV(mtsym.st_shndx)); … … 722 722 /// offset and size verifying 723 723 if (mtOffset >= ULEV(shdr.sh_size)) 724 throw Exception("Kernel ISAMetadata offset out of range");724 throw BinException("Kernel ISAMetadata offset out of range"); 725 725 if (usumGt(mtOffset, mtSize, ULEV(shdr.sh_size))) 726 throw Exception("Kernel ISAMetadata offset and size out of range");726 throw BinException("Kernel ISAMetadata offset and size out of range"); 727 727 728 728 cxbyte* metadata = binaryCode + ULEV(shdr.sh_offset) + mtOffset; … … 956 956 const cxbyte* noteContent = (const cxbyte*)innerBin.getNotes(); 957 957 if (noteContent==nullptr) 958 throw Exception("Missing notes in inner binary!");958 throw BinException("Missing notes in inner binary!"); 959 959 size_t notesSize = innerBin.getNotesSize(); 960 960 // find note about AMDGPU … … 966 966 size_t descsz = ULEV(nhdr->n_descsz); 967 967 if (usumGt(offset, namesz+descsz, notesSize)) 968 throw Exception("Note offset+size out of range");968 throw BinException("Note offset+size out of range"); 969 969 if (ULEV(nhdr->n_type) == 0x3 && namesz==4 && descsz>=0x1a && 970 970 ::strcmp((const char*)noteContent+offset+ … … 979 979 if ((arch==GPUArchitecture::GCN1_2 && major<8) || 980 980 (arch==GPUArchitecture::GCN1_1 && major!=7)) 981 throw Exception("Wrong arch major for GPU architecture");981 throw BinException("Wrong arch major for GPU architecture"); 982 982 // fix for GFX900 - we don't know what is type of device 983 983 if (arch==GPUArchitecture::GCN1_2 && major!=8) … … 985 985 } 986 986 else if (major != 9 && major != 8 && major != 7) 987 throw Exception("Unknown arch major");987 throw BinException("Unknown arch major"); 988 988 989 989 archMinor = ULEV(content[2]); … … 1009 1009 1010 1010 if (!knownGPUType) 1011 throw Exception("Can't determine GPU device type");1011 throw BinException("Can't determine GPU device type"); 1012 1012 1013 1013 outArchMinor = archMinor; -
CLRadeonExtender/trunk/amdbin/ElfBinaries.cpp
r3418 r3457 41 41 using namespace CLRX; 42 42 43 // BinException costuctor 44 BinException::BinException(const std::string& message) : Exception(message) 45 { } 46 47 // BinGenException costuctor 48 BinGenException::BinGenException(const std::string& message) : Exception(message) 49 { } 50 43 51 /* determine unfinished strings region in string table for checking further consistency */ 44 52 static size_t unfinishedRegionOfStringTable(const cxbyte* table, size_t size) … … 90 98 { 91 99 if (binaryCodeSize < sizeof(typename Types::Ehdr)) 92 throw Exception("Binary is too small!!!");100 throw BinException("Binary is too small!!!"); 93 101 94 102 const typename Types::Ehdr* ehdr = … … 97 105 // checking ELF magic, ELFCLASS and endian (only little-endian accepted) 98 106 if (ULEV(*reinterpret_cast<const uint32_t*>(binaryCode)) != elfMagicValue) 99 throw Exception("This is not ELF binary");107 throw BinException("This is not ELF binary"); 100 108 if (ehdr->e_ident[EI_CLASS] != Types::ELFCLASS) 101 throw Exception(std::string("This is not ")+Types::bitName+"bit ELF binary");109 throw BinException(std::string("This is not ")+Types::bitName+"bit ELF binary"); 102 110 if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) 103 throw Exception("Other than little-endian binaries are not supported!");111 throw BinException("Other than little-endian binaries are not supported!"); 104 112 105 113 if ((ULEV(ehdr->e_phoff) == 0 && ULEV(ehdr->e_phnum) != 0)) 106 throw Exception("Elf invalid phoff and phnum combination");114 throw BinException("Elf invalid phoff and phnum combination"); 107 115 if (ULEV(ehdr->e_phoff) != 0) 108 116 { 109 117 /* reading and checking program headers */ 110 118 if (ULEV(ehdr->e_phoff) > binaryCodeSize) 111 throw Exception("ProgramHeaders offset out of range!");119 throw BinException("ProgramHeaders offset out of range!"); 112 120 if (usumGt(ULEV(ehdr->e_phoff), 113 121 ((typename Types::Word)ULEV(ehdr->e_phentsize))*ULEV(ehdr->e_phnum), 114 122 binaryCodeSize)) 115 throw Exception("ProgramHeaders offset+size out of range!");123 throw BinException("ProgramHeaders offset+size out of range!"); 116 124 117 125 cxuint phnum = ULEV(ehdr->e_phnum); … … 121 129 const typename Types::Phdr& phdr = getProgramHeader(i); 122 130 if (ULEV(phdr.p_offset) > binaryCodeSize) 123 throw Exception("Segment offset out of range!");131 throw BinException("Segment offset out of range!"); 124 132 if (usumGt(ULEV(phdr.p_offset), ULEV(phdr.p_filesz), binaryCodeSize)) 125 throw Exception("Segment offset+size out of range!");133 throw BinException("Segment offset+size out of range!"); 126 134 } 127 135 } 128 136 129 137 if ((ULEV(ehdr->e_shoff) == 0 && ULEV(ehdr->e_shnum) != 0)) 130 throw Exception("Elf invalid shoff and shnum combination");138 throw BinException("Elf invalid shoff and shnum combination"); 131 139 if (ULEV(ehdr->e_shoff) != 0 && ULEV(ehdr->e_shstrndx) != SHN_UNDEF) 132 140 { 133 141 /* indexing of sections */ 134 142 if (ULEV(ehdr->e_shoff) > binaryCodeSize) 135 throw Exception("SectionHeaders offset out of range!");143 throw BinException("SectionHeaders offset out of range!"); 136 144 if (usumGt(ULEV(ehdr->e_shoff), 137 145 ((typename Types::Word)ULEV(ehdr->e_shentsize))*ULEV(ehdr->e_shnum), 138 146 binaryCodeSize)) 139 throw Exception("SectionHeaders offset+size out of range!");147 throw BinException("SectionHeaders offset+size out of range!"); 140 148 if (ULEV(ehdr->e_shstrndx) >= ULEV(ehdr->e_shnum)) 141 throw Exception("Shstrndx out of range!");149 throw BinException("Shstrndx out of range!"); 142 150 143 151 typename Types::Shdr& shstrShdr = getSectionHeader(ULEV(ehdr->e_shstrndx)); … … 159 167 /// checking section offset ranges 160 168 if (ULEV(shdr.sh_offset) > binaryCodeSize) 161 throw Exception("Section offset out of range!");169 throw BinException("Section offset out of range!"); 162 170 if (ULEV(shdr.sh_type) != SHT_NOBITS) 163 171 if (usumGt(ULEV(shdr.sh_offset), ULEV(shdr.sh_size), binaryCodeSize)) 164 throw Exception("Section offset+size out of range!");172 throw BinException("Section offset+size out of range!"); 165 173 if (ULEV(shdr.sh_link) >= ULEV(ehdr->e_shnum)) 166 throw Exception("Section link out of range!");174 throw BinException("Section link out of range!"); 167 175 168 176 const typename Types::Size sh_nameindx = ULEV(shdr.sh_name); 169 177 if (sh_nameindx >= ULEV(shstrShdr.sh_size)) 170 throw Exception("Section name index out of range!");178 throw BinException("Section name index out of range!"); 171 179 172 180 if (sh_nameindx >= unfinishedShstrPos) 173 throw Exception("Unfinished section name!");181 throw BinException("Unfinished section name!"); 174 182 175 183 const char* shname = … … 196 204 // indexing symbols 197 205 if (ULEV(symTableHdr->sh_entsize) < sizeof(typename Types::Sym)) 198 throw Exception("SymTable entry size is too small!");206 throw BinException("SymTable entry size is too small!"); 199 207 200 208 symbolEntSize = ULEV(symTableHdr->sh_entsize); 201 209 symbolTable = binaryCode + ULEV(symTableHdr->sh_offset); 202 210 if (ULEV(symTableHdr->sh_link) == SHN_UNDEF) 203 throw Exception("Symbol table doesn't have string table");211 throw BinException("Symbol table doesn't have string table"); 204 212 205 213 typename Types::Shdr& symstrShdr = getSectionHeader(ULEV(symTableHdr->sh_link)); … … 218 226 const typename Types::Size symnameindx = ULEV(sym.st_name); 219 227 if (symnameindx >= ULEV(symstrShdr.sh_size)) 220 throw Exception("Symbol name index out of range!");228 throw BinException("Symbol name index out of range!"); 221 229 // check whether name is finished in string section content 222 230 if (symnameindx >= unfinishedSymstrPos) 223 throw Exception("Unfinished symbol name!");231 throw BinException("Unfinished symbol name!"); 224 232 225 233 const char* symname = … … 237 245 // indexing dynamic symbols 238 246 if (ULEV(dynSymTableHdr->sh_entsize) < sizeof(typename Types::Sym)) 239 throw Exception("DynSymTable entry size is too small!");247 throw BinException("DynSymTable entry size is too small!"); 240 248 241 249 dynSymEntSize = ULEV(dynSymTableHdr->sh_entsize); 242 250 dynSymTable = binaryCode + ULEV(dynSymTableHdr->sh_offset); 243 251 if (ULEV(dynSymTableHdr->sh_link) == SHN_UNDEF) 244 throw Exception("DynSymbol table doesn't have string table");252 throw BinException("DynSymbol table doesn't have string table"); 245 253 246 254 typename Types::Shdr& dynSymstrShdr = … … 261 269 const typename Types::Size symnameindx = ULEV(sym.st_name); 262 270 if (symnameindx >= ULEV(dynSymstrShdr.sh_size)) 263 throw Exception("DynSymbol name index out of range!");271 throw BinException("DynSymbol name index out of range!"); 264 272 // check whether name is finished in string section content 265 273 if (symnameindx >= unfinishedSymstrPos) 266 throw Exception("Unfinished dynsymbol name!");274 throw BinException("Unfinished dynsymbol name!"); 267 275 268 276 const char* symname = … … 287 295 const typename Types::Size size = ULEV(dynamicTableHdr->sh_size); 288 296 if (entSize < sizeof(typename Types::Dyn)) 289 throw Exception("Size of dynamic entry is too small!");297 throw BinException("Size of dynamic entry is too small!"); 290 298 if (size % entSize != 0) 291 throw Exception("Size of dynamic section is not match!");299 throw BinException("Size of dynamic section is not match!"); 292 300 dynamicsNum = entSize / size; 293 301 dynamicEntSize = entSize; … … 305 313 sectionIndexMap.begin(), sectionIndexMap.end(), name, CStringLess()); 306 314 if (it == sectionIndexMap.end()) 307 throw Exception(std::string("Can't find Elf")+Types::bitName+" Section");315 throw BinException(std::string("Can't find Elf")+Types::bitName+" Section"); 308 316 return it->second; 309 317 } … … 316 324 return i; 317 325 } 318 throw Exception(std::string("Can't find Elf")+Types::bitName+" Section");326 throw BinException(std::string("Can't find Elf")+Types::bitName+" Section"); 319 327 } 320 328 } … … 326 334 symbolIndexMap.begin(), symbolIndexMap.end(), name, CStringLess()); 327 335 if (it == symbolIndexMap.end()) 328 throw Exception(std::string("Can't find Elf")+Types::bitName+" Symbol");336 throw BinException(std::string("Can't find Elf")+Types::bitName+" Symbol"); 329 337 return it->second; 330 338 } … … 336 344 dynSymIndexMap.begin(), dynSymIndexMap.end(), name, CStringLess()); 337 345 if (it == dynSymIndexMap.end()) 338 throw Exception(std::string("Can't find Elf")+Types::bitName+" DynSymbol");346 throw BinException(std::string("Can't find Elf")+Types::bitName+" DynSymbol"); 339 347 return it->second; 340 348 } … … 379 387 const uint16_t shndx = builtinSections[sectionIndex-ELFSECTID_START]; 380 388 if (shndx == SHN_UNDEF) // if table entry for sectionIndex is not defined 381 throw Exception("Wrong BinSection:sectionId");389 throw BinGenException("Wrong BinSection:sectionId"); 382 390 return builtinSections[sectionIndex-ELFSECTID_START]; 383 391 } 384 392 else // failed 385 throw Exception("Wrong BinSection:sectionId");393 throw BinGenException("Wrong BinSection:sectionId"); 386 394 } 387 395 … … 499 507 /* verify data */ 500 508 if (header.entryRegion != UINT_MAX && header.entryRegion >= regions.size()) 501 throw Exception("Header entry region out of range");509 throw BinGenException("Header entry region out of range"); 502 510 503 511 regionOffsets.reset(new typename Types::Word[regions.size()]); … … 541 549 } 542 550 else 543 throw Exception("Wrong Hash Sym section!");551 throw BinGenException("Wrong Hash Sym section!"); 544 552 } 545 553 sectionCount++; 546 554 } 547 555 if (!hashSymDetected) 548 throw Exception("Wrong Hash Sym is not detected!");556 throw BinGenException("Wrong Hash Sym is not detected!"); 549 557 } 550 558 … … 567 575 if (sym.sectionIndex >= sectionsNum && sym.sectionIndex!=SHN_ABS && 568 576 sym.sectionIndex!=SHN_UNDEF) 569 throw Exception("Symbol section index out of range");577 throw BinGenException("Symbol section index out of range"); 570 578 for (const auto& sym: dynSymbols) 571 579 if (sym.sectionIndex >= sectionsNum && sym.sectionIndex!=SHN_ABS && 572 580 sym.sectionIndex!=SHN_UNDEF) 573 throw Exception("DynSymbol section index out of range");581 throw BinGenException("DynSymbol section index out of range"); 574 582 575 583 for (size_t i = 0; i < regions.size(); i++) … … 598 606 if (progHdr.regionStart!=PHREGION_FILESTART && 599 607 progHdr.regionStart >= regions.size()) 600 throw Exception("Region start out of range");608 throw BinGenException("Region start out of range"); 601 609 if ((progHdr.regionStart==PHREGION_FILESTART && 602 610 progHdr.regionsNum > regions.size()) || 603 611 (progHdr.regionStart!=PHREGION_FILESTART && 604 612 uint64_t(progHdr.regionStart) + progHdr.regionsNum > regions.size())) 605 throw Exception("Region end out of range");613 throw BinGenException("Region end out of range"); 606 614 } 607 615 if (addrStartRegion==PHREGION_FILESTART) … … 626 634 // if section 627 635 if (region.section.link >= sectionsNum) 628 throw Exception("Section link out of range");636 throw BinGenException("Section link out of range"); 629 637 630 638 if (haveDynamic) -
CLRadeonExtender/trunk/amdbin/GalliumBinaries.cpp
r3447 r3457 82 82 if (amdGPUConfigSize != 24 && amdGPUConfigSize != 40 && 83 83 shdrSize % amdGPUConfigSize != 0) 84 throw Exception("Wrong size of .AMDGPU.config section!");84 throw BinException("Wrong size of .AMDGPU.config section!"); 85 85 // detect whether is binary generated for LLVM >= 3.9.0 by amdGPUConfig size 86 86 llvm390 = amdGPUConfigSize==40; … … 102 102 { 103 103 if (ULEV(sym.st_value) >= textSize) 104 throw Exception("kernel symbol offset out of range");104 throw BinException("kernel symbol offset out of range"); 105 105 if (hasProgInfoMap) 106 106 progInfoEntryMap[progInfosNum] = std::make_pair(symName, … … 110 110 } 111 111 if (progInfosNum*amdGPUConfigSize != ULEV(shdr.sh_size)) 112 throw Exception("Number of symbol kernels doesn't match progInfos number!");112 throw BinException("Number of symbol kernels doesn't match progInfos number!"); 113 113 cxbyte* binaryCode = (cxbyte*)elfBinary.getBinaryCode(); 114 114 progInfoEntries = reinterpret_cast<GalliumProgInfoEntry*>(binaryCode + … … 161 161 progInfoEntryMap.end(), name, CStringLess()); 162 162 if (it == progInfoEntryMap.end()) 163 throw Exception("Can't find GalliumElf ProgInfoEntry");163 throw BinException("Can't find GalliumElf ProgInfoEntry"); 164 164 return it->second; 165 165 } … … 189 189 { symIndex = elfBinary.getSymbolIndex(kernel.kernelName.c_str()); } 190 190 catch(const Exception& ex) 191 { throw Exception("Kernel symbol not found"); }191 { throw BinException("Kernel symbol not found"); } 192 192 const auto& sym = elfBinary.getSymbol(symIndex); 193 193 const char* symName = elfBinary.getSymbolName(symIndex); … … 198 198 // names must be stored in order 199 199 if (kernel.kernelName != symName) 200 throw Exception("Kernel symbols out of order!");200 throw BinException("Kernel symbols out of order!"); 201 201 if (ULEV(sym.st_value) != kernel.offset) 202 throw Exception("Kernel symbol value and Kernel "202 throw BinException("Kernel symbol value and Kernel " 203 203 "offset doesn't match"); 204 204 } 205 205 else 206 throw Exception("Wrong section or binding for kernel symbol");206 throw BinException("Wrong section or binding for kernel symbol"); 207 207 } 208 208 } … … 215 215 { 216 216 if (binaryCodeSize < 4) 217 throw Exception("GalliumBinary is too small!!!");217 throw BinException("GalliumBinary is too small!!!"); 218 218 uint32_t* data32 = reinterpret_cast<uint32_t*>(binaryCode); 219 219 kernelsNum = ULEV(*data32); 220 220 if (binaryCodeSize < uint64_t(kernelsNum)*16U) 221 throw Exception("Kernels number is too big!");221 throw BinException("Kernels number is too big!"); 222 222 kernels.reset(new GalliumKernel[kernelsNum]); 223 223 cxbyte* data = binaryCode + 4; … … 227 227 GalliumKernel& kernel = kernels[i]; 228 228 if (usumGt(uint32_t(data-binaryCode), 4U, binaryCodeSize)) 229 throw Exception("GalliumBinary is too small!!!");229 throw BinException("GalliumBinary is too small!!!"); 230 230 231 231 const cxuint symNameLen = ULEV(*reinterpret_cast<const uint32_t*>(data)); 232 232 data+=4; 233 233 if (usumGt(uint32_t(data-binaryCode), symNameLen, binaryCodeSize)) 234 throw Exception("Kernel name length is too long!");234 throw BinException("Kernel name length is too long!"); 235 235 236 236 kernel.kernelName.assign((const char*)data, symNameLen); … … 238 238 data += symNameLen; 239 239 if (usumGt(uint32_t(data-binaryCode), 12U, binaryCodeSize)) 240 throw Exception("GalliumBinary is too small!!!");240 throw BinException("GalliumBinary is too small!!!"); 241 241 242 242 data32 = reinterpret_cast<uint32_t*>(data); … … 248 248 249 249 if (UINT32_MAX/24U < argsNum) 250 throw Exception("Number of arguments number is too high!");250 throw BinException("Number of arguments number is too high!"); 251 251 if (usumGt(uint32_t(data-binaryCode), 24U*argsNum, binaryCodeSize)) 252 throw Exception("GalliumBinary is too small!!!");252 throw BinException("GalliumBinary is too small!!!"); 253 253 254 254 kernel.argInfos.resize(argsNum); … … 259 259 // accept not known arg type by this CLRadeonExtender 260 260 if (type > 255) 261 throw Exception("Type of kernel argument out of handled range");261 throw BinException("Type of kernel argument out of handled range"); 262 262 argInfo.type = GalliumArgType(type); 263 263 argInfo.size = ULEV(data32[1]); … … 268 268 // accept not known semantic type by this CLRadeonExtender 269 269 if (semType > 255) 270 throw Exception("Semantic of kernel argument out of handled range");270 throw BinException("Semantic of kernel argument out of handled range"); 271 271 argInfo.semantic = GalliumArgSemantic(semType); 272 272 data32 += 6; … … 276 276 277 277 if (usumGt(uint32_t(data-binaryCode), 4U, binaryCodeSize)) 278 throw Exception("GalliumBinary is too small!!!");278 throw BinException("GalliumBinary is too small!!!"); 279 279 280 280 sectionsNum = ULEV(data32[0]); 281 281 if (binaryCodeSize-(data-binaryCode) < uint64_t(sectionsNum)*20U) 282 throw Exception("Sections number is too big!");282 throw BinException("Sections number is too big!"); 283 283 sections.reset(new GalliumSection[sectionsNum]); 284 284 // parse sections and their content … … 291 291 GalliumSection& section = sections[i]; 292 292 if (usumGt(uint32_t(data-binaryCode), 20U, binaryCodeSize)) 293 throw Exception("GalliumBinary is too small!!!");293 throw BinException("GalliumBinary is too small!!!"); 294 294 295 295 section.sectionId = ULEV(data32[0]); … … 297 297 // section type must be lower than 256 298 298 if (secType > 255) 299 throw Exception("Type of section out of range");299 throw BinException("Type of section out of range"); 300 300 section.type = GalliumSectionType(secType); 301 301 section.size = ULEV(data32[2]); … … 303 303 const uint32_t sizeFromHeader = ULEV(data32[4]); // from LLVM binary 304 304 if (section.size != sizeOfData-4 || section.size != sizeFromHeader) 305 throw Exception("Section size fields doesn't match itself!");305 throw BinException("Section size fields doesn't match itself!"); 306 306 307 307 data = reinterpret_cast<cxbyte*>(data32+5); 308 308 if (usumGt(uint32_t(data-binaryCode), section.size, binaryCodeSize)) 309 throw Exception("Section size is too big!!!");309 throw BinException("Section size is too big!!!"); 310 310 311 311 section.offset = data-binaryCode; … … 317 317 mesa170 = (section.type == GalliumSectionType::TEXT_EXECUTABLE_170); 318 318 if (section.size < sizeof(Elf32_Ehdr)) 319 throw Exception("Wrong GalliumElfBinary size");319 throw BinException("Wrong GalliumElfBinary size"); 320 320 const Elf32_Ehdr& ehdr = *reinterpret_cast<const Elf32_Ehdr*>(data); 321 321 if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) … … 335 335 } 336 336 else // wrong class 337 throw Exception("Wrong GalliumElfBinary class");337 throw BinException("Wrong GalliumElfBinary class"); 338 338 } 339 339 data += section.size; … … 342 342 343 343 if (!elfBinary) 344 throw Exception("Gallium Elf binary not found!");344 throw BinException("Gallium Elf binary not found!"); 345 345 for (uint32_t i = 0; i < kernelsNum; i++) 346 346 if (kernels[i].sectionId != elfSectionId) 347 throw Exception("Kernel not in text section!");347 throw BinException("Kernel not in text section!"); 348 348 // verify kernel offsets 349 349 if (!elf64BitBinary) … … 360 360 { return k1.kernelName < k2.kernelName; }); 361 361 if (it == kernels.get()+kernelsNum || it->kernelName != name) 362 throw Exception("Can't find Gallium Kernel Index");362 throw BinException("Can't find Gallium Kernel Index"); 363 363 return it-kernels.get(); 364 364 } … … 619 619 const GalliumKernelConfig& config = kernel.config; 620 620 if (config.usedVGPRsNum > maxVGPRSNum) 621 throw Exception("Used VGPRs number out of range");621 throw BinGenException("Used VGPRs number out of range"); 622 622 if (config.usedSGPRsNum > maxSGPRSNum) 623 throw Exception("Used SGPRs number out of range");623 throw BinGenException("Used SGPRs number out of range"); 624 624 if (config.localSize > 32768) 625 throw Exception("LocalSize out of range");625 throw BinGenException("LocalSize out of range"); 626 626 if (config.priority >= 4) 627 throw Exception("Priority out of range");627 throw BinGenException("Priority out of range"); 628 628 if (config.userDataNum > 16) 629 throw Exception("UserDataNum out of range");629 throw BinGenException("UserDataNum out of range"); 630 630 } 631 631 … … 666 666 #endif 667 667 elfSize > UINT32_MAX) 668 throw Exception("Elf binary size is too big!");668 throw BinGenException("Elf binary size is too big!"); 669 669 670 670 #ifdef HAVE_32BIT 671 671 if (binarySize > UINT32_MAX) 672 throw Exception("Binary size is too big!");672 throw BinGenException("Binary size is too big!"); 673 673 #endif 674 674 /**** … … 707 707 const GalliumKernelInput& kernel = input->kernels[korder]; 708 708 if (kernel.offset >= input->codeSize) 709 throw Exception("Kernel offset out of range");709 throw BinGenException("Kernel offset out of range"); 710 710 711 711 bos.writeObject<uint32_t>(LEV(uint32_t(kernel.kernelName.size()))); -
CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp
r3444 r3457 68 68 } 69 69 if (code==nullptr && regionsNum!=0) 70 throw Exception("No code if regions number is not zero");70 throw BinException("No code if regions number is not zero"); 71 71 regions.reset(new ROCmRegion[regionsNum]); 72 72 size_t j = 0; … … 82 82 const size_t value = ULEV(sym.st_value); 83 83 if (value < codeOffset) 84 throw Exception("Region offset is too small!");84 throw BinException("Region offset is too small!"); 85 85 const size_t size = ULEV(sym.st_size); 86 86 … … 99 99 symOffsets[j] = std::make_pair(value, j); 100 100 if (type!=ROCmRegionType::DATA && value+0x100 > codeOffset+codeSize) 101 throw Exception("Kernel or code offset is too big!");101 throw BinException("Kernel or code offset is too big!"); 102 102 regions[j++] = { getSymbolName(i), size, value, type }; 103 103 } … … 113 113 ROCmRegion& region = regions[symOffsets[i-1].second]; 114 114 if (region.type==ROCmRegionType::KERNEL && symOffsets[i-1].first+0x100 > end) 115 throw Exception("Kernel size is too small!");115 throw BinException("Kernel size is too small!"); 116 116 117 117 const size_t regSize = end - symOffsets[i-1].first; … … 144 144 const cxbyte* noteContent = (const cxbyte*)getNotes(); 145 145 if (noteContent==nullptr) 146 throw Exception("Missing notes in inner binary!");146 throw BinException("Missing notes in inner binary!"); 147 147 size_t notesSize = getNotesSize(); 148 148 // find note about AMDGPU … … 153 153 size_t descsz = ULEV(nhdr->n_descsz); 154 154 if (usumGt(offset, namesz+descsz, notesSize)) 155 throw Exception("Note offset+size out of range");155 throw BinException("Note offset+size out of range"); 156 156 if (ULEV(nhdr->n_type) == 0x3 && namesz==4 && descsz>=0x1a && 157 157 ::strcmp((const char*)noteContent+offset+sizeof(Elf64_Nhdr), "AMD")==0) … … 180 180 regionsMap.end(), name); 181 181 if (it == regionsMap.end()) 182 throw Exception("Can't find region name");182 throw BinException("Can't find region name"); 183 183 return regions[it->second]; 184 184 } -
CLRadeonExtender/trunk/utils/GPUId.cpp
r3445 r3457 27 27 28 28 using namespace CLRX; 29 30 GPUIdException::GPUIdException(const std::string& message) : Exception(message) 31 { } 29 32 30 33 // length of GPU device table (number of recognized GPU devices) … … 164 167 name, CStringCaseLess()); 165 168 if (it == lowerCaseGpuDeviceEntryTable+lowerCaseGpuDeviceEntryTableSize) 166 throw Exception("Unknown GPU device type");169 throw GPUIdException("Unknown GPU device type"); 167 170 return it->second; 168 171 } … … 176 179 break; 177 180 if (found == sizeof(gpuArchitectureNameTable2) / sizeof(const char*)) 178 throw Exception("Unknown GPU architecture");181 throw GPUIdException("Unknown GPU architecture"); 179 182 return GPUArchitecture(found/3); 180 183 } … … 183 186 { 184 187 if (deviceType > GPUDeviceType::GPUDEVICE_MAX) 185 throw Exception("Unknown GPU device type");188 throw GPUIdException("Unknown GPU device type"); 186 189 return gpuDeviceArchTable[cxuint(deviceType)]; 187 190 } … … 190 193 { 191 194 if (architecture > GPUArchitecture::GPUARCH_MAX) 192 throw Exception("Unknown GPU architecture");195 throw GPUIdException("Unknown GPU architecture"); 193 196 return gpuLowestDeviceFromArchTable[cxuint(architecture)]; 194 197 } … … 197 200 { 198 201 if (deviceType > GPUDeviceType::GPUDEVICE_MAX) 199 throw Exception("Unknown GPU device type");202 throw GPUIdException("Unknown GPU device type"); 200 203 return gpuDeviceNameTable[cxuint(deviceType)]; 201 204 } … … 204 207 { 205 208 if (architecture > GPUArchitecture::GPUARCH_MAX) 206 throw Exception("Unknown GPU architecture");209 throw GPUIdException("Unknown GPU architecture"); 207 210 return gpuArchitectureNameTable[cxuint(architecture)]; 208 211 } … … 212 215 { 213 216 if (architecture > GPUArchitecture::GPUARCH_MAX) 214 throw Exception("Unknown GPU architecture");217 throw GPUIdException("Unknown GPU architecture"); 215 218 if (regType == REGTYPE_VGPR) 216 219 return 256; // VGPRS … … 360 363 { 361 364 if (deviceType > GPUDeviceType::GPUDEVICE_MAX) 362 throw Exception("Unknown GPU device type");365 throw GPUIdException("Unknown GPU device type"); 363 366 // choose correct GPU arch values table 364 367 const AMDGPUArchVersion* archValuesTable = (table == GPUArchVersionTable::AMDCL2) ?
Note: See TracChangeset
for help on using the changeset viewer.