1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
shyouhei 2018-09-13 03:46:46 +00:00
parent 63130b2348
commit 6925c9c6f5
3 changed files with 38 additions and 23 deletions

View file

@ -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

View file

@ -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 %>);

View file

@ -200,6 +200,27 @@ enum vm_regan_acttype {
/**********************************************************/
/**********************************************************/
/* deal with stack canary */
/**********************************************************/
#if VM_CHECK_MODE > 0
#define DECLARE_CANARY bool leaf; VALUE *canary
#define SETUP_CANARY() \
if ((leaf = INSN_ATTR(leaf))) { \
canary = GET_SP(); \
SET_SV(vm_stack_canary); \
}
#define CHECK_CANARY() \
if (leaf && (*canary != vm_stack_canary)) { \
vm_canary_is_found_dead(INSN_ATTR(bin), *canary); \
}
#else
#define DECLARE_CANARY /* void */
#define SETUP_CANARY() /* void */
#define CHECK_CANARY() /* void */
#endif
/**********************************************************/
/* others */
/**********************************************************/