shmat() system call?

Warren Tucker wht at n4hgf.Mt-Park.GA.US
Thu Aug 16 12:37:45 AEST 1990


In article <27 at astph.UUCP> jeff at astph.UUCP (8592x2) writes:
>
>Question concerning the shared memory attach call:
>
>I am writing a shared memory allocation manager for a multi-user
>database.
>I need to know if additional attaches by other processes will be
>guaranteed to return the same address as that the first process
>was returned.

To be sure, specify the attach address, regardless of what the FM says.
Make a small program that passes 0 for the address and see what it
returns.  Then, use that value hardcoded, possibly #defined for each
arcitecture you plan to run the program on.

I.E.,
/*---------------------- header file --------------------*/
#if defined(M_I286)
#define SHMPTR  char far *
#define SYSPTR  struct system_control *
#else
#define SHMPTR  char *
#define SYSPTR  struct system_control *
#endif

#if defined(M_SYS5)
#if defined(M_I386)
#define SHM_ATTACH_ADDR     ((SHMPTR)0x67000000L)   /* 386 */
#else
#define SHM_ATTACH_ADDR     ((SHMPTR)0x00670000L)   /* 286 */
#endif
#else /* not xenix */
#ifdef (pyr)
#define SHM_ATTACH_ADDR     ((SHMPTR)0xC0000000L)   /* PYRAMID */
#else
#define SHM_ATTACH_ADDR     ErrorInHeaderFile
#endif
#endif

/*---------------------- code file --------------------*/

    if((sys = shmat(*pshmid,SHM_ATTACH_ADDR,0)) !=
        (SHMPTR)SHM_ATTACH_ADDR)
    {
        /* attach error: either returned (SHMPTR)-1 or wrong address */
    }
 
-----------------------------------------------------------------------
Warren Tucker, TuckerWare   gatech!n4hgf!wht or wht at n4hgf.Mt-Park.GA.US
"Tell the moon; don't tell the March Hare: He is here. Do look around."



More information about the Comp.unix.wizards mailing list