rocr: Error Handling Issues (#264)
* rocr: Fix Incorrect Assertion Check The wrong variable is used in the assertion statement, should be error checking for the value of paramEndLoc after it is modified by the call to find(). Signed-off-by: Sunday Clement <Sunday.Clement@amd.com> * rocr: Fix Potential Undefined Behaviour In the event that the SvmProfileControl destructor is called and event == -1 is true then the call to close(event) is effectively close(-1) which is undefined behaviour. This has been changed to only call close() on valid file descriptors. Signed-off-by: Sunday Clement <Sunday.Clement@amd.com> * rocr: Add Error Check on Bytes Read In the case that there is an incomplete read the call to copyTo() will now return an error. Signed-off-by: Sunday Clement <Sunday.Clement@amd.com> * rocr: Fix Exception Error Destructors are implicitly marked with noexcept being true by default so if its not explicitly marked false in the destructor or the functions it calls, any thrown exceptions will cause the program to crash. Signed-off-by: Sunday Clement <Sunday.Clement@amd.com> --------- Signed-off-by: Sunday Clement <Sunday.Clement@amd.com> Co-authored-by: Sunday Clement <Sunday.Clement@amd.com>
This commit is contained in:
committed by
GitHub
orang tua
a442766d26
melakukan
f1fabcfd64
@@ -506,7 +506,7 @@ int GetKernelSourceParam(const char* paramName) {
|
||||
std::string::size_type paramValLoc = paramDefLoc + paramDef.str().size();
|
||||
std::string::size_type paramEndLoc =
|
||||
kBlitKernelSource().find('\n', paramDefLoc);
|
||||
assert(paramDefLoc != std::string::npos);
|
||||
assert(paramEndLoc != std::string::npos);
|
||||
|
||||
std::string paramVal(&kBlitKernelSource()[paramValLoc],
|
||||
&kBlitKernelSource()[paramEndLoc]);
|
||||
|
||||
@@ -356,14 +356,16 @@ SvmProfileControl::SvmProfileControl() : event(-1), exit(false) {
|
||||
}
|
||||
|
||||
SvmProfileControl::~SvmProfileControl() {
|
||||
if (event != -1) eventfd_write(event, 1);
|
||||
if (event != -1) {
|
||||
eventfd_write(event, 1);
|
||||
close(event);
|
||||
}
|
||||
if (poll_smi_thread_ != NULL) {
|
||||
exit = true;
|
||||
os::WaitForThread(poll_smi_thread_);
|
||||
os::CloseThread(poll_smi_thread_);
|
||||
poll_smi_thread_ = NULL;
|
||||
}
|
||||
close(event);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
|
||||
@@ -179,7 +179,7 @@ class ScopeGuard {
|
||||
|
||||
ScopeGuard(ScopeGuard& rhs) { *this = rhs; }
|
||||
|
||||
__forceinline ~ScopeGuard() {
|
||||
__forceinline ~ScopeGuard() noexcept(false) {
|
||||
if (!dismiss_) release_();
|
||||
}
|
||||
__forceinline ScopeGuard& operator=(ScopeGuard& rhs) {
|
||||
|
||||
@@ -274,7 +274,16 @@ namespace elf {
|
||||
{
|
||||
size_t size1 = getSize();
|
||||
void* buffer1 = malloc(size1);
|
||||
if (_read(d, buffer1, size1) < 0) { free(buffer1); return perror("read failed"); }
|
||||
ssize_t bytes_read = _read(d, buffer1, size1);
|
||||
if (bytes_read < 0) {
|
||||
free(buffer1);
|
||||
return perror("read failed");
|
||||
}
|
||||
if (static_cast<size_t>(bytes_read) != size1) {
|
||||
free(buffer1);
|
||||
return perror("Incomplete read");
|
||||
}
|
||||
|
||||
*buffer = buffer1;
|
||||
if (size) { *size = size1; }
|
||||
return true;
|
||||
@@ -284,7 +293,10 @@ namespace elf {
|
||||
{
|
||||
size_t size1 = getSize();
|
||||
if (size < size1) { return error("Buffer size is not enough"); }
|
||||
if (_read(d, buffer, size1) < 0) { return perror("read failed"); }
|
||||
ssize_t bytes_read = _read(d, buffer, size1);
|
||||
if (bytes_read < 0) { return perror("read failed"); }
|
||||
if (static_cast<size_t>(bytes_read) != size1) { return perror("Incomplete read"); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user