Sorry, this patch is not correct. I'm canceling this patch. I'll consder it again. -- ASOU Masato
From: Masato Asou <a...@soum.co.jp> Date: Fri, 03 Apr 2020 12:24:32 +0900 (JST) > Hello, > > I made patch for print symbold of ld.so, if error was occured as > below: > > > Before apply this patch: > $ valgrind ./a.out > ==62211== Memcheck, a memory error detector > ==62211== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et > al. > ==62211== Using Valgrind-3.10.1 and LibVEX; rerun with -h for > copyright info > ==62211== Command: ./a.out > ==62211== > ==62211== Invalid write of size 1 > ==62211== at 0x4108E72: ??? > ==62211== by 0x4108374: ??? > ==62211== by 0x41096FA: ??? > ==62211== by 0x4102D4E: ??? > ==62211== by 0x4103986: ??? > ==62211== by 0x4104535: ??? > ==62211== Address 0x40052a0 is not stack'd, malloc'd or (recently) free'd > ==62211== > > </snip> > > > After apply this patch: > $ valgrind ./a.out > ==81691== Memcheck, a memory error detector > ==81691== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et > al. > ==81691== Using Valgrind-3.10.1 and LibVEX; rerun with -h for > copyright info > ==81691== Command: ./a.out > ==81691== > ==81691== Invalid write of size 1 > ==81691== at 0x4108E72: chacha_encrypt_bytes (chacha_private.h:191) > ==81691== by 0x4108374: _dl_arc4randombuf (util.c:98) > ==81691== by 0x41096FA: rbytes_init (malloc.c:187) > ==81691== by 0x4102D4E: _dl_malloc_init (in /usr/libexec/ld.so) > ==81691== by 0x4103986: _dl_boot (in /usr/libexec/ld.so) > ==81691== by 0x4104535: _dl_start (in /usr/libexec/ld.so) > ==81691== Address 0x40053e0 is not stack'd, malloc'd or (recently) free'd > ==81691== > > </snip> > > Regards > > Index: Makefile > =================================================================== > RCS file: /cvs/ports/devel/valgrind/Makefile,v > retrieving revision 1.23 > diff -u -p -r1.23 Makefile > --- Makefile 23 Dec 2019 23:26:32 -0000 1.23 > +++ Makefile 3 Apr 2020 03:12:38 -0000 > @@ -7,7 +7,7 @@ CATEGORIES = devel > > V = 3.10.1 > PV = 20160331 > -REVISION = 16 > +REVISION = 17 > DISTNAME = valgrind-${V} > EXTRACT_SUFX = .tar.bz2 > > Index: patches/patch-coregrind_m_libcfile_c > =================================================================== > RCS file: patches/patch-coregrind_m_libcfile_c > diff -N patches/patch-coregrind_m_libcfile_c > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ patches/patch-coregrind_m_libcfile_c 3 Apr 2020 03:12:38 -0000 > @@ -0,0 +1,129 @@ > +--- coregrind/m_libcfile.c > ++++ coregrind/m_libcfile.c > +@@ -40,6 +40,9 @@ > + #include "pub_core_xarray.h" > + #include "pub_core_clientstate.h" // VG_(fd_hard_limit) > + #include "pub_core_syscall.h" > ++#if defined(VGO_openbsd) > ++#include "pub_core_mallocfree.h" > ++#endif > + > + /* IMPORTANT: on Darwin it is essential to use the _nocancel versions > + of syscalls rather than the vanilla version, if a _nocancel version > +@@ -165,6 +168,90 @@ > + } > + #endif > + > ++#if defined(VGO_openbsd) > ++/* --------------------------------------------------------------------- > ++ File-descriptor tracking > ++ ------------------------------------------------------------------ */ > ++ > ++/* One of these is allocated for each open file descriptor. */ > ++typedef struct OpenFd > ++{ > ++ Int fd; /* The file descriptor */ > ++ HChar *pathname; /* NULL if not a regular file or unknown > */ > ++ struct OpenFd *next, *prev; > ++} OpenFd; > ++ > ++/* List of allocated file descriptors. */ > ++static OpenFd *opened_fds = NULL; > ++ > ++/* Note the fact that a file descriptor was just closed. */ > ++static > ++void delete_fd(Int fd) > ++{ > ++ OpenFd *i = opened_fds; > ++ > ++ while(i) { > ++ if(i->fd == fd) { > ++ if(i->prev) > ++ i->prev->next = i->next; > ++ else > ++ opened_fds = i->next; > ++ if(i->next) > ++ i->next->prev = i->prev; > ++ if(i->pathname) > ++ VG_(arena_free) (VG_AR_CORE, i->pathname); > ++ VG_(arena_free) (VG_AR_CORE, i); > ++ break; > ++ } > ++ i = i->next; > ++ } > ++} > ++ > ++/* Note the fact that a file descriptor was just opened. */ > ++static > ++void register_fd(Int fd, const HChar *pathname) > ++{ > ++ OpenFd *i; > ++ > ++ /* Check to see if this fd is already open. */ > ++ i = opened_fds; > ++ while (i) { > ++ if (i->fd == fd) { > ++ if (i->pathname) VG_(arena_free)(VG_AR_CORE, i->pathname); > ++ break; > ++ } > ++ i = i->next; > ++ } > ++ > ++ /* Not already one: allocate an OpenFd */ > ++ if (i == NULL) { > ++ i = VG_(arena_malloc)(VG_AR_CORE, "libcfile.regfd.1", sizeof(OpenFd)); > ++ > ++ i->prev = NULL; > ++ i->next = opened_fds; > ++ if(opened_fds) opened_fds->prev = i; > ++ opened_fds = i; > ++ } > ++ > ++ i->fd = fd; > ++ i->pathname = VG_(arena_strdup)(VG_AR_CORE, "libcfile.regfd.2", > pathname); > ++} > ++ > ++extern char *VG_(pathname_by_fd)(Int); > ++ > ++char * > ++VG_(pathname_by_fd)(Int fd) > ++{ > ++ OpenFd *a; > ++ > ++ for (a = opened_fds; a; a = a->next) { > ++ if (a->fd == fd && a->pathname) > ++ return a->pathname; > ++ } > ++ return NULL; > ++} > ++#endif > ++ > + SysRes VG_(open) ( const HChar* pathname, Int flags, Int mode ) > + { > + # if defined(VGP_arm64_linux) > +@@ -174,6 +261,15 @@ > + # elif defined(VGO_linux) || defined(VGO_freebsd) || defined(VGO_openbsd) > + SysRes res = VG_(do_syscall3)(__NR_open, > + (UWord)pathname, flags, mode); > ++# if defined(VGO_openbsd) > ++ if ( !sr_isError(res) ) { > ++ // Track opened files by Valgrind so that we can look up filenames for > ++ // mapped vnodes via the recorded table, instead of relying on procfs > ++ // or kvm. This is possible as all executables and related files > ++ // (dynamic linkder etc.) are all opened by host (Valgrind). > ++ register_fd(sr_Res(res), pathname); > ++ } > ++# endif > + # elif defined(VGO_darwin) > + SysRes res = VG_(do_syscall3)(__NR_open_nocancel, > + (UWord)pathname, flags, mode); > +@@ -198,6 +294,9 @@ > + /* Hmm. Return value is not checked. That's uncool. */ > + # if defined(VGO_linux) || defined(VGO_freebsd) || defined(VGO_openbsd) > + (void)VG_(do_syscall1)(__NR_close, fd); > ++# if defined(VGO_openbsd) > ++ delete_fd(fd); > ++# endif > + # elif defined(VGO_darwin) > + (void)VG_(do_syscall1)(__NR_close_nocancel, fd); > + # else > Index: patches/patch-coregrind_m_syswrap_priv_syswrap_generic_h > =================================================================== > RCS file: patches/patch-coregrind_m_syswrap_priv_syswrap_generic_h > diff -N patches/patch-coregrind_m_syswrap_priv_syswrap_generic_h > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ patches/patch-coregrind_m_syswrap_priv_syswrap_generic_h 3 Apr 2020 > 03:12:38 -0000 > @@ -0,0 +1,11 @@ > +--- coregrind/m_syswrap/priv_syswrap-generic.h > ++++ coregrind/m_syswrap/priv_syswrap-generic.h > +@@ -95,8 +95,6 @@ void ML_(PRE_unknown_ioctl)(ThreadId tid, UWord request, > UWord arg); > + extern > + void ML_(POST_unknown_ioctl)(ThreadId tid, UInt res, UWord request, UWord > arg); > + > +-char *VG_(pathname_by_fd)(Int fd); > +- > + > + DECL_TEMPLATE(generic, sys_ni_syscall); // * P -- unimplemented > + DECL_TEMPLATE(generic, sys_exit); > Index: patches/patch-coregrind_m_syswrap_syswrap_generic_c > =================================================================== > RCS file: > /cvs/ports/devel/valgrind/patches/patch-coregrind_m_syswrap_syswrap_generic_c,v > retrieving revision 1.1 > diff -u -p -r1.1 patch-coregrind_m_syswrap_syswrap_generic_c > --- patches/patch-coregrind_m_syswrap_syswrap_generic_c 23 Dec 2019 > 23:26:32 -0000 1.1 > +++ patches/patch-coregrind_m_syswrap_syswrap_generic_c 3 Apr 2020 > 03:12:38 -0000 > @@ -14,3 +14,25 @@ > arg5, arg6); > > /* A refinement: it may be that the kernel refused aspacem's choice > +@@ -4480,21 +4480,6 @@ PRE(sys_sethostname) > + #undef PRE > + #undef POST > + > +-#if defined(VGO_openbsd) > +- > +-char * > +-VG_(pathname_by_fd)(Int fd) > +-{ > +- OpenFd *a; > +- > +- for (a = allocated_fds; a; a = a->next) { > +- if (a->fd == fd && a->pathname) > +- return a->pathname; > +- } > +- return NULL; > +-} > +-#endif > +- > + #endif // defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_freebsd) > || defined(VGO_openbsd) > + > + /*--------------------------------------------------------------------*/ > Index: patches/patch-coregrind_m_ume_main_c > =================================================================== > RCS file: patches/patch-coregrind_m_ume_main_c > diff -N patches/patch-coregrind_m_ume_main_c > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ patches/patch-coregrind_m_ume_main_c 3 Apr 2020 03:12:38 -0000 > @@ -0,0 +1,23 @@ > +--- coregrind/m_ume/main.c > ++++ coregrind/m_ume/main.c > +@@ -80,20 +80,6 @@ VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd, > Bool allow_setuid) > + } > + fd = sr_Res(res); > + > +-#if defined(VGO_openbsd) > +- extern Int VG_(fd_hard_limit); > +- void ML_(record_fd_open_with_given_name)(ThreadId tid, Int fd, char > *pathname); > +- > +- // Track opened files by Valgrind so that we can look up filenames for > mapped > +- // vnodes via the recorded table, instead of relying on procfs or kvm. > This is > +- // possible as all executables and related files (dynamic linkder etc.) > are all > +- // opened by host (Valgrind). > +- VG_(fd_hard_limit) = 10; > +- ML_(record_fd_open_with_given_name)(-1, fd, exe_name); > +- ML_(mark_fd_as_internal)(-1, fd); > +- VG_(fd_hard_limit) = -1; > +-#endif > +- > + // Check we have execute permissions > + ret = VG_(check_executable)(&is_setuid, exe_name, allow_setuid); > + if (0 != ret) { > -- > ASOU Masato