Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Sample code for calculating physical memory in QNX4.
Ref. No. QNX.000009575
Category(ies) Kernel, Development
Issue Is there a way to calculate the physical memory location of a particular process and if so, how would you do it?

Solution Yes, here is some sample code on how to do this.

#include <sys/types.h>
#include <sys/seginfo.h>
#include <sys/inline.h>
#include <i86.h>

int
vtop(caddr_t v, paddr_t *p)
{
        unsigned long l = (unsigned long)v;
        int            sel;
        struct _seginfo d;
        if (qnx_segment_info(0,0, _ds(), &d) != _ds() ||
          (sel=qnx_segment_overlay(d.addr+(v&~(PAGESIZE-1)), PAGESIZE,
                                    _PMF_VOVERLAY)) == -1 ||
                qnx_segment_info(0,0,sel, &d) != sel) {
                return -1;
        }
        *p = d.addr+(v&(PAGESIZE-1));
        return 0;
}