mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
c2bfb4e93c
An instruction is leaf if it has no rb_funcall inside. In order to check this property, we introduce stack canary which is a random number collected at runtime. Stack top is always filled with this number and checked for stack smashing operations, when VM_CHECK_MODE. [GH-1947] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
76 lines
2.2 KiB
Text
76 lines
2.2 KiB
Text
%# -*- mode:c; style:ruby; coding: utf-8; indent-tabs-mode: nil -*-
|
|
%# Copyright (c) 2017 Urabe, Shyouhei. All rights reserved.
|
|
%#
|
|
%# This file is a part of the programming language Ruby. Permission is hereby
|
|
%# granted, to either redistribute and/or modify this file, provided that the
|
|
%# conditions mentioned in the file COPYING are met. Consult the file for
|
|
%# details.
|
|
%;
|
|
|
|
/* insn <%= insn.pretty_name %> */
|
|
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
|
|
START_OF_ORIGINAL_INSN(<%= insn.name %>);
|
|
% insn.preamble.each do |konst|
|
|
<%= render_c_expr konst -%>
|
|
% end
|
|
% insn.opes.each_with_index do |ope, i|
|
|
<%= ope[:name] %> = (<%= ope[:type] %>)GET_OPERAND(<%= i + 1 %>);
|
|
% end
|
|
%
|
|
% insn.pops.reverse_each.with_index.reverse_each do |pop, i|
|
|
<%= pop[:name] %> = <%= insn.cast_from_VALUE pop, "TOPN(#{i})"%>;
|
|
% end
|
|
DEBUG_ENTER_INSN(INSN_ATTR(name));
|
|
ADD_PC(INSN_ATTR(width));
|
|
% 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
|
|
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
|
|
% if insn.handles_sp?
|
|
% insn.rets.reverse_each do |ret|
|
|
PUSH(<%= insn.cast_to_VALUE ret %>);
|
|
% end
|
|
% else
|
|
ADJ_SP(INSN_ATTR(sp_inc));
|
|
% insn.rets.reverse_each.with_index do |ret, i|
|
|
TOPN(<%= i %>) = <%= insn.cast_to_VALUE ret %>;
|
|
% end
|
|
% end
|
|
END_INSN(<%= insn.name %>);
|
|
# undef INSN_ATTR
|
|
# undef NAME_OF_CURRENT_INSN
|
|
}
|