unw_nto_destroy()

QNX SDP8.0C Library ReferenceAPIDeveloper

Free up resources after the application runs the libunwind command on the target process; destroy the hold on the target thread, thus allowing the thread to continue

Synopsis:

void unw_nto_destroy (void *arg)

Arguments:

arg
An opaque pointer returned by unw_nto_create().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The unw_nto_destroy() function frees up memory and other resources after the application runs the libunwind command on the target process, including the hold on the remote thread, which allows the thread to proceed. As a result, the application continues executing the target thread previously held by unw_nto_create().

The unw_nto_destroy() function takes the opaque pointer returned by unw_nto_create() and returns no value.

Returns:

0
An error occurred.
Any other value
Success.

Example:

#include "unw_nto_internal.h"
#include "os-qnx.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/procfs.h>
#include <sys/neutrino.h>
#include <unistd.h>


/**
 * Continues a (held) thread.
 * @param[in] ctl_fd  File descriptor for /proc process ctl file
 * @param[in] tid     Identifies thread to continue
 *
 * @returns 0 on error, otherwise on success.
 */
static void _cont_thread (int ctl_fd, pthread_t tid)
{
  procfs_threadctl tctl =
  {
    .cmd = _NTO_TCTL_ONE_THREAD_CONT,
    .tid = tid
  };
  memcpy (tctl.data, & (tid), sizeof (tid));
  int ret = devctl (ctl_fd, DCMD_PROC_THREADCTL, &tctl, sizeof (tctl), NULL);

  if (ret != EOK)
    {
      Debug (0, "error %d continuing thread %d: %s\n",
             ret, tid, strerror (ret));
    }
}


/**
 * Tears down an NTO unwind context.
 */
void unw_nto_destroy (void *arg)
{
  unw_nto_internal_t *uni = (unw_nto_internal_t *)arg;
  int ctl_fd = unw_nto_procfs_open_ctl (uni->pid);

  if (ctl_fd < 0)
    {
      Debug (0, "error %d opening procfs ctl file for pid %d: %s\n",
             errno, uni->pid, strerror (errno));
      free (uni);
      return;
    }

  _cont_thread (ctl_fd, uni->tid);
  close (ctl_fd);
  free (uni);
}
Page updated: