Here are some notes that I have been providing based on my own situiation which is
very similar if not exactly the same as yours. This is working for me. Also note
that if you specify in lilo.conf append = "mem = 124m" that the operating system will
not recognize the 4 meg of shared memory. It has to do with the fact that the page
size is 4 megs. I also noticed that I used a capital M in my lilo.conf I do not know
if this would make a difference.
I hope this helps.
A while back someone asked how to setup shared memory.
I passed along a description of how I setup 3 Meg of shared
memory starting at 125 Meg and going to 128 Meg.
I have provided it below so that it may help you
determine the problem.
The problem as you have described it sounds like you may
have changed the amount of shared memory you would like
to use without changing the definition of how much you want
to use in all the necessary locations.
1.) Definition of the shared memory pointer in user space
2.) Definition of the shared memory pointer in kernel space
3.) Definition of the shared memory in lilo.conf
Make sure that all of these definitions are declared for the
same amount of shared memory. See below for an example.
I hope this helps.
Rich
> Here are my notes on how I setup and use shared memory.
>
> ----- sh_mem.h -----
>
> I created a header file called sh_mem.h that defines where
> the shared memory will begin.
>
> #define SH_MEM_BASE_ADDR (125 * 0x100000)
>
> This value is three megs below the top of physical memory (128M).
>
> It also defines the data structure for the variables I
> want to have in shared memory.
>
> typedef struct
> {
> char variable1[255];
> int variable2;
> long variable3;
> ....
>
> } RUN_DATA;
>
> I then define a function that gets the physical address and returns
> that address in the form of a pointer to my structure.
>
> RUN_DATA *get_sh_mem_ptr(void);
>
>
> ---- sh_mem.c ----
>
> Here is the routine that returns the physical address in memory
> in the form of a pointer to my structure.
>
> #include <unistd.h> /* open() */
> #include <fcntl.h> /* O_RDWR */
> #include <stdlib.h> /* sizeof() */
> #include <stdio.h>
> #include <sys/mman.h> /* mmap(), PROT_READ, MAP_FILE */
> #include "sh_mem.h" /* RUN_DATA */
>
> RUN_DATA *ptr;
>
> RUN_DATA *get_sh_mem_ptr(void)
> {
> int fd;
>
> if ((fd = open("/dev/mem", O_RDWR)) < 0)
> {
> printf("sh_mem.c: Unable to open /dev/mem.\n\n");
> exit(-1);
> }
> ptr = (RUN_DATA *) mmap(0, sizeof(RUN_DATA), PROT_READ | PROT_WRITE,
> MAP_FILE | MAP_SHARED, fd, SH_MEM_BASE_ADDR);
>
> if (ptr == MAP_FAILED)
> {
> printf("sh_mem.c: Unable to map shared memory.\n\n");
> close(fd);
> exit(-1);
> }
> close(fd);
> return(ptr);
> }
>
>
> ---- user space program ----
>
> #include "sh_mem.h"
>
> extern RUN_DATA *ptr;
>
> int main(void)
> {
> ....
>
> ptr = get_sh_mem_ptr(); /* init struct pointer to shared mem addr */
> ....
>
> strcpy(ptr->variable1, string); /* copy string to my struct in shared mem */
> temp1 = ptr->variable2; /* get a value from struct in shared mem */
> ptr->variable3 = temp2; /* set a value in struct in shared mem */
> ....
> }
>
>
>
> ---- real time module ----
>
> #include "sh_mem.h
>
> RUN_DATA *ptr; /* define the structure pointer */
>
> int init_module(void) /* real time module inti routine */
> {
> ptr = (RUN_DATA *) SH_MEM_BASE_ADDR; /*init struct ptr to shared mem addr */
> ....
>
> strcpy(ptr->variable1, string); /* copy string to my struct in shared mem */
> temp1 = ptr->variable2; /* get a value from struct in shared mem */
> ptr->variable3 = temp2; /* set a value in struct in shared mem */>
> ....
>
> }
>
>
> Before all of this will work you need to add a line to /etc/lilo.conf
>
> append="mem=125M"
>
> This line is added at the end of the list before the lines
> that define the boot image. This is what tells Linux to reserve
> the top 3 Megs of physical memory.
>
> example:
>
> boot=/dev/hda
> map=/boot/map
> install=/boot/boot.b
> #compact
> #linear
> prompt
> timeout=50
> append="mem=125M"
>
> image=/boot/rtlinuz-1.1
> label=rtlinux
> root=/dev/hda2
> read-only
>
> ....
>
>
>
> You will have to run /etc/lilo so that it knows the new configuration
> and then you have to reboot the machine and your all set.
>
> Any program that uses shared memory like this must have root privilege.
> This can be done by running your program as root or setting uid. However,
> that requires another discussion for which I may not be fully qualified.
> System security is involved and that is a tricky subject to master.
> Personally I think it all depends on what you are doing and what access
> is provided to the machine.
>
> This may seem complex but once it is done, accessing any of your data
> in shared memory is a snap (as shown above in ---- user space program ----
> and in ---- real time module ----).
>
> This should get you rolling quickly. As I understand the problem
> of trying to get 4 Megs of shared memory it is very difficult if not
> impossible. There have been several discussions in the past 3 or 4
> months on this very subject but I don't recall any clear cut solutions.
>
> The problem as I understand it is that if you try to establish exactly
> 4 Megs of memory Linux just flat out does not recognize that it is there.
> If you try to establish 4.1 Megs Linux does not recognize the first 4 Megs
> but you do get 0.1 Megs available for your use.
>
> I hope this gets you under way as easily as possible. I used the
> Shared memory How-To to get this far. It took a little work but once
> you understand the concept it goes quite smoothly.
>
>
>
>
>
> ----------
> From: Estabridis, Janet P[SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, June 08, 1999 7:01 AM
> To: 'RTL Newsgroup'
> Subject: Shared Memory in a computer with 128MBytes of memory
>
> Hi,
> I have read all the old messages on shared memory and nothing has helped.
>
> I have been attempting to use shared memory as is spelled out in the paper
> "Using Shared Memory in Real-Time Linux" by Fredrick M. Proctor and in your
> "HOWTO." I am confused and if you have any suggestions I'd appreciate it.
>
> 1. I have gotten shared memory to work with two non-real time applications. But,
>when I try and add a rt application the real-time application appears to be accessing
>different memory because if I write a new value to the shared memory the applications
>don't see it. I have verified that the pointer to memory in the real-time
>application and the pointers in the linux applications all contain the same address.
>I did this by passing the rt_ptr through a FIFO to the non-real time application and
>doing an fprintf.
>
> what I mean is that the user_ptr = (BLOCK *) mmap ( .... ) from the linux
>applications is the same as the address pointer in the real-time application char
>*rt_ptr = ADDRESS
>
> So, why aren't the accessing the same memory?? user_ptr = 0x7d00000 and rt_ptr =
>0x7d00000 but why doesn't the application see it when the rt process initializes the
>block structure to a value ?? i.e. rt_ptr->block[0]= 500 or rt_ptr->block[10] = 444;
>
> I use a common header file where
>
> struct {
> unsigned short block[5000];
> } BLOCK;
>
> Any suggestions ??
>
> I am using Kernel 2.0.36 and RTL v1.1
> I have 128Mbytes of memory on a pentinum II and I want to use close to 4Bytes
>maximum eventually, so my lilo.conf has append="mem=125m"
>
> I am very new to Linux so would appreciate any help in finding the answer.
>
> Thanks
>
>
> Janet Estabridis>
> Electrical Engineer
> NAWC Code 473E00D
> China Lake, CA 93555
> (760) 939-2896 FAX (760) 939 -3075
>
>
--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/