Reading & Writing To Memory

Supposed we have the following application,which consists of more than one
files.

#include <…>
#include “function_protoypes.h”

#define ADDRESS 0x9000000

int *ptr,fd;

main()
{
fd=shm_open(“Physical”,O-RDWR,0777);
ptr=(int)mmap(0,4096,PROT_READ | PROT_WRITE,MAP_SHARED,ADDRESS);
/
… some stuff here…*/

function();

/…some more stuff here…/

}



function.c


include"funtion_protoypes.h"

function()
{
extern int *ptr;

/*…function reads and writes to memory,defined by pointer ptr…/

return 0;
}

Will the function be able to read and write to memory we wish,just by using
the ptr pointer,returned to the main by the shm_open and mmap calls??
If the function wants to read and write to the specific memory region,will
it have to call again these functions?
I am writing a device driver for a PCI network card.The function() is
supposed to do the required work,after an interrupt occurs.(the ISR
triggers the appropriate proxy,the main function checks the proxy’s pid and
then calls the respective function to do the work-in our case function().)My
purpose is to minimize the number of things to be done in the function(),so
that it’s job is very quickly done,before another interrupt occurs;that’s
why I’m trying to avoid reopening physical memory and remmaping it.Can this
be avoided?Any suggestions?
Thank you very much in advance!!

“Akis” <romeoita@yahoo.com> wrote in message
news:9de6mh$hc6$1@inn.qnx.com

Supposed we have the following application,which consists of more than
one
files.

#include <…
#include “function_protoypes.h”

#define ADDRESS 0x9000000

int *ptr,fd;

main()
{
fd=shm_open(“Physical”,O-RDWR,0777);
ptr=(int)mmap(0,4096,PROT_READ | PROT_WRITE,MAP_SHARED,ADDRESS);
/
… some stuff here…*/

function();

/…some more stuff here…/

}



function.c


include"funtion_protoypes.h"

function()
{
extern int *ptr;

/*…function reads and writes to memory,defined by pointer
ptr…/

return 0;
}

Will the function be able to read and write to memory we wish,just by
using
the ptr pointer,returned to the main by the shm_open and mmap calls??
If the function wants to read and write to the specific memory region,will
it have to call again these functions?

Yes

I am writing a device driver for a PCI network card.The function() is
supposed to do the required work,after an interrupt occurs.(the ISR
triggers the appropriate proxy,the main function checks the proxy’s pid
and
then calls the respective function to do the work-in our case
function().)My
purpose is to minimize the number of things to be done in the
function(),so
that it’s job is very quickly done,before another interrupt occurs;that’s
why I’m trying to avoid reopening physical memory and remmaping it.Can
this
be avoided?Any suggestions?

As long as you don’t unmap the pointer you are free to use it at will.
It’s the same as a file, you can read()/write() as long as you don’t
call close()


Thank you very much in advance!!
\