]> git.lizzy.rs Git - rust.git/commitdiff
Changes to error handling
authorDavid Cook <divergentdave@gmail.com>
Sun, 5 Apr 2020 18:53:03 +0000 (13:53 -0500)
committerDavid Cook <divergentdave@gmail.com>
Sun, 5 Apr 2020 18:53:03 +0000 (13:53 -0500)
src/shims/sync.rs

index 90d7104b9e7b0671c1a09f11cc14acc8a78fb4b0..d7ae32daaa2baebeddf062eb11588933d4586667 100644 (file)
@@ -263,7 +263,7 @@ fn pthread_mutex_lock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx
                 None => this.eval_libc_i32("EAGAIN"),
             }
         } else {
-            this.eval_libc_i32("EINVAL")
+            throw_ub_format!("called pthread_mutex_lock on an unsupported type of mutex");
         }
     }
 
@@ -291,7 +291,7 @@ fn pthread_mutex_trylock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'
                 None => this.eval_libc_i32("EAGAIN"),
             }
         } else {
-            this.eval_libc_i32("EINVAL")
+            throw_ub_format!("called pthread_mutex_trylock on an unsupported type of mutex");
         }
     }
 
@@ -306,9 +306,7 @@ fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'t
                 mutex_set_locked_count(this, mutex_op, Scalar::from_u32(0))?;
                 Ok(0)
             } else {
-                throw_ub_format!(
-                    "Attempted to unlock a PTHREAD_MUTEX_NORMAL mutex that was not locked"
-                );
+                throw_ub_format!("unlocked a PTHREAD_MUTEX_NORMAL mutex that was not locked");
             }
         } else if kind == this.eval_libc("PTHREAD_MUTEX_ERRORCHECK")? {
             if locked_count != 0 {
@@ -329,7 +327,7 @@ fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'t
                 }
             }
         } else {
-            this.eval_libc_i32("EINVAL")
+            throw_ub_format!("called pthread_mutex_unlock on an unsupported type of mutex");
         }
     }
 
@@ -337,7 +335,7 @@ fn pthread_mutex_destroy(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'
         let this = self.eval_context_mut();
 
         if mutex_get_locked_count(this, mutex_op)?.to_u32()? != 0 {
-            return this.eval_libc_i32("EBUSY");
+            throw_ub_format!("destroyed a locked mutex");
         }
 
         mutex_set_kind(this, mutex_op, ScalarMaybeUndef::Undef)?;
@@ -422,18 +420,17 @@ fn pthread_rwlock_unlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<
             rwlock_set_writers(this, rwlock_op, Scalar::from_u32(0))?;
             Ok(0)
         } else {
-            this.eval_libc_i32("EPERM")
+            throw_ub_format!("unlocked an rwlock that was not locked");
         }
     }
 
     fn pthread_rwlock_destroy(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();
 
-        if rwlock_get_readers(this, rwlock_op)?.to_u32()? != 0 {
-            return this.eval_libc_i32("EBUSY");
-        }
-        if rwlock_get_writers(this, rwlock_op)?.to_u32()? != 0 {
-            return this.eval_libc_i32("EBUSY");
+        if rwlock_get_readers(this, rwlock_op)?.to_u32()? != 0
+            || rwlock_get_writers(this, rwlock_op)?.to_u32()? != 0
+        {
+            throw_ub_format!("destroyed a locked rwlock");
         }
 
         rwlock_set_readers(this, rwlock_op, ScalarMaybeUndef::Undef)?;