/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* interface to continue a target process (DIRECT_MODE) and helper
* functions needed by this routine.
*/
#include "tnfctl_int.h"
#include "prb_proc.h"
#include "dbg.h"
#include <stdlib.h>
#include <errno.h>
/*
* continue the target process and return the evt it stopped on.
* If child_hndl is set and we see a fork, return a handle on child
* process.
*/
{
/* set my_evt to something other than TNFCTL_EVENT_TARGGONE */
/* this interface only works for DIRECT_MODE clients */
return (TNFCTL_ERR_BADARG);
return (tnfctl_status_map(errno));
/*
* XXXX block all signals. Synchronous signals like SEGV that
* the user could catch and handle will now result in a core dump.
* But, this is very unlikely for 2 reasons - most users don't try
* to handle synchronous signals - it usually just aborts the process.
* And, secondly, the code until we return the original mask is the
* place where this synchronous signal would be generated - and, it
* is not very much code.
*/
return (tnfctl_status_map(errno));
/*
* Target is stopped on entry because tnfctl_continue()
* only returns with a stopped target.
*/
/* target process shouldn't be stopped when link maps are incosistent */
if (prexstat) {
if (my_evt == TNFCTL_EVENT_TARGGONE ||
my_evt == TNFCTL_EVENT_EXIT) {
/*
* target exited - free obj list and probe
* list so that we keep our internal state
* correct, else probe control interfaces will
* have wrong information.
*/
return (TNFCTL_ERR_NONE);
} else if (my_evt == TNFCTL_EVENT_EXEC) {
return (TNFCTL_ERR_NONE);
} else if (prexstat == TNFCTL_ERR_FILENOTFOUND) {
return (TNFCTL_ERR_NOPROCESS);
} else {
return (prexstat);
}
}
if (my_evt == TNFCTL_EVENT_FORK) {
/*
* sanity check. we should only get here if child_hndl is set
*/
if (child_hndl) {
if (prbstat) {
return (prexstat);
}
return (prexstat);
}
return (TNFCTL_ERR_NONE);
}
/*
* update state in handle
* REMIND: Only need to call _tnfctl_refresh_process on
* dlopen or dlclose. Need to take out other functionality
* of refresh_process into a separate function that should
* be called here.
*/
return (prexstat);
}
/* see if we have more detail about the event */
return (TNFCTL_ERR_NONE);
}
/*
* Continues target and waits for it to stop.
* warning: This routine returns TNFCTL_EVENT_DLOPEN for any kind of
* dl activity. Up to the caller to determine the actual DL event.
*/
static tnfctl_errcode_t
{
/* set up state before we run process */
if (prexstat)
return (prexstat);
/* resume target */
if (prbstat) {
goto end_of_func;
}
/* wait on target to stop (standby) */
if (prbstat) {
if (prbstat2) {
goto end_of_func;
}
/* target process finished */
if (hndl->called_exit)
*evt = TNFCTL_EVENT_EXIT;
else
/* return directly - process no longer around */
return (TNFCTL_ERR_INTERNAL);
} else {
goto end_of_func;
}
}
if (prbstat) {
goto end_of_func;
}
if (state.ps_isbptfault) {
/* dlopen or dlclose */
if (prbstat) {
goto end_of_func;
}
/*
* actually don't know if it is a dlopen or dlclose yet.
* But, we return dlopen here. Up to the caller to determine
* which one it actually is.
*/
} else
if (state.ps_issysentry) {
switch (state.ps_syscallnum) {
case SYS_execve:
*evt = TNFCTL_EVENT_EXEC;
break;
case SYS_exit:
goto again;
default:
break;
}
} else if (state.ps_issysexit) {
switch (state.ps_syscallnum) {
case SYS_vfork:
case SYS_forksys:
*evt = TNFCTL_EVENT_FORK;
break;
default:
break;
}
}
/*
* disable all our sycall tracing and bpt setup in process when it
* is stopped, so that even if the controlling process aborts,
* the target could continue running
*/
if (prexstat)
return (prexstat);
return (ret_prexstat);
}
/*
* enable the system call tracing and dl activity tracing
*/
static tnfctl_errcode_t
{
/* trace exec */
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
/* trace exit */
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
/* trace fork if the caller requests */
if (watch_forks) {
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
}
/*
* tracing flags for fork and exec will get unset when
* process stops. see disable_target_state()
*/
/* setup process to stop during dlopen() or dlclose() */
return (_tnfctl_map_to_errcode(prbstat));
}
/*
* disable the system call tracing and dl activity tracing
*/
static tnfctl_errcode_t
{
/* remove the stalking breakpoint while the process is stopped */
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
/* remove the exec, exit and fork tracing while stopped */
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
if (prbstat)
return (_tnfctl_map_to_errcode(prbstat));
return (TNFCTL_ERR_NONE);
}