public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: shmat problem
@ 2003-01-07  8:14 Dirk Bull
  2003-01-07 18:41 ` Alex Riesen
  0 siblings, 1 reply; 12+ messages in thread
From: Dirk Bull @ 2003-01-07  8:14 UTC (permalink / raw)
  To: fork0, doug; +Cc: linux-kernel

Thanks for your help. I also thought the memory mapping code I'm
porting looked funny. The code forms part of a simulation program where a 
few processes have to share data in a data base. In the code they(the 
original implementers) initialize a bunch of variables and then share these 
variables as I've shown you. I've referenced W.R Stevens's UNIX programming 
books and found no information on whether you could share memory other than 
that on the heap (did not want to change their code to use pointers, not a 
good idea to change too much of the original code). To end a long story, 
Alex, thanks for the SHM_REMAP flag, would never have found it, you've saved 
me a lot of time. Finally, in the code they share pages, therefor using 
SHM_REMAP is not that unsafe, but still not good practice?

Thanks again.

Dirk









_________________________________________________________________
Help STOP SPAM: Try the new MSN 8 and get 2 months FREE* 
http://join.msn.com/?page=features/junkmail


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: shmat problem
@ 2003-01-06 16:22 Alex Riesen
  2003-01-06 16:36 ` Doug McNaught
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Riesen @ 2003-01-06 16:22 UTC (permalink / raw)
  To: Dirk Bull; +Cc: linux-kernel

> Doug, thanks for the reply. I've set SHM_RND in the call and used
> "__attribute__ ((aligned(4096)))" during the the declaration of variable 
> global01_
> (as shown below) such that it is aligned on a page boundary. I'm porting 
> code that was
> written for a Unix system to Linux and the example shown below is how the 
> code is implemented on Unix.

on which exactly?

> The example included executed correctly on:
> mandrake - ? (Can't remember, but it was an old version)
> 
> but fails to work on:
> redhat - 2.2.14-5.0
> debian - 2.2.9
> mandrake - 2.4.19-16mdk
> 
> We are currently working on mandrake - kernel 2.4.19-16mdk.

You have to add SHM_REMAP to shmat flags (see definitions of SHM_ flags).

> 
> 	if ( (shmptr = shmat(shmid, &global01_, SHM_RND)) == (void *) -1)
> 		printf("shmat error: %d %s\n",errno, strerror(errno));
> 	else

add SHM_REMAP.

-alex


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: shmat problem
@ 2003-01-06 14:53 Dirk Bull
  2003-01-06 15:32 ` Doug McNaught
  0 siblings, 1 reply; 12+ messages in thread
From: Dirk Bull @ 2003-01-06 14:53 UTC (permalink / raw)
  To: doug; +Cc: linux-kernel

Doug, thanks for the reply. I've set SHM_RND in the call and used
"__attribute__ ((aligned(4096)))" during the the declaration of variable 
global01_
(as shown below) such that it is aligned on a page boundary. I'm porting 
code that was
written for a Unix system to Linux and the example shown below is how the 
code is
implemented on Unix.

The example included executed correctly on :
mandrake - ? (Can't remember, but it was an old version)

but fails to work on:
redhat - 2.2.14-5.0
debian - 2.2.9
mandrake - 2.4.19-16mdk



We are currently working on mandrake - kernel 2.4.19-16mdk.


Dirk

-------------------------------------------------------------------------------
Example program:
-------------------------------------------------------------------------------

#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>

#define SHM_MODE (SHM_R | SHM_W)

union {
	long IN[2048];
} global01_ __attribute__ ((aligned(4096)));

int main(void) {
	int shmid;
	char *shmptr;


	if ( (shmid = shmget(IPC_PRIVATE, sizeof(global01_), SHM_MODE)) < 0){
		printf("shmget error: %d %s\n",errno, strerror(errno));
		exit(0);
	}

	if ( (shmptr = shmat(shmid, &global01_, SHM_RND)) == (void *) -1)
		printf("shmat error: %d %s\n",errno, strerror(errno));
	else
		printf("shared memory attached from %x to %x\n",
				shmptr, shmptr+sizeof(global01_));

	if (shmctl(shmid, IPC_RMID, 0) < 0)
		printf("shmctl error: %d %s\n",errno, strerror(errno));

	exit(0);
}









_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


^ permalink raw reply	[flat|nested] 12+ messages in thread
* shmat problem
@ 2003-01-06  9:05 Dirk Bull
  2003-01-06 14:17 ` Doug McNaught
  0 siblings, 1 reply; 12+ messages in thread
From: Dirk Bull @ 2003-01-06  9:05 UTC (permalink / raw)
  To: linux-kernel



Hi all

I have a problem with the shmat() function. It works correctly when
one doesn't specify an address where the segment should be attached,
but fails when one does. To specify an address it must be alligned
and I did by using  __attribute__ (aligned()). Still the function
fails. What is the most effective way for a solution
to this problem.

Thanks
Dirk


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-01-07 18:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-07  8:14 shmat problem Dirk Bull
2003-01-07 18:41 ` Alex Riesen
  -- strict thread matches above, loose matches on Subject: below --
2003-01-06 16:22 Alex Riesen
2003-01-06 16:36 ` Doug McNaught
2003-01-06 16:43   ` Alex Riesen
2003-01-06 16:50     ` Doug McNaught
2003-01-06 17:01       ` Alex Riesen
2003-01-06 14:53 Dirk Bull
2003-01-06 15:32 ` Doug McNaught
2003-01-06 15:50   ` Richard B. Johnson
2003-01-06  9:05 Dirk Bull
2003-01-06 14:17 ` Doug McNaught

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox