-
Couldn't load subscription status.
- Fork 5.2k
[mono] Add SwiftError support for Swift reverse pinvokes #101122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
94ae2a4
8f8a71a
74c708a
97003cd
1ba2a83
32455a4
6e7620d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2887,7 +2887,12 @@ mono_arch_allocate_vars (MonoCompile *cfg) | |
| offset += size; | ||
|
|
||
| cfg->arch.swift_error_var = ins; | ||
| cfg->used_int_regs |= 1 << ARMREG_R21; | ||
|
|
||
| /* In the n2m case, the error register functions as an extra return register | ||
| * and is thus is not treated as callee-saved. | ||
| */ | ||
| if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) | ||
| cfg->used_int_regs |= 1 << ARMREG_R21; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be helpful to explain here that in the NATIVE_TO_MANAGED case, the error register is functioning as an extra return register, and thus isn't treated as callee-save. |
||
| break; | ||
| } | ||
| default: | ||
|
|
@@ -3731,8 +3736,13 @@ emit_move_return_value (MonoCompile *cfg, guint8 * code, MonoInst *ins) | |
| MonoCallInst *call; | ||
|
|
||
| if (cfg->arch.swift_error_var) { | ||
| code = emit_ldrx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| code = emit_strx (code, ARMREG_R21, ARMREG_IP0, 0); | ||
| if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) { | ||
| code = emit_ldrx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| code = emit_strx (code, ARMREG_R21, ARMREG_IP0, 0); | ||
| } else if (cfg->method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) { | ||
| /* Load the value of SwiftError into R21 */ | ||
| code = emit_ldrx (code, ARMREG_R21, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| } | ||
| } | ||
|
|
||
| call = (MonoCallInst*)ins; | ||
|
|
@@ -5937,11 +5947,17 @@ emit_move_args (MonoCompile *cfg, guint8 *code) | |
| code = emit_strfpq (code, ainfo->reg, ins->inst_basereg, GTMREG_TO_INT (ins->inst_offset)); | ||
| break; | ||
| case ArgSwiftError: | ||
| if (ainfo->offset) { | ||
| code = emit_ldrx (code, ARMREG_IP0, cfg->arch.args_reg, ainfo->offset); | ||
| code = emit_strx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| } else { | ||
| code = emit_strx (code, ainfo->reg, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) { | ||
| if (ainfo->offset) { | ||
| code = emit_ldrx (code, ARMREG_IP0, cfg->arch.args_reg, ainfo->offset); | ||
| code = emit_strx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| } else { | ||
| code = emit_strx (code, ainfo->reg, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| } | ||
| } else if (cfg->method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) { | ||
| arm_addx_imm (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
| /* Relies on arguments being passed on the stack */ | ||
| code = emit_strx (code, ARMREG_IP0, ins->inst_basereg, GTMREG_TO_INT (ins->inst_offset)); | ||
| } | ||
| break; | ||
| default: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it doesn't include the
ARGS_OFFSEToffset between fp and the first argument in the callee?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ainfo->offsetwas always 0 here. So it was always allocated at ARGS_OFFSET from the beginning. I think thatoffsetalready includes information about the distance.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Swift types are specified either at the beginning or the end of signature. We don't enforce strict signature rules, but it would be beneficial to make them more general if possible. Can it still function if
SwiftErroris specified as the last argument, usingainfo->offsetinstead ofoffset?@amanasifkhalid, what are the limitations from the CoreCLR side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't enforce any signature rules, either. The Swift special register types can appear anywhere in the signature's parameter list.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kotlarmilos i think for that to work with ainfo->offset without any modifications, the error would have to be the first argument. We could probably update ainfo->offset in get_call_info so that it works for every position. I'm not sure what are the benefits of using ainfo->offset though, as the current solution works for every position.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sounds good. I forgot that the
ainfo->offsetis always 0 forswifterrorin theget_call_info.