2008-02-22 Mark Probst <mark.probst@gmail.com>
[mono.git] / mono / mini / tramp-amd64.c
1 /*
2  * tramp-x86.c: JIT trampoline code for x86
3  *
4  * Authors:
5  *   Dietmar Maurer (dietmar@ximian.com)
6  *
7  * (C) 2001 Ximian, Inc.
8  */
9
10 #include <config.h>
11 #include <glib.h>
12
13 #include <mono/metadata/appdomain.h>
14 #include <mono/metadata/marshal.h>
15 #include <mono/metadata/tabledefs.h>
16 #include <mono/metadata/mono-debug-debugger.h>
17 #include <mono/arch/amd64/amd64-codegen.h>
18
19 #ifdef HAVE_VALGRIND_MEMCHECK_H
20 #include <valgrind/memcheck.h>
21 #endif
22
23 #include "mini.h"
24 #include "mini-amd64.h"
25
26 #define IS_REX(inst) (((inst) >= 0x40) && ((inst) <= 0x4f))
27
28 static guint8* nullified_class_init_trampoline;
29
30 /*
31  * mono_arch_get_unbox_trampoline:
32  * @m: method pointer
33  * @addr: pointer to native code for @m
34  *
35  * when value type methods are called through the vtable we need to unbox the
36  * this argument. This method returns a pointer to a trampoline which does
37  * unboxing before calling the method
38  */
39 gpointer
40 mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
41 {
42         guint8 *code, *start;
43         int this_reg = AMD64_ARG_REG1;
44
45         MonoDomain *domain = mono_domain_get ();
46
47         if (!mono_method_signature (m)->ret->byref && MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
48                 this_reg = AMD64_ARG_REG2;
49
50         mono_domain_lock (domain);
51         start = code = mono_code_manager_reserve (domain->code_mp, 20);
52         mono_domain_unlock (domain);
53
54         amd64_alu_reg_imm (code, X86_ADD, this_reg, sizeof (MonoObject));
55         /* FIXME: Optimize this */
56         amd64_mov_reg_imm (code, AMD64_RAX, addr);
57         amd64_jump_reg (code, AMD64_RAX);
58         g_assert ((code - start) < 20);
59
60         mono_arch_flush_icache (start, code - start);
61
62         return start;
63 }
64
65 /*
66  * mono_arch_patch_callsite:
67  *
68  *   Patch the callsite whose address is given by ORIG_CODE so it calls ADDR. ORIG_CODE
69  * points to the pc right after the call.
70  */
71 void
72 mono_arch_patch_callsite (guint8 *orig_code, guint8 *addr)
73 {
74         guint8 *code;
75         guint8 buf [16];
76         gboolean can_write = mono_breakpoint_clean_code (orig_code - 14, buf, sizeof (buf));
77
78         code = buf + 14;
79
80         if (((code [-13] == 0x49) && (code [-12] == 0xbb)) || (code [-5] == 0xe8)) {
81                 if (code [-5] != 0xe8) {
82                         if (can_write)
83                                 InterlockedExchangePointer ((gpointer*)(orig_code - 11), addr);
84                 } else {
85                         if ((((guint64)(addr)) >> 32) != 0) {
86                                 /* Print some diagnostics */
87                                 MonoJitInfo *ji = mono_jit_info_table_find (mono_domain_get (), (char*)orig_code);
88                                 if (ji)
89                                         fprintf (stderr, "At %s, offset 0x%zx\n", mono_method_full_name (ji->method, TRUE), (guint8*)orig_code - (guint8*)ji->code_start);
90                                 fprintf (stderr, "Addr: %p\n", addr);
91                                 ji = mono_jit_info_table_find (mono_domain_get (), (char*)addr);
92                                 if (ji)
93                                         fprintf (stderr, "Callee: %s\n", mono_method_full_name (ji->method, TRUE));
94                                 g_assert_not_reached ();
95                         }
96                         g_assert ((((guint64)(orig_code)) >> 32) == 0);
97                         if (can_write)
98                                 InterlockedExchange ((gint32*)(orig_code - 4), ((gint64)addr - (gint64)orig_code));
99                 }
100         }
101         else if ((code [-7] == 0x41) && (code [-6] == 0xff) && (code [-5] == 0x15)) {
102                 /* call *<OFFSET>(%rip) */
103                 gpointer *got_entry = (gpointer*)((guint8*)orig_code + (*(guint32*)(orig_code - 4)));
104                 if (can_write)
105                         InterlockedExchangePointer (got_entry, addr);
106         }
107 }
108
109 void
110 mono_arch_patch_plt_entry (guint8 *code, guint8 *addr)
111 {
112         gint32 disp;
113         gpointer *plt_jump_table_entry;
114
115         /* A PLT entry: jmp *<DISP>(%rip) */
116         g_assert (code [0] == 0xff);
117         g_assert (code [1] == 0x25);
118
119         disp = *(gint32*)(code + 2);
120
121         plt_jump_table_entry = (gpointer*)(code + 6 + disp);
122
123         InterlockedExchangePointer (plt_jump_table_entry, addr);
124 }
125
126 void
127 mono_arch_nullify_class_init_trampoline (guint8 *code, gssize *regs)
128 {
129         code -= 3;
130
131         /* 
132          * A given byte sequence can match more than case here, so we have to be
133          * really careful about the ordering of the cases. Longer sequences
134          * come first.
135          */
136         if ((code [-4] == 0x41) && (code [-3] == 0xff) && (code [-2] == 0x15)) {
137                 gpointer *vtable_slot;
138
139                 /* call *<OFFSET>(%rip) */
140                 vtable_slot = mono_arch_get_vcall_slot_addr (code + 3, (gpointer*)regs);
141                 g_assert (vtable_slot);
142
143                 *vtable_slot = nullified_class_init_trampoline;
144         } else if (code [-2] == 0xe8) {
145                 /* call <TARGET> */
146                 guint8 *buf = code - 2;
147
148                 buf [0] = 0x66;
149                 buf [1] = 0x66;
150                 buf [2] = 0x90;
151                 buf [3] = 0x66;
152                 buf [4] = 0x90;
153         } else if ((code [0] == 0x41) && (code [1] == 0xff)) {
154                 /* call <REG> */
155                 /* happens on machines without MAP_32BIT like freebsd */
156                 /* amd64_set_reg_template is 10 bytes long */
157                 guint8* buf = code - 10;
158
159                 /* FIXME: Make this thread safe */
160                 /* Padding code suggested by the AMD64 Opt Manual */
161                 buf [0] = 0x66;
162                 buf [1] = 0x66;
163                 buf [2] = 0x66;
164                 buf [3] = 0x90;
165                 buf [4] = 0x66;
166                 buf [5] = 0x66;
167                 buf [6] = 0x66;
168                 buf [7] = 0x90;
169                 buf [8] = 0x66;
170                 buf [9] = 0x66;
171                 buf [10] = 0x90;
172                 buf [11] = 0x66;
173                 buf [12] = 0x90;
174         } else if (code [0] == 0x90 || code [0] == 0xeb || code [0] == 0x66) {
175                 /* Already changed by another thread */
176                 ;
177         } else {
178                 printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
179                                 code [4], code [5], code [6]);
180                 g_assert_not_reached ();
181         }
182 }
183
184 void
185 mono_arch_nullify_plt_entry (guint8 *code)
186 {
187         mono_arch_patch_plt_entry (code, nullified_class_init_trampoline);
188 }
189
190 guchar*
191 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
192 {
193         guint8 *buf, *code, *tramp, *br [2];
194         int i, lmf_offset, offset, res_offset, arg_offset, tramp_offset, saved_regs_offset, saved_fpregs_offset, framesize;
195         gboolean has_caller;
196
197         if (tramp_type == MONO_TRAMPOLINE_JUMP)
198                 has_caller = FALSE;
199         else
200                 has_caller = TRUE;
201
202         code = buf = mono_global_codeman_reserve (512);
203
204         framesize = 512 + sizeof (MonoLMF);
205         framesize = (framesize + (MONO_ARCH_FRAME_ALIGNMENT - 1)) & ~ (MONO_ARCH_FRAME_ALIGNMENT - 1);
206
207         offset = 0;
208
209         if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT) {
210                 static int byte_offset = -1;
211                 static guint8 bitmask;
212
213                 guint8 *jump;
214
215                 if (byte_offset < 0)
216                         mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
217
218                 amd64_test_membase_imm_size (code, MONO_ARCH_VTABLE_REG, byte_offset, bitmask, 1);
219                 jump = code;
220                 amd64_branch8 (code, X86_CC_Z, -1, 1);
221
222                 amd64_ret (code);
223
224                 x86_patch (jump, code);
225         }
226
227         /*
228          * The generic class init trampoline is called directly by
229          * JITted code, there is no specific trampoline.  The lazy
230          * fetch trampolines behave like generic class init
231          * trampolines.
232          */
233         if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT &&
234                         tramp_type != MONO_TRAMPOLINE_RGCTX_LAZY_FETCH) {
235                 /* Pop the return address off the stack */
236                 amd64_pop_reg (code, AMD64_R11);
237         }
238
239         /* 
240          * Allocate a new stack frame
241          */
242         amd64_push_reg (code, AMD64_RBP);
243         amd64_mov_reg_reg (code, AMD64_RBP, AMD64_RSP, 8);
244         amd64_alu_reg_imm (code, X86_SUB, AMD64_RSP, framesize);
245
246         offset += 8;
247         tramp_offset = - offset;
248
249         offset += 8;
250         arg_offset = - offset;
251
252         if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT &&
253                         tramp_type != MONO_TRAMPOLINE_RGCTX_LAZY_FETCH) {
254                 /* Compute the trampoline address from the return address */
255                 /* 5 = length of amd64_call_membase () */
256                 amd64_alu_reg_imm (code, X86_SUB, AMD64_R11, 5);
257                 amd64_mov_membase_reg (code, AMD64_RBP, tramp_offset, AMD64_R11, 8);
258         } else {
259                 amd64_mov_membase_imm (code, AMD64_RBP, tramp_offset, 0, 8);
260         }
261
262         offset += 8;
263         res_offset = - offset;
264
265         /* Save all registers */
266
267         offset += AMD64_NREG * 8;
268         saved_regs_offset = - offset;
269         for (i = 0; i < AMD64_NREG; ++i)
270                 amd64_mov_membase_reg (code, AMD64_RBP, saved_regs_offset + (i * 8), i, 8);
271         offset += 8 * 8;
272         saved_fpregs_offset = - offset;
273         for (i = 0; i < 8; ++i)
274                 amd64_movsd_membase_reg (code, AMD64_RBP, saved_fpregs_offset + (i * 8), i);
275
276         if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT &&
277                         tramp_type != MONO_TRAMPOLINE_RGCTX_LAZY_FETCH) {
278                 /* Obtain the trampoline argument which is encoded in the instruction stream */
279                 amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, tramp_offset, 8);
280                 amd64_mov_reg_membase (code, AMD64_RAX, AMD64_R11, 5, 1);
281                 amd64_widen_reg (code, AMD64_RAX, AMD64_RAX, TRUE, FALSE);
282                 amd64_alu_reg_imm_size (code, X86_CMP, AMD64_RAX, 4, 1);
283                 br [0] = code;
284                 x86_branch8 (code, X86_CC_NE, 6, FALSE);
285                 /* 32 bit immediate */
286                 amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 4);
287                 br [1] = code;
288                 x86_jump8 (code, 10);
289                 /* 64 bit immediate */
290                 mono_amd64_patch (br [0], code);
291                 amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 8);
292                 mono_amd64_patch (br [1], code);
293                 amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, AMD64_R11, 8);
294         } else {
295                 amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, MONO_ARCH_VTABLE_REG, 8);
296         }
297
298         /* Save LMF begin */
299
300         offset += sizeof (MonoLMF);
301         lmf_offset = - offset;
302
303         /* Save ip */
304         if (has_caller)
305                 amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, 8, 8);
306         else
307                 amd64_mov_reg_imm (code, AMD64_R11, 0);
308         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, rip), AMD64_R11, 8);
309         /* Save fp */
310         amd64_mov_reg_membase (code, AMD64_R11, AMD64_RSP, framesize, 8);
311         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, rbp), AMD64_R11, 8);
312         /* Save sp */
313         amd64_mov_reg_reg (code, AMD64_R11, AMD64_RSP, 8);
314         amd64_alu_reg_imm (code, X86_ADD, AMD64_R11, framesize + 16);
315         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, rsp), AMD64_R11, 8);
316         /* Save method */
317         if (tramp_type == MONO_TRAMPOLINE_GENERIC || tramp_type == MONO_TRAMPOLINE_JUMP) {
318                 amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, arg_offset, 8);
319                 amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, method), AMD64_R11, 8);
320         } else {
321                 amd64_mov_membase_imm (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, method), 0, 8);
322         }
323         /* Save callee saved regs */
324 #ifdef PLATFORM_WIN32
325         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, rdi), AMD64_RDI, 8);
326         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, rsi), AMD64_RSI, 8);
327 #endif
328         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, rbx), AMD64_RBX, 8);
329         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, r12), AMD64_R12, 8);
330         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, r13), AMD64_R13, 8);
331         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, r14), AMD64_R14, 8);
332         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, r15), AMD64_R15, 8);
333
334         amd64_mov_reg_imm (code, AMD64_R11, mono_get_lmf_addr);
335         amd64_call_reg (code, AMD64_R11);
336
337         /* Save lmf_addr */
338         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, lmf_addr), AMD64_RAX, 8);
339         /* Save previous_lmf */
340         /* Set the lowest bit to 1 to signal that this LMF has the ip field set */
341         amd64_mov_reg_membase (code, AMD64_R11, AMD64_RAX, 0, 8);
342         amd64_alu_reg_imm_size (code, X86_ADD, AMD64_R11, 1, 8);
343         amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, previous_lmf), AMD64_R11, 8);
344         /* Set new lmf */
345         amd64_lea_membase (code, AMD64_R11, AMD64_RBP, lmf_offset);
346         amd64_mov_membase_reg (code, AMD64_RAX, 0, AMD64_R11, 8);
347
348         /* Save LMF end */
349
350         /* Arg1 is the pointer to the saved registers */
351         amd64_lea_membase (code, AMD64_ARG_REG1, AMD64_RBP, saved_regs_offset);
352
353         /* Arg2 is the address of the calling code */
354         if (has_caller)
355                 amd64_mov_reg_membase (code, AMD64_ARG_REG2, AMD64_RBP, 8, 8);
356         else
357                 amd64_mov_reg_imm (code, AMD64_ARG_REG2, 0);
358
359         /* Arg3 is the method/vtable ptr */
360         amd64_mov_reg_membase (code, AMD64_ARG_REG3, AMD64_RBP, arg_offset, 8);
361
362         /* Arg4 is the trampoline address */
363         amd64_mov_reg_membase (code, AMD64_ARG_REG4, AMD64_RBP, tramp_offset, 8);
364
365         tramp = (guint8*)mono_get_trampoline_func (tramp_type);
366         amd64_mov_reg_imm (code, AMD64_RAX, tramp);
367         amd64_call_reg (code, AMD64_RAX);
368
369         /* Check for thread interruption */
370         /* This is not perf critical code so no need to check the interrupt flag */
371         amd64_mov_membase_reg (code, AMD64_RBP, res_offset, AMD64_RAX, 8);
372         amd64_mov_reg_imm (code, AMD64_RAX, (guint8*)mono_thread_interruption_checkpoint);
373         amd64_call_reg (code, AMD64_RAX);
374         amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RBP, res_offset, 8);      
375
376         /* Restore LMF */
377
378         amd64_mov_reg_membase (code, AMD64_RCX, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, previous_lmf), 8);
379         amd64_alu_reg_imm_size (code, X86_SUB, AMD64_RCX, 1, 8);
380         amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, lmf_addr), 8);
381         amd64_mov_membase_reg (code, AMD64_R11, 0, AMD64_RCX, 8);
382
383         /* Restore argument registers */
384         for (i = 0; i < AMD64_NREG; ++i)
385                 if (AMD64_IS_ARGUMENT_REG (i))
386                         amd64_mov_reg_membase (code, i, AMD64_RBP, saved_regs_offset + (i * 8), 8);
387
388         for (i = 0; i < 8; ++i)
389                 amd64_movsd_reg_membase (code, i, AMD64_RBP, saved_fpregs_offset + (i * 8));
390
391         /* Restore stack */
392         amd64_leave (code);
393
394         if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT ||
395                         tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT ||
396                         tramp_type == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
397                 amd64_ret (code);
398         else
399                 /* call the compiled method */
400                 amd64_jump_reg (code, X86_EAX);
401
402         g_assert ((code - buf) <= 512);
403
404         mono_arch_flush_icache (buf, code - buf);
405
406         if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
407                 /* Initialize the nullified class init trampoline used in the AOT case */
408                 nullified_class_init_trampoline = code = mono_global_codeman_reserve (16);
409                 x86_ret (code);
410         }
411
412         return buf;
413 }
414
415 gpointer
416 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
417 {
418         guint8 *code, *buf, *tramp;
419         int size;
420
421         tramp = mono_get_trampoline_code (tramp_type);
422
423         if ((((guint64)arg1) >> 32) == 0)
424                 size = 5 + 1 + 4;
425         else
426                 size = 5 + 1 + 8;
427
428         mono_domain_lock (domain);
429         code = buf = mono_code_manager_reserve_align (domain->code_mp, size, 1);
430         mono_domain_unlock (domain);
431
432         amd64_call_code (code, tramp);
433         /* The trampoline code will obtain the argument from the instruction stream */
434         if ((((guint64)arg1) >> 32) == 0) {
435                 *code = 0x4;
436                 *(guint32*)(code + 1) = (gint64)arg1;
437                 code += 5;
438         } else {
439                 *code = 0x8;
440                 *(guint64*)(code + 1) = (gint64)arg1;
441                 code += 9;
442         }
443
444         g_assert ((code - buf) <= size);
445
446         if (code_len)
447                 *code_len = size;
448
449         mono_arch_flush_icache (buf, size);
450
451         return buf;
452 }       
453
454 gpointer
455 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 encoded_offset)
456 {
457         guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_RGCTX_LAZY_FETCH);
458         gboolean indirect = MONO_RGCTX_OFFSET_IS_INDIRECT (encoded_offset);
459         int offset = indirect ? MONO_RGCTX_OFFSET_INDIRECT_OFFSET (encoded_offset) :
460                 MONO_RGCTX_OFFSET_DIRECT_OFFSET (encoded_offset);
461         guint8 *code, *buf, *jump;
462         guint8 *dummy;
463         int slots_reg;
464
465         g_assert (tramp);
466         if (indirect)
467                 g_assert (MONO_RGCTX_OFFSET_INDIRECT_SLOT (encoded_offset) == 0);
468
469         code = buf = mono_global_codeman_reserve (32);
470
471         /* load slots ptr */
472         if (indirect) {
473                 /* if indirect, load extra_other_infos ptr */
474                 amd64_mov_reg_membase (buf, AMD64_RAX, AMD64_ARG_REG1, G_STRUCT_OFFSET (MonoRuntimeGenericContext, extra_other_infos), 8);
475                 slots_reg = AMD64_RAX;
476         } else {
477                 slots_reg = AMD64_ARG_REG1;
478         }
479         /* fetch slot */
480         amd64_mov_reg_membase (buf, AMD64_RAX, slots_reg, offset, 8);
481
482         dummy = buf;
483
484         /* is slot null? */
485         amd64_test_reg_reg (buf, AMD64_RAX, AMD64_RAX);
486         jump = buf;
487         /* if yes, jump to actual trampoline */
488         amd64_branch8 (buf, X86_CC_Z, -1, 1);
489
490         /* if no, just return */
491         amd64_ret (buf);
492
493         x86_patch (jump, buf);
494         /* move the rgctx pointer to the VTABLE register */
495         amd64_mov_reg_reg (buf, MONO_ARCH_VTABLE_REG, AMD64_ARG_REG1, 8);
496         /* store the offset in RAX */
497         amd64_mov_reg_imm (buf, AMD64_RAX, encoded_offset);
498         /* jump to the actual trampoline */
499         amd64_jump_code (buf, tramp);
500
501         mono_arch_flush_icache (code, buf - code);
502
503         g_assert (buf - code <= 32);
504
505         return code;
506 }
507
508 guint32
509 mono_arch_get_rgctx_lazy_fetch_offset (gpointer *regs)
510 {
511         return (guint32)(gulong)(regs [AMD64_RAX]);
512 }
513
514 void
515 mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
516 {
517         /* FIXME: This is not thread safe */
518         guint8 *code = ji->code_start;
519
520         amd64_mov_reg_imm (code, AMD64_ARG_REG1, func_arg);
521         amd64_mov_reg_imm (code, AMD64_R11, func);
522
523         x86_push_imm (code, (guint64)func_arg);
524         amd64_call_reg (code, AMD64_R11);
525 }
526
527 /*
528  * This method is only called when running in the Mono Debugger.
529  */
530 gpointer
531 mono_debugger_create_notification_function (void)
532 {
533         guint8 *buf, *code;
534
535         code = buf = mono_global_codeman_reserve (2);
536         x86_breakpoint (buf);
537         x86_ret (buf);
538         return code;
539 }