Skip to content

Commit d2ab545

Browse files
mnaczksys_zuul
authored andcommitted
Improve passig RegFlag via option by better checking flag name, and
returned info to user if one of flag has error Change-Id: I79bb5d2ed86c513baf18ed5a11aabcda11e17fcf
1 parent 3b5ec8b commit d2ab545

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

IGC/AdaptorOCL/ocl_igc_interface/impl/igc_ocl_translation_ctx_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ CIF_DECLARE_INTERFACE_PIMPL(IgcOclTranslationCtx) : CIF::PimplBase
222222
}
223223
}
224224
}
225-
LoadRegistryKeys(RegKeysFlagsFromOptions);
225+
bool RegFlagNameError = 0;
226+
LoadRegistryKeys(RegKeysFlagsFromOptions, &RegFlagNameError);
227+
if(RegFlagNameError) outputInterface->GetImpl()->SetError(TranslationErrorType::Unused, "Invalid registry flag name in -igc_opts, at least one flag has been ignored");
226228

227229
bool success = false;
228230
if (this->inType == CodeType::elf)

IGC/common/igc_regkeys.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ bool CheckHashRange(const std::vector<HashRange>& hashes)
674674
return false;
675675
}
676676

677-
static void LoadFromRegKeyOrEnvVarOrOptions(const std::string& options = "", std::string registrykeypath = IGC_REGISTRY_KEY)
677+
static void LoadFromRegKeyOrEnvVarOrOptions(const std::string& options = "", bool* RegFlagNameError = nullptr, std::string registrykeypath = IGC_REGISTRY_KEY)
678678
{
679679
SRegKeyVariableMetaData* pRegKeyVariable = (SRegKeyVariableMetaData*)&g_RegKeyList;
680680
unsigned NUM_REGKEY_ENTRIES = sizeof(SRegKeysList) / sizeof(SRegKeyVariableMetaData);
@@ -703,32 +703,39 @@ static void LoadFromRegKeyOrEnvVarOrOptions(const std::string& options = "", std
703703
std::size_t foundComma = options.find(',', found);
704704
if (foundComma != std::string::npos)
705705
{
706-
std::string token = options.substr(found + nameWithEqual.size(), foundComma - (found + nameWithEqual.size()));
707-
unsigned int size = sizeof(value);
708-
void* pValueFromOptions = &valueFromOptions;
709-
710-
const char* envValFromOptions = token.c_str();
711-
bool valueIsInt = false;
712-
if (envValFromOptions != NULL)
706+
if (found == 0 || options[found - 1] == ' ' || options[found - 1] == ',')
713707
{
714-
if (size >= sizeof(unsigned int))
708+
std::string token = options.substr(found + nameWithEqual.size(), foundComma - (found + nameWithEqual.size()));
709+
unsigned int size = sizeof(value);
710+
void* pValueFromOptions = &valueFromOptions;
711+
712+
const char* envValFromOptions = token.c_str();
713+
bool valueIsInt = false;
714+
if (envValFromOptions != NULL)
715715
{
716-
// Try integer conversion
717-
char* pStopped = nullptr;
718-
unsigned int* puValFromOptions = (unsigned int*)pValueFromOptions;
719-
*puValFromOptions = strtoul(envValFromOptions, &pStopped, 0);
720-
if (pStopped == envValFromOptions + strlen(envValFromOptions))
716+
if (size >= sizeof(unsigned int))
721717
{
722-
valueIsInt = true;
718+
// Try integer conversion
719+
char* pStopped = nullptr;
720+
unsigned int* puValFromOptions = (unsigned int*)pValueFromOptions;
721+
*puValFromOptions = strtoul(envValFromOptions, &pStopped, 0);
722+
if (pStopped == envValFromOptions + strlen(envValFromOptions))
723+
{
724+
valueIsInt = true;
725+
}
726+
}
727+
if (!valueIsInt)
728+
{
729+
// Just return the string
730+
strncpy_s((char*)pValueFromOptions, size, envValFromOptions, size);
723731
}
724732
}
725-
if (!valueIsInt)
726-
{
727-
// Just return the string
728-
strncpy_s((char*)pValueFromOptions, size, envValFromOptions, size);
729-
}
733+
memcpy_s(pRegKeyVariable[i].m_string, sizeof(valueFromOptions), valueFromOptions, sizeof(valueFromOptions));
734+
}
735+
else if(RegFlagNameError != nullptr)
736+
{
737+
*RegFlagNameError = true;
730738
}
731-
memcpy_s(pRegKeyVariable[i].m_string, sizeof(valueFromOptions), valueFromOptions, sizeof(valueFromOptions));
732739
}
733740
}
734741
}
@@ -754,7 +761,7 @@ void SetCurrentDebugHash(unsigned long long hash)
754761
None
755762
756763
\*****************************************************************************/
757-
void LoadRegistryKeys(const std::string& options)
764+
void LoadRegistryKeys(const std::string& options, bool *RegFlagNameError)
758765
{
759766
// only load the debug flags once before compiling to avoid any multi-threading issue
760767
static std::mutex loadFlags;
@@ -772,12 +779,12 @@ void LoadRegistryKeys(const std::string& options)
772779
{
773780
std::string driverStoreRegKeyPath = getNewRegistryPath(driverInfo);
774781
std::string registryKeyPath = "SYSTEM\\ControlSet001\\Control\\Class\\" + driverStoreRegKeyPath + "\\IGC";
775-
LoadFromRegKeyOrEnvVarOrOptions(options, registryKeyPath);
782+
LoadFromRegKeyOrEnvVarOrOptions(options, RegFlagNameError, registryKeyPath);
776783
}
777784
#endif
778785
//DumpIGCRegistryKeyDefinitions();
779786
LoadDebugFlagsFromFile();
780-
LoadFromRegKeyOrEnvVarOrOptions(options);
787+
LoadFromRegKeyOrEnvVarOrOptions(options, RegFlagNameError);
781788

782789
if(IGC_IS_FLAG_ENABLED(LLVMCommandLine))
783790
{

IGC/common/igc_regkeys.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ struct DEVICE_INFO
217217

218218
void DumpIGCRegistryKeyDefinitions();
219219
void DumpIGCRegistryKeyDefinitions3(std::string driverRegistryPath, unsigned long pciBus, unsigned long pciDevice, unsigned long pciFunction);
220-
void LoadRegistryKeys(const std::string& options = "");
220+
void LoadRegistryKeys(const std::string& options = "", bool *RegFlagNameError = nullptr);
221221
void SetCurrentDebugHash(unsigned long long hash);
222222
#undef LINUX_RELEASE_MODE
223223
#else
224224
static inline void SetCurrentDebugHash(unsigned long long hash) {}
225-
static inline void LoadRegistryKeys(const std::string& options = "") {}
225+
static inline void LoadRegistryKeys(const std::string& options = "", bool *RegFlagNameError=nullptr) {}
226226
#define IGC_SET_FLAG_VALUE( name, regkeyValue ) ;
227227
#define DECLARE_IGC_REGKEY(dataType, regkeyName, defaultValue, description, releaseMode) \
228228
static const unsigned int regkeyName##default = (unsigned int)defaultValue;

0 commit comments

Comments
 (0)