#define VGA_CLREQ_ARGS guest_RAX
#define VGA_CLREQ_RET guest_RDX
-#define VGA_PTHREQ_RET guest_RDX
// Register numbers, for vg_symtab2.c
#define VGA_R_STACK_PTR 4
#define VGA_CLREQ_ARGS guest_R0
#define VGA_CLREQ_RET guest_R0
-#define VGA_PTHREQ_RET guest_R0
// Register numbers, for vg_symtab2.c
#define VGA_R_STACK_PTR 13
request codes. A few, publically-visible, request codes are also
defined in valgrind.h, and similar headers for some tools. */
+/* Obsolete pthread-related requests */
#define VG_USERREQ__MALLOC 0x2001
#define VG_USERREQ__FREE 0x2002
-
-/* Obsolete pthread-related requests */
#define VG_USERREQ__APPLY_IN_NEW_THREAD 0x3001
#define VG_USERREQ__QUIT 0x3002
#define VG_USERREQ__WAIT_JOINER 0x3003
#define VG_USERREQ__PTHREAD_KEY_DELETE 0x3014
#define VG_USERREQ__PTHREAD_SETSPECIFIC_PTR 0x3015
#define VG_USERREQ__PTHREAD_GETSPECIFIC_PTR 0x3016
+#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017
#define VG_USERREQ__PTHREAD_SIGMASK 0x3018
#define VG_USERREQ__SIGWAIT 0x3019
#define VG_USERREQ__PTHREAD_KILL 0x301A
#define VG_USERREQ__PTHREAD_ERROR 0x3102
-#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3017
-
/* Internal equivalent of VALGRIND_PRINTF . */
#define VG_USERREQ__INTERNAL_PRINTF 0x3103
/* Internal equivalent of VALGRIND_PRINTF_BACKTRACE . (no longer used) */
Exports of vg_defaults.c
------------------------------------------------------------------ */
-extern Bool VG_(tl_malloc_called_by_scheduler);
+extern Bool VG_(tl_malloc_called_deliberately);
SET_THREAD_REG(zztid, zzval, CLREQ_RET, post_reg_write_clientcall_return, \
zztid, O_CLREQ_RET, sizeof(UWord), f)
-#define SET_PTHREQ_ESP(zztid, zzval) \
- SET_THREAD_REG(zztid, zzval, STACK_PTR, post_reg_write, \
- Vg_CorePThread, zztid, O_STACK_PTR, sizeof(Addr))
-
-#define SET_PTHREQ_RETVAL(zztid, zzval) \
- SET_THREAD_REG(zztid, zzval, PTHREQ_RET, post_reg_write, \
- Vg_CorePThread, zztid, O_PTHREQ_RET, sizeof(UWord))
-
/* ---------------------------------------------------------------------
Exports of vg_signals.c
------------------------------------------------------------------ */
#define STACK_PTR(regs) ((regs).vex.VGA_STACK_PTR)
#define FRAME_PTR(regs) ((regs).vex.VGA_FRAME_PTR)
#define CLREQ_ARGS(regs) ((regs).vex.VGA_CLREQ_ARGS)
-#define PTHREQ_RET(regs) ((regs).vex.VGA_PTHREQ_RET)
#define CLREQ_RET(regs) ((regs).vex.VGA_CLREQ_RET)
// Offsets for the Vex state
#define O_STACK_PTR (offsetof(VexGuestArchState, VGA_STACK_PTR))
#define O_FRAME_PTR (offsetof(VexGuestArchState, VGA_FRAME_PTR))
#define O_CLREQ_RET (offsetof(VexGuestArchState, VGA_CLREQ_RET))
-#define O_PTHREQ_RET (offsetof(VexGuestArchState, VGA_PTHREQ_RET))
// Setting up the initial thread (1) state
__attribute__ ((weak))
SizeT VG_(vg_malloc_redzone_szB) = 8;
-Bool VG_(tl_malloc_called_by_scheduler) = False;
-
-/* If the tool hasn't replaced malloc(), this one can be called from the
- scheduler, for the USERREQ__MALLOC user request used by vg_libpthread.c.
- (Nb: it cannot call glibc's malloc().) The lock variable ensures that the
- scheduler is the only place this can be called from; this ensures that a
- malloc()-replacing tool cannot forget to implement TL_(malloc)() or
- TL_(free)(). */
+Bool VG_(tl_malloc_called_deliberately) = False;
+
+/* If the tool hasn't replaced malloc(), this one can be called
+ deliberately. The lock variable ensures that this isn't called by
+ accident, which could happen if a malloc()-replacing tool forgot to
+ implement TL_(malloc)() or TL_(free)(). */
__attribute__ ((weak))
void* TL_(malloc)( ThreadId tid, SizeT size )
{
- if (VG_(tl_malloc_called_by_scheduler))
+ if (VG_(tl_malloc_called_deliberately))
return VG_(cli_malloc)(VG_MIN_MALLOC_SZB, size);
else
malloc_panic(__PRETTY_FUNCTION__);
void TL_(free)( ThreadId tid, void* p )
{
/* see comment for TL_(malloc)() above */
- if (VG_(tl_malloc_called_by_scheduler))
+ if (VG_(tl_malloc_called_deliberately))
VG_(cli_free)(p);
else
malloc_panic(__PRETTY_FUNCTION__);
tst = VG_(get_ThreadState)(VG_(get_running_tid)());
- VG_(sk_malloc_called_by_scheduler) = True;
- data = SK_(malloc)(sizeof(*data));
- VG_(sk_malloc_called_by_scheduler) = False;
+ // XXX: why use TL_(malloc)() here? What characteristics does this
+ // allocation require?
+ // [Possible: When using a tool that replaces malloc(), we want to call
+ // the replacement version. Otherwise, we want to use VG_(cli_malloc)().
+ // So we go via the default version of TL_(malloc)() in vg_default?]
+ VG_(tl_malloc_called_deliberately) = True;
+ data = TL_(malloc)(sizeof(*data));
+ VG_(tl_malloc_called_deliberately) = False;
VG_TRACK(pre_mem_write, Vg_CorePThread, tst->tid, "new thread data",
(Addr)data, sizeof(*data));
break;
}
- /* Note: for tools that replace malloc() et al, we want to call
- the replacement versions. For those that don't, we want to call
- VG_(cli_malloc)() et al. We do this by calling SK_(malloc)(), which
- malloc-replacing tools must replace, but have the default definition
- of SK_(malloc)() call VG_(cli_malloc)(). */
-
- /* Note: for MALLOC and FREE, must set the appropriate "lock"... see
- the comment in vg_defaults.c/SK_(malloc)() for why. */
- case VG_USERREQ__MALLOC:
- VG_(tl_malloc_called_by_scheduler) = True;
- SET_PTHREQ_RETVAL(
- tid, (Addr)TL_(malloc) ( tid, arg[1] )
- );
- VG_(tl_malloc_called_by_scheduler) = False;
- break;
-
- case VG_USERREQ__FREE:
- VG_(tl_malloc_called_by_scheduler) = True;
- TL_(free) ( tid, (void*)arg[1] );
- VG_(tl_malloc_called_by_scheduler) = False;
- SET_PTHREQ_RETVAL(tid, 0); /* irrelevant */
- break;
-
case VG_USERREQ__RUNNING_ON_VALGRIND:
SET_CLREQ_RETVAL(tid, RUNNING_ON_VALGRIND+1);
break;
- case VG_USERREQ__READ_MILLISECOND_TIMER:
- SET_PTHREQ_RETVAL(tid, VG_(read_millisecond_timer)());
- break;
-
case VG_USERREQ__PRINTF: {
int count =
VG_(vmessage)( Vg_ClientMsg, (char *)arg[1], (void*)arg[2] );
case VG_USERREQ__PTHREAD_KEY_DELETE:
case VG_USERREQ__PTHREAD_SETSPECIFIC_PTR:
case VG_USERREQ__PTHREAD_GETSPECIFIC_PTR:
+ case VG_USERREQ__READ_MILLISECOND_TIMER:
case VG_USERREQ__PTHREAD_SIGMASK:
case VG_USERREQ__SIGWAIT:
case VG_USERREQ__PTHREAD_KILL:
case VG_USERREQ__GET_SIGRT_MIN:
case VG_USERREQ__GET_SIGRT_MAX:
case VG_USERREQ__ALLOC_RTSIG:
+ case VG_USERREQ__MALLOC:
+ case VG_USERREQ__FREE:
VG_(message)(Vg_UserMsg, "It looks like you've got an old libpthread.so* ");
VG_(message)(Vg_UserMsg, "installed in \"%s\".", VG_(libdir));
VG_(message)(Vg_UserMsg, "Please delete it and try again.");
#define VGA_CLREQ_ARGS guest_EAX
#define VGA_CLREQ_RET guest_EDX
-#define VGA_PTHREQ_RET guest_EDX
-
// Register numbers, for vg_symtab2.c
#define VGA_R_STACK_PTR 4