History

Change assert to exception if a dis module contains an invalid magic number. Broken threads now terminate the VM using the default scheduler. Tools can not get a callback for broken threads.

arr committed 10 years ago

Commit 096b0c71 parent 9c1abd69 files · +74 −28Browse files

Showing the changes to src/include (3 of 9 files). Show all

Unified · Split

3 files
  1. src/include/exceptions.h +12 −0
  2. src/include/runtime.h +7 −2
  3. src/include/vm_tools.h +1 −0
src/include/exceptions.h+12−0
@@ -128,6 +128,18 @@ namespace disvm · 127 unmodified lines
128128 const char *module_name;
129129 const vm_pc_t program_counter;
130130 };
131+
132+ class vm_term_request final : public vm_user_exception
133+ {
134+ public:
135+ explicit vm_term_request()
136+ : vm_user_exception("VM termination requested")
137+ { }
138+
139+ explicit vm_term_request(const char *msg)
140+ : vm_user_exception(msg)
141+ { }
142+ };
131143 }
132144 }
133145
src/include/runtime.h+7−2
@@ -717,7 +717,7 @@ namespace disvm · 716 unmodified lines
717717 exiting, // exit instruction
718718 empty_stack,
719719
720− broken, // thread crashed
720+ broken, // thread crashed - the scheduler is free to terminate the entire VM if any thread enters this state.
721721 };
722722
723723 // Forward declaration
@@ -787,6 +787,10 @@ namespace disvm · 63 unmodified lines
787787
788788 vm_thread_state_t get_state() const;
789789
790+ // This function will only return a non-null
791+ // value if this thread is in the broken state.
792+ const char *get_error_message() const;
793+
790794 uint32_t get_thread_id() const;
791795
792796 uint32_t get_parent_thread_id() const;
@@ -794,9 +798,10 @@ namespace disvm · 1 unmodified line
794798 const vm_registers_t& get_registers() const;
795799
796800 private:
801+ vm_registers_t _registers;
797802 const uint32_t _thread_id;
798803 const uint32_t _parent_thread_id;
799− vm_registers_t _registers;
804+ char *_error_message;
800805 };
801806
802807 //
src/include/vm_tools.h+1−0
@@ -49,6 +49,7 @@ namespace disvm · 48 unmodified lines
4949
5050 thread_begin, // value1: const vm_thread_t
5151 thread_end, // value1: const vm_thread_t
52+ thread_broken, // value1: const vm_thread_t
5253
5354 exception_raised, // value1: vm_registers_t
5455 // value2: const vm_string_t - exception ID