Commit a489abe8 authored by bjaideep's avatar bjaideep Committed by Commit bot

PPC/s390: [sim] Consistent support for C calls with up to 9 args

Port 3337cccc

Original Commit Message:

    Consistently support calls to host-C-linkage functions with up to 9 arguments
    from the simulator, and check that these limits aren't exceeded accidentally.

R=jgruber@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=v8:6281
LOG=N

Review-Url: https://codereview.chromium.org/2841693003
Cr-Commit-Position: refs/heads/master@{#44858}
parent 28930128
......@@ -2960,6 +2960,7 @@ void MacroAssembler::CallCFunction(Register function, int num_arguments) {
void MacroAssembler::CallCFunctionHelper(Register function,
int num_reg_arguments,
int num_double_arguments) {
DCHECK_LE(num_reg_arguments + num_double_arguments, kMaxCParameters);
DCHECK(has_frame());
// Just call directly. The function called cannot cause a GC, or
......
......@@ -1292,7 +1292,9 @@ static void decodeObjectPair(ObjectPair* pair, intptr_t* x, intptr_t* y) {
// Calls into the V8 runtime.
typedef intptr_t (*SimulatorRuntimeCall)(intptr_t arg0, intptr_t arg1,
intptr_t arg2, intptr_t arg3,
intptr_t arg4, intptr_t arg5);
intptr_t arg4, intptr_t arg5,
intptr_t arg6, intptr_t arg7,
intptr_t arg8);
typedef ObjectPair (*SimulatorRuntimePairCall)(intptr_t arg0, intptr_t arg1,
intptr_t arg2, intptr_t arg3,
intptr_t arg4, intptr_t arg5);
......@@ -1329,7 +1331,8 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
(get_register(sp) & (::v8::internal::FLAG_sim_stack_alignment - 1)) ==
0;
Redirection* redirection = Redirection::FromSwiInstruction(instr);
const int kArgCount = 6;
const int kArgCount = 9;
const int kRegisterArgCount = 8;
int arg0_regnum = 3;
intptr_t result_buffer = 0;
bool uses_result_buffer =
......@@ -1341,9 +1344,15 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
arg0_regnum++;
}
intptr_t arg[kArgCount];
for (int i = 0; i < kArgCount; i++) {
// First eight arguments in registers r3-r10.
for (int i = 0; i < kRegisterArgCount; i++) {
arg[i] = get_register(arg0_regnum + i);
}
intptr_t* stack_pointer = reinterpret_cast<intptr_t*>(get_register(sp));
// Remaining argument on stack
arg[kRegisterArgCount] = stack_pointer[kStackFrameExtraParamSlot];
STATIC_ASSERT(kArgCount == kRegisterArgCount + 1);
STATIC_ASSERT(kMaxCParameters == 9);
bool fp_call =
(redirection->type() == ExternalReference::BUILTIN_FP_FP_CALL) ||
(redirection->type() == ExternalReference::BUILTIN_COMPARE_CALL) ||
......@@ -1519,9 +1528,10 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
PrintF(
"Call to host function at %p,\n"
"\t\t\t\targs %08" V8PRIxPTR ", %08" V8PRIxPTR ", %08" V8PRIxPTR
", %08" V8PRIxPTR ", %08" V8PRIxPTR ", %08" V8PRIxPTR
", %08" V8PRIxPTR ", %08" V8PRIxPTR ", %08" V8PRIxPTR,
static_cast<void*>(FUNCTION_ADDR(target)), arg[0], arg[1],
arg[2], arg[3], arg[4], arg[5]);
static_cast<void*>(FUNCTION_ADDR(target)), arg[0], arg[1], arg[2],
arg[3], arg[4], arg[5], arg[6], arg[7], arg[8]);
if (!stack_aligned) {
PrintF(" with unaligned stack %08" V8PRIxPTR "\n",
get_register(sp));
......@@ -1568,8 +1578,8 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
DCHECK(redirection->type() == ExternalReference::BUILTIN_CALL);
SimulatorRuntimeCall target =
reinterpret_cast<SimulatorRuntimeCall>(external);
intptr_t result =
target(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]);
intptr_t result = target(arg[0], arg[1], arg[2], arg[3], arg[4],
arg[5], arg[6], arg[7], arg[8]);
if (::v8::internal::FLAG_trace_sim) {
PrintF("Returned %08" V8PRIxPTR "\n", result);
}
......
......@@ -2712,6 +2712,7 @@ void MacroAssembler::CallCFunction(Register function, int num_arguments) {
void MacroAssembler::CallCFunctionHelper(Register function,
int num_reg_arguments,
int num_double_arguments) {
DCHECK_LE(num_reg_arguments + num_double_arguments, kMaxCParameters);
DCHECK(has_frame());
// Just call directly. The function called cannot cause a GC, or
......
......@@ -1934,7 +1934,9 @@ static void decodeObjectPair(ObjectPair* pair, intptr_t* x, intptr_t* y) {
// Calls into the V8 runtime.
typedef intptr_t (*SimulatorRuntimeCall)(intptr_t arg0, intptr_t arg1,
intptr_t arg2, intptr_t arg3,
intptr_t arg4, intptr_t arg5);
intptr_t arg4, intptr_t arg5,
intptr_t arg6, intptr_t arg7,
intptr_t arg8);
typedef ObjectPair (*SimulatorRuntimePairCall)(intptr_t arg0, intptr_t arg1,
intptr_t arg2, intptr_t arg3,
intptr_t arg4, intptr_t arg5);
......@@ -1971,7 +1973,8 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
(get_register(sp) & (::v8::internal::FLAG_sim_stack_alignment - 1)) ==
0;
Redirection* redirection = Redirection::FromSwiInstruction(instr);
const int kArgCount = 6;
const int kArgCount = 9;
const int kRegisterArgCount = 5;
int arg0_regnum = 2;
intptr_t result_buffer = 0;
bool uses_result_buffer =
......@@ -1983,11 +1986,18 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
arg0_regnum++;
}
intptr_t arg[kArgCount];
for (int i = 0; i < kArgCount - 1; i++) {
// First 5 arguments in registers r2-r6.
for (int i = 0; i < kRegisterArgCount; i++) {
arg[i] = get_register(arg0_regnum + i);
}
// Remaining arguments on stack
intptr_t* stack_pointer = reinterpret_cast<intptr_t*>(get_register(sp));
arg[5] = stack_pointer[kCalleeRegisterSaveAreaSize / kPointerSize];
for (int i = kRegisterArgCount; i < kArgCount; i++) {
arg[i] = stack_pointer[(kCalleeRegisterSaveAreaSize / kPointerSize) +
(i - kRegisterArgCount)];
}
STATIC_ASSERT(kArgCount == kRegisterArgCount + 4);
STATIC_ASSERT(kMaxCParameters == 9);
bool fp_call =
(redirection->type() == ExternalReference::BUILTIN_FP_FP_CALL) ||
(redirection->type() == ExternalReference::BUILTIN_COMPARE_CALL) ||
......@@ -2165,9 +2175,10 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
PrintF(
"Call to host function at %p,\n"
"\t\t\t\targs %08" V8PRIxPTR ", %08" V8PRIxPTR ", %08" V8PRIxPTR
", %08" V8PRIxPTR ", %08" V8PRIxPTR ", %08" V8PRIxPTR
", %08" V8PRIxPTR ", %08" V8PRIxPTR ", %08" V8PRIxPTR,
static_cast<void*>(FUNCTION_ADDR(target)), arg[0], arg[1], arg[2],
arg[3], arg[4], arg[5]);
arg[3], arg[4], arg[5], arg[6], arg[7], arg[8]);
if (!stack_aligned) {
PrintF(" with unaligned stack %08" V8PRIxPTR "\n",
static_cast<intptr_t>(get_register(sp)));
......@@ -2214,8 +2225,8 @@ void Simulator::SoftwareInterrupt(Instruction* instr) {
DCHECK(redirection->type() == ExternalReference::BUILTIN_CALL);
SimulatorRuntimeCall target =
reinterpret_cast<SimulatorRuntimeCall>(external);
intptr_t result =
target(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]);
intptr_t result = target(arg[0], arg[1], arg[2], arg[3], arg[4],
arg[5], arg[6], arg[7], arg[8]);
if (::v8::internal::FLAG_trace_sim) {
PrintF("Returned %08" V8PRIxPTR "\n", result);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment