aboutsummaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-13 03:46:46 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-13 03:46:46 +0000
commit6c5a78b628203a571387451a2f8a834954c11406 (patch)
treea9c1c737ae7f45f8db587888debf990b2ef12613 /tool
parenta347d9541662ff0e3ecff0b4aff82141c8c1396a (diff)
downloadruby-6c5a78b628203a571387451a2f8a834954c11406.tar.gz
move canary-related statements into macros
This is mostly cosmetic. Should generate a slightly readable vm.inc output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rwxr-xr-xtool/ruby_vm/models/bare_instructions.rb16
-rw-r--r--tool/ruby_vm/views/_insn_entry.erb24
2 files changed, 17 insertions, 23 deletions
diff --git a/tool/ruby_vm/models/bare_instructions.rb b/tool/ruby_vm/models/bare_instructions.rb
index 30a6e0ff88..ed3d886014 100755
--- a/tool/ruby_vm/models/bare_instructions.rb
+++ b/tool/ruby_vm/models/bare_instructions.rb
@@ -109,8 +109,20 @@ class RubyVM::BareInstructions
@attrs.fetch('leaf').expr.expr == 'true;'
end
- def complicated_return_values?
- @sig[:ret].any? {|i| i == '...' }
+ def handle_canary stmt
+ # Stack canary is basically a good thing that we want to add, however:
+ #
+ # - When the instruction returns variadic number of return values,
+ # it is not easy to tell where is the stack top. We can't but
+ # skip it.
+ #
+ # - When the instruction body is empty (like putobject), we can
+ # say for 100% sure that canary is a waste of time.
+ #
+ # So we skip canary for those cases.
+ return '' if @sig[:ret].any? {|i| i == '...' }
+ return '' if @expr.blank?
+ return " #{stmt};\n"
end
def inspect
diff --git a/tool/ruby_vm/views/_insn_entry.erb b/tool/ruby_vm/views/_insn_entry.erb
index 90a489f624..d3c7b63582 100644
--- a/tool/ruby_vm/views/_insn_entry.erb
+++ b/tool/ruby_vm/views/_insn_entry.erb
@@ -13,16 +13,11 @@ INSN_ENTRY(<%= insn.name %>)
%# NAME_OF_CURRENT_INSN is used in vm_exec.h
# define NAME_OF_CURRENT_INSN <%= insn.name %>
# define INSN_ATTR(x) <%= insn.call_attribute(' ## x ## ') %>
-% unless insn.complicated_return_values?
-# if VM_CHECK_MODE > 0
- bool leaf;
- VALUE *canary;
-# endif
-% end
% unless insn.declarations.empty?
<%= insn.declarations.join(";\n ") %>;
% end
+<%= insn.handle_canary "DECLARE_CANARY" -%>
START_OF_ORIGINAL_INSN(<%= insn.name %>);
% insn.preamble.each do |konst|
<%= render_c_expr konst -%>
@@ -39,27 +34,14 @@ INSN_ENTRY(<%= insn.name %>)
% if insn.handles_sp?
POPN(INSN_ATTR(popn));
% end
-% unless insn.complicated_return_values?
-#if VM_CHECK_MODE > 0
- if ((leaf = INSN_ATTR(leaf))) {
- canary = STACK_ADDR_FROM_TOP(-1);
- *canary = vm_stack_canary;
- }
-#endif
-% end
+<%= insn.handle_canary "SETUP_CANARY()" -%>
COLLECT_USAGE_INSN(INSN_ATTR(bin));
% insn.opes.each_with_index do |ope, i|
COLLECT_USAGE_OPERAND(INSN_ATTR(bin), <%= i %>, <%= ope[:name] %>);
% end
<%= render_c_expr insn.expr -%>
CHECK_VM_STACK_OVERFLOW_FOR_INSN(VM_REG_CFP, INSN_ATTR(retn));
-% unless insn.complicated_return_values?
-#if VM_CHECK_MODE > 0
- if (leaf && (*canary != vm_stack_canary)) {
- vm_canary_is_found_dead(INSN_ATTR(bin), *canary);
- }
-#endif
-% end
+<%= insn.handle_canary "CHECK_CANARY()" -%>
% if insn.handles_sp?
% insn.rets.reverse_each do |ret|
PUSH(<%= insn.cast_to_VALUE ret %>);