--- coregrind/m_scheduler/scheduler.c.orig
+++ coregrind/m_scheduler/scheduler.c
@@ -854,6 +854,9 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
    volatile ThreadState* tst            = NULL; /* stop gcc complaining */
    volatile Int          done_this_time = 0;
    volatile HWord        host_code_addr = 0;
+#if defined(__OpenBSD__)
+   volatile UInt         host_code_len  = 0;
+#endif

    /* Paranoia */
    vg_assert(VG_(is_valid_tid)(tid));
@@ -879,8 +882,15 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
    } else {
       /* normal case -- redir translation */
       UInt cno = (UInt)VG_TT_FAST_HASH((Addr)tst->arch.vex.VG_INSTR_PTR);
+#if defined(__OpenBSD__)
+      if (LIKELY(VG_(tt_fast)[cno].guest == (Addr)tst->arch.vex.VG_INSTR_PTR)) {
+         host_code_addr = VG_(tt_fast)[cno].host;
+         host_code_len  = VG_(tt_fast)[cno].len;
+      }
+#else
       if (LIKELY(VG_(tt_fast)[cno].guest == (Addr)tst->arch.vex.VG_INSTR_PTR))
          host_code_addr = VG_(tt_fast)[cno].host;
+#endif
       else {
          AddrH res   = 0;
          /* not found in VG_(tt_fast). Searching here the transtab
@@ -932,6 +942,22 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
    vg_assert(VG_(in_generated_code) == False);
    VG_(in_generated_code) = True;

+#if defined(__OpenBSD__)
+   if (host_code_len > 0) {
+      SysRes  sres;
+
+      /* Protect the guard areas. */
+      sres = VG_(am_do_mprotect_NO_NOTIFY)(
+         host_code_addr, host_code_len,
+         VKI_PROT_READ | VKI_PROT_EXEC
+      );
+      if (sr_isError(sres)) {
+         VG_(printf)("valgrind: m_ume.c: mprotect failed\n");
+         vg_assert(0);
+      }
+   }
+#endif
+
    SCHEDSETJMP(
       tid,
       jumped,
@@ -942,6 +968,22 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
       )
    );

+#if defined(__OpenBSD__)
+   if (host_code_len > 0) {
+      SysRes  sres;
+
+      /* Protect the guard areas. */
+      sres = VG_(am_do_mprotect_NO_NOTIFY)(
+         host_code_addr, host_code_len,
+         VKI_PROT_READ | VKI_PROT_WRITE | VKI_PROT_EXEC
+      );
+      if (sr_isError(sres)) {
+         VG_(printf)("valgrind: m_ume.c: mprotect failed\n");
+         vg_assert(0);
+      }
+   }
+#endif
+
    vg_assert(VG_(in_generated_code) == True);
    VG_(in_generated_code) = False;

