logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: /dev/mem access from phpextension (from .so file)
Author
linto.thomas



Joined: 17 Apr 2013
Posts: 5
Location: India

PostPosted: Thu 18 Apr '13 11:15    Post subject: /dev/mem access from phpextension (from .so file) Reply with quote

I need to write some configuration to hardware by accessing /dev/mem from apache but the function 'open("/dev/mem",O_RDWR)' in php extension returns '-1' ,permission denied

if any body knows how to solve this problem please help

thanks in advance

linto
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7405
Location: EU, Germany, Next to Hamburg

PostPosted: Tue 23 Apr '13 10:53    Post subject: Reply with quote

I guess the apache process has no rights / permission to write to it. Which chmod has /dev/mem ?
Back to top
linto.thomas



Joined: 17 Apr 2013
Posts: 5
Location: India

PostPosted: Tue 23 Apr '13 13:09    Post subject: Reply with quote

-bash-4.2# ls -l /dev/mem*
crw-r----- 1 root kmem 1, 1 Dec 31 19:00 /dev/mem

I add a user www and add the user in root ,kmem,wheel groups .

if i log in as www and run a sample C code to open it will work . the same user is used in httpd.conf
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7405
Location: EU, Germany, Next to Hamburg

PostPosted: Tue 23 Apr '13 13:29    Post subject: Reply with quote

Open yes, but the group is only allowed to read, not to write. So you should allow the group to write!

Code:
chmod g+w /dev/mem
Back to top
linto.thomas



Joined: 17 Apr 2013
Posts: 5
Location: India

PostPosted: Tue 23 Apr '13 13:59    Post subject: Reply with quote

but open itself return -1
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7405
Location: EU, Germany, Next to Hamburg

PostPosted: Tue 23 Apr '13 15:25    Post subject: Reply with quote

-1 is false. So it does not seem to work.

You might try to get a better error message.

Code:

int fd;
   if ((fd=open("/dev/mem", O_RDWR)) < 0)
   {
      fprintf(stderr, "Fehler beim öffnen von /dev/mem\n");
      exit(1);
   }
Back to top
linto.thomas



Joined: 17 Apr 2013
Posts: 5
Location: India

PostPosted: Wed 24 Apr '13 12:36    Post subject: Reply with quote

I also use the same code and the handle fd returns -1
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7405
Location: EU, Germany, Next to Hamburg

PostPosted: Wed 24 Apr '13 18:24    Post subject: Reply with quote

I googled a bit and found out that the linux kernel disables the access to /dev/mem for non root users

google CONFIG_STRICT_DEVMEM

So I think you have to find another way to access the memory. maybe mmap ? See also the proved answer in http://stackoverflow.com/questions/647783/direct-memory-access-in-linux
Back to top
linto.thomas



Joined: 17 Apr 2013
Posts: 5
Location: India

PostPosted: Thu 25 Apr '13 15:03    Post subject: Reply with quote

error value 22
EINVAL
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7405
Location: EU, Germany, Next to Hamburg

PostPosted: Thu 25 Apr '13 15:15    Post subject: Reply with quote

I think you should ask a linux kernel guy about that.
Back to top


Reply to topic   Topic: /dev/mem access from phpextension (from .so file) View previous topic :: View next topic
Post new topic   Forum Index -> Apache