<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>82974</integer>
    </number>
    <user>
      <string>B</string>
    </user>
    <title>
      <string>untitled</string>
    </title>
    <contents>
      <string>#include &lt;assert.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;sys/queue.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;kvm.h&gt;

#define _KERNEL_STRUCTURES
#include &lt;sys/mqueue.h&gt;

static LIST_HEAD(, mqueue) mqueue_head =
                LIST_HEAD_INITIALIZER(mqueue_head);

static kvm_t *kd;

/*                                                                                                           
 * We need an array of nlist symbols, that                                                                   
 * terminates with a NULL n_name field.                                                                      
 */
static struct nlist symbols[] = {
        { &quot;_mqueue_head&quot; },
        { NULL }
};

int main(void)
{
        char *execfile = NULL;  /* kernel executable image */
        char *corefile = NULL;  /* kernel memory device file */
        char *swapfile = NULL;  /* swap device */

        /*                                                                                                   
         * Get a descriptor to access kernel virtual memory via the kvm(3)                                   
         * library routines. By passing NULL to the following arguments,                                     
         * we imply the respective default values.                                                           
         */
        kd = kvm_open(execfile, corefile, swapfile, O_RDONLY, &quot;pipcs&quot;);
        if (kd == NULL)
                exit(EXIT_FAILURE);

        /* Retrieve symbol table entries. */
        if (kvm_nlist(kd, symbols) == -1) {
                perror(&quot;kvm_nlist&quot;);
                exit(EXIT_FAILURE);
        }

        /* XXX: Proper error handling. */
        assert(symbols[0].n_value != 0);

        if (kvm_read(kd, symbols[0].n_value, &amp;mqueue_head, sizeof(mqueue_head))
            != sizeof(mqueue_head)) {
                perror(&quot;kvm_read&quot;);
                exit(EXIT_FAILURE);
        }

        /* We are done -- close kvm channel. */
        if (kvm_close(kd) == -1)
                exit(EXIT_FAILURE);

        /* Enumerate message queues. */
        struct mqueue mq_data;
        struct mqueue *mq;

        mq = mqueue_head.lh_first;
        if (kvm_read(kd, (unsigned long)mq,
                &amp;mq_data, sizeof(mq_data)) == sizeof(mq_data)) {
                printf(&quot;%20s %10p %8x %8x %3u %6lu %6lu %6lu\n&quot;,
                   mq_data.mq_name, mq, mq_data.mq_mode,
                    mq_data.mq_attrib.mq_flags, mq_data.mq_refcnt,
                    mq_data.mq_attrib.mq_maxmsg, mq_data.mq_attrib.mq_msgsize,
                    mq_data.mq_attrib.mq_curmsgs);
        } else {
                perror(&quot;kvm_read&quot;);
        }

        return (EXIT_SUCCESS);
}
</string>
    </contents>
    <universal-time>
      <integer>3455639875</integer>
    </universal-time>
    <channel>
      <string>None</string>
    </channel>
    <colorization-mode>
      <string>None</string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </paste>
</paste-with-annotations>
