Re: Valgrind: patch to run Pthread target program

2019-12-08 Thread Masato Asou
Sorry,

From: Masato Asou 
Date: Mon, 09 Dec 2019 14:50:41 +0900 (JST)

> Valgrind does not run Pthread target program.
> I made patch to run Pthread target program.

I forget increment REVISION in Makefile.
--
ASOU Masato



Valgrind: patch to run Pthread target program

2019-12-08 Thread Masato Asou
Hi, ports

Valgrind does not run Pthread target program.
I made patch to run Pthread target program.

I applied this patch and run attached main.c as:

  $ cc main.c -lpthread
  $ while :; do valgrind ./a.out 32 8; done

for 24 hours.  I got no problem.

ok?

Index: patches/patch-coregrind_m_libcsignal_c
===
RCS file: patches/patch-coregrind_m_libcsignal_c
diff -N patches/patch-coregrind_m_libcsignal_c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-coregrind_m_libcsignal_c  9 Dec 2019 05:30:18 -
@@ -0,0 +1,21 @@
+--- coregrind/m_libcsignal.c.orig
 coregrind/m_libcsignal.c
+@@ -397,6 +397,7 @@
+ Int VG_(tkill)( Int lwpid, Int signo )
+ {
+ #  if defined(__NR_tkill)
++   PRINT("sys___tfork ( %ld, %ld )",ARG1,ARG2);
+SysRes res = VG_(mk_SysRes_Error)(VKI_ENOSYS);
+res = VG_(do_syscall2)(__NR_tkill, lwpid, signo);
+if (sr_isError(res) && sr_Err(res) == VKI_ENOSYS)
+@@ -415,7 +416,9 @@
+return sr_isError(res) ? -1 : 0;
+ 
+ #  elif defined(VGO_openbsd)
+-   I_die_here;
++   SysRes res;
++   res = VG_(do_syscall3)(__NR_thrkill, lwpid, signo, NULL);
++   return sr_isError(res) ? -1 : 0;
+ 
+ #  else
+ #error "Unsupported plat"
Index: patches/patch-coregrind_m_syswrap_priv_syswrap_openbsd_h
===
RCS file: 
/cvs/ports/devel/valgrind/patches/patch-coregrind_m_syswrap_priv_syswrap_openbsd_h,v
retrieving revision 1.1
diff -u -p -r1.1 patch-coregrind_m_syswrap_priv_syswrap_openbsd_h
--- patches/patch-coregrind_m_syswrap_priv_syswrap_openbsd_h23 Oct 2019 
02:35:05 -  1.1
+++ patches/patch-coregrind_m_syswrap_priv_syswrap_openbsd_h9 Dec 2019 
05:30:18 -
@@ -1,5 +1,14 @@
 --- coregrind/m_syswrap/priv_syswrap-openbsd.h.orig
 +++ coregrind/m_syswrap/priv_syswrap-openbsd.h
+@@ -50,7 +50,7 @@
+ DECL_TEMPLATE(openbsd, sys_open);
+ DECL_TEMPLATE(openbsd, sys_close);
+ DECL_TEMPLATE(openbsd, sys_getentropy);
+-DECL_TEMPLATE(openbsd, sys___tfork);
++DECL_TEMPLATE(openbsd, sys___tfork_thread);
+ DECL_TEMPLATE(openbsd, sys_link);
+ DECL_TEMPLATE(openbsd, sys_unlink);
+ DECL_TEMPLATE(openbsd, sys_wait4);
 @@ -144,6 +144,7 @@
  DECL_TEMPLATE(openbsd, sys_pledge);
  DECL_TEMPLATE(openbsd, sys_ppoll);
Index: patches/patch-coregrind_m_syswrap_syswrap_amd64_openbsd_c
===
RCS file: patches/patch-coregrind_m_syswrap_syswrap_amd64_openbsd_c
diff -N patches/patch-coregrind_m_syswrap_syswrap_amd64_openbsd_c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-coregrind_m_syswrap_syswrap_amd64_openbsd_c   9 Dec 2019 
05:30:18 -
@@ -0,0 +1,215 @@
+--- coregrind/m_syswrap/syswrap-amd64-openbsd.c.orig
 coregrind/m_syswrap/syswrap-amd64-openbsd.c
+@@ -120,6 +120,212 @@
+ #define PRE(name)   DEFN_PRE_TEMPLATE(openbsd, name)
+ #define POST(name)  DEFN_POST_TEMPLATE(openbsd, name)
+ 
++extern UWord do_syscall_tfork_amd64_openbsd (
++Addr params,
++UWord psize,
++Addr startfunc,
++Addr startarg);
++asm(
++".text\n"
++".globl do_syscall_tfork_amd64_openbsd\n"
++"do_syscall_tfork_amd64_openbsd:\n"
++  /* Copy %rdx to %r8 and %rcx to %r9.  See:
++ - lib/libc/arch/amd64/sys/tfork_thread.S */
++" movq%rdx, %r8\n"
++" movq%rcx, %r9\n"
++" movq$8, %rax\n" /* syscall_no */
++" syscall\n"
++" jb  5f\n"   /* error */
++  /*
++   * Check to see if we are in the parent or child
++   */
++" cmpl$0, %eax\n"
++" jz  4f\n"   /* child */
++" jmp 5f\n"   /* parent */
++  /* the retpoline we'll use to call the child's main */
++".align   16, 0xcc\n" /* _ALIGN_TRAPS */
++"1:\n"/* JMP_RETPOLINE(r8) --> */
++" call3f\n"
++"2:   pause\n"
++" lfence\n"
++" jmp 2b\n"
++".align   16, 0xcc\n" /* _ALIGN_TRAPS */
++"3:   mov %r8,(%rsp)\n"
++" ret\n"
++  /* JMP_RETPOLINE(r8) <-- */
++  /*
++   * If we are in the child (new thread), then
++   * set-up the call to the internal subroutine.  If it
++   * returns, then call __threxit.
++   */
++".align   16, 0xcc\n" /* _ALIGN_TRAPS */
++"4:\n"
++" movq%r9, %rdi\n"
++" call1b\n"
++  /*
++   * Thread exit system call
++   */
++" movl$302, %eax\n"   /* 302 == SYS___threxit */
++" xorl%edi, %edi\n"
++" syscall\n"
++  /*NOTREACHED*/
++"5:\n"/* parent or error */
++" ret\n"
++".previous\n"
++);
++
++static void setup_child ( ThreadArchState*, ThreadArchState* );
++
++void setup_child ( /*OUT*/ ThreadArchState *child,
++   /*IN*/  ThreadArchState *parent )
++{
++   /* We inherit