Skip to content

Commit db492f6

Browse files
Fixes for issues found in the PR review.
1 parent bd8d105 commit db492f6

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

mono/mini/mini-arm64.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,69 @@ typedef struct {
164164

165165
#endif
166166

167-
#if defined(TARGET_IOS) || defined(TARGET_APPLETV) || defined(TARGET_OSX)
167+
#if defined(TARGET_APPLETVOS) || defined(TARGET_IOS) || defined(TARGET_OSX)
168168
#define MONO_ARCH_HAVE_UNWIND_BACKTRACE 1
169169
#endif
170170

171+
#if defined(TARGET_OSX)
172+
173+
typedef enum {
174+
JPM_NONE,
175+
JPM_ENABLED,
176+
JPM_DISABLED,
177+
} jit_protect_mode;
178+
179+
extern __thread jit_protect_mode arm_current_jit_protect_mode;
180+
181+
static void mono_arm_jit_write_protect_enable()
182+
{
183+
if (__builtin_available(macOS 11, *)) {
184+
if (arm_current_jit_protect_mode != JPM_ENABLED) {
185+
pthread_jit_write_protect_np(1);
186+
arm_current_jit_protect_mode = JPM_ENABLED;
187+
}
188+
}
189+
}
190+
191+
static void mono_arm_jit_write_protect_disable()
192+
{
193+
if (__builtin_available(macOS 11, *)) {
194+
if (arm_current_jit_protect_mode != JPM_DISABLED) {
195+
pthread_jit_write_protect_np(0);
196+
arm_current_jit_protect_mode = JPM_DISABLED;
197+
}
198+
}
199+
}
200+
201+
#define MONO_SCOPE_ENABLE_JIT_WRITE() \
202+
__attribute__((unused, cleanup(mono_arm_restore_jit_protect_mode))) \
203+
jit_protect_mode scope_restrict_mode = arm_current_jit_protect_mode; \
204+
mono_arm_jit_write_protect_disable(); \
205+
206+
#define MONO_SCOPE_ENABLE_JIT_EXEC() \
207+
__attribute__((unused, cleanup(mono_arm_restore_jit_protect_mode))) \
208+
jit_protect_mode scope_restrict_mode = arm_current_jit_protect_mode; \
209+
mono_arm_jit_write_protect_enable(); \
210+
211+
static void mono_arm_restore_jit_protect_mode(jit_protect_mode* previous_jit_protect_mode)
212+
{
213+
if (*previous_jit_protect_mode == arm_current_jit_protect_mode)
214+
return;
215+
216+
switch (*previous_jit_protect_mode)
217+
{
218+
case JPM_ENABLED:
219+
mono_arm_jit_write_protect_enable();
220+
break;
221+
case JPM_DISABLED:
222+
case JPM_NONE:
223+
default:
224+
mono_arm_jit_write_protect_disable();
225+
}
226+
}
227+
228+
#endif
229+
171230
/* Relocations */
172231
#define MONO_R_ARM64_B 1
173232
#define MONO_R_ARM64_BCC 2

mono/mini/mini.h

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,65 +2886,11 @@ gboolean MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal);
28862886
MonoGenericContext
28872887
mono_get_generic_context_from_stack_frame (MonoJitInfo *ji, gpointer generic_info);
28882888

2889-
#if defined(__APPLE__) && defined(__arm64__)
2890-
2891-
typedef enum {
2892-
JPM_NONE,
2893-
JPM_ENABLED,
2894-
JPM_DISABLED,
2895-
} jit_protect_mode;
2896-
2897-
extern __thread jit_protect_mode arm_current_jit_protect_mode;
2898-
2899-
static void mono_arm_jit_write_protect_enable()
2900-
{
2901-
if (__builtin_available(macOS 11, *)) {
2902-
if (arm_current_jit_protect_mode != JPM_ENABLED) {
2903-
pthread_jit_write_protect_np(1);
2904-
arm_current_jit_protect_mode = JPM_ENABLED;
2905-
}
2906-
}
2907-
}
2908-
2909-
static void mono_arm_jit_write_protect_disable()
2910-
{
2911-
if (__builtin_available(macOS 11, *)) {
2912-
if (arm_current_jit_protect_mode != JPM_DISABLED) {
2913-
pthread_jit_write_protect_np(0);
2914-
arm_current_jit_protect_mode = JPM_DISABLED;
2915-
}
2916-
}
2917-
}
2918-
2919-
#define MONO_SCOPE_ENABLE_JIT_WRITE() \
2920-
__attribute__((unused, cleanup(mono_arm_restore_jit_protect_mode))) \
2921-
jit_protect_mode scope_restrict_mode = arm_current_jit_protect_mode; \
2922-
mono_arm_jit_write_protect_disable(); \
2923-
2924-
#define MONO_SCOPE_ENABLE_JIT_EXEC() \
2925-
__attribute__((unused, cleanup(mono_arm_restore_jit_protect_mode))) \
2926-
jit_protect_mode scope_restrict_mode = arm_current_jit_protect_mode; \
2927-
mono_arm_jit_write_protect_enable(); \
2928-
2929-
static void mono_arm_restore_jit_protect_mode(jit_protect_mode* previous_jit_protect_mode)
2930-
{
2931-
if (*previous_jit_protect_mode == arm_current_jit_protect_mode)
2932-
return;
2933-
2934-
switch (*previous_jit_protect_mode)
2935-
{
2936-
case JPM_ENABLED:
2937-
mono_arm_jit_write_protect_enable();
2938-
break;
2939-
case JPM_DISABLED:
2940-
case JPM_NONE:
2941-
default:
2942-
mono_arm_jit_write_protect_disable();
2943-
}
2944-
}
2945-
2946-
#else
2889+
#ifndef MONO_SCOPE_ENABLE_JIT_WRITE
29472890
#define MONO_SCOPE_ENABLE_JIT_WRITE()
2891+
#endif
2892+
2893+
#ifndef MONO_SCOPE_ENABLE_JIT_EXEC
29482894
#define MONO_SCOPE_ENABLE_JIT_EXEC()
29492895
#endif
29502896

mono/mini/unwind.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,6 @@ mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len,
518518
mgreg_t **save_locations, int save_locations_len,
519519
guint8 **out_cfa)
520520
{
521-
MONO_SCOPE_ENABLE_JIT_WRITE();
522-
523521
Loc locations [NUM_HW_REGS];
524522
guint8 reg_saved [NUM_HW_REGS];
525523
int pos, reg, hwreg, cfa_reg = -1, cfa_offset = 0, offset;

0 commit comments

Comments
 (0)