HP-UX Shared memory windows in mixed mode - Unix

This is a discussion on HP-UX Shared memory windows in mixed mode - Unix ; Hi, This question is targeting on HP-UX B11.11 (pa risc 2.0) shared memory memory windowing in mixed mode (32-bit application and 64-bit application) environment. I notice an issue when 32-bit application acquires a shared memory segment under memory windows and ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: HP-UX Shared memory windows in mixed mode

  1. HP-UX Shared memory windows in mixed mode

    Hi,

    This question is targeting on HP-UX B11.11 (pa risc 2.0) shared memory
    memory windowing in mixed mode (32-bit application and 64-bit
    application) environment.

    I notice an issue when 32-bit application acquires a shared memory
    segment under memory windows and 64-bit application tries to attach to
    it.

    Attached below is the sample code and the error information from the
    run.

    This gives me an impression that 64-bit application do not able to
    'see' 32-bit application windowing on Q3. Is there any way to get
    around this?

    Thanks and regards,
    Ravi Nallappan

    Sample Code for reproduce the situation:
    $ cat s.c
    /*
    This is to demo mixed mode shared memory issue under HPUX memory
    windowing.
    The idea is for 2 executables to be compiled out off this code.

    c32(client) - invoke server process which is exact same code but
    in 64-bits,
    and then generates shm key (ftok) from passed pathname(arg 1),
    using the key
    creates/attaches shared memory segment writes passed msg (arg 2).
    using ANSI C - cc s.c -o c32

    s64(server) - generates shm key from passed pathname(arg 1), using
    the key
    attaches to client shared memory segment and reads the msg.
    using ANSI C - cc +DD64 s.c -o s64

    ps: fork and exec ensure both client and server are in same
    window.
    */

    #include
    #include
    #include

    #include
    #include
    #include
    #include

    #define SHM_SIZE 1000

    int is_client = 1 ;

    char *shm_do( char *key_file ) {
    static int shmid = -1 ;
    static char *data = NULL ;
    key_t key;
    int mode;
    struct shmid_ds buf ;

    if ( shmid != -1 ) {
    /* already create, time to detach and destroy it */

    printf("%x: exiting..\n", getpid() ) ;
    /* detach from the segment: */
    if (shmdt(data) == -1) {
    printf("%x: shmdt - %s\n", getpid(), strerror(errno) );
    exit(1);
    }

    if ( is_client && shmctl(shmid, IPC_RMID, &buf) == -1 ) {
    printf("%x: shmctl - %s\n", getpid(), strerror(errno) );
    exit(1);
    }
    return NULL ;
    }

    printf( "%x: path - %s\n", getpid(), key_file ) ;
    if ((key = ftok(key_file, 'R')) == -1) {
    printf("%x: ftok - %s\n", getpid(), strerror(errno) );
    exit(1);
    }

    printf( "%x: key - %ld\n", getpid(), key ) ;
    if ((shmid = shmget(key, SHM_SIZE, 0666 | ((is_client)? IPC_CREAT :
    0) )) == -1) {
    printf("%x: shmget - %s\n", getpid(), strerror(errno) );
    exit(1);
    }

    /* attach to the segment to get a pointer to it: */
    data = shmat(shmid, (void *)0, 0);
    if (data == (char *)(-1)) {
    printf("%x: shmat - %s\n", getpid(), strerror(errno) );
    exit(1);
    }

    return data ;
    }

    int main( int argc, char *argv[] ) {
    printf("%x: starting %s..\n", getpid(), argv[0] ) ;

    /* verbose all arguments */
    {
    int i ;
    printf( "%x: num of argc - %d\n", getpid(), argc ) ;
    for ( i = 0; i < argc; i++ ) {
    printf( "%x: arg[%i] - %s\n", getpid(), i, argv[i] ) ;
    }
    }

    /* assign global flag to indicate whether it is a client or server
    */
    {
    is_client = (char)argv[0][0] == 'c' ;
    }

    /* client should have 3 arguments, its own name, key file and msg */
    if ( is_client && argc != 3 ) {
    printf( "%x: missing key_file and msg\n", getpid() ) ;
    exit(1) ;
    }

    /* server should have 2 arguments, its own name and key file */
    if ( !is_client && argc != 2 ) {
    printf( "%x: incorrect client call\n", getpid() ) ;
    exit(1) ;
    }

    /* if client, prepare to fork and exec server */
    if ( is_client ) {
    pid_t v_ret ;
    v_ret = fork() ;
    if ( v_ret == -1 ) {
    printf("%x: fork - %s\n", getpid(), strerror(errno) );
    exit(1) ;
    }
    else if ( v_ret == 0 ) {
    int e_ret ;
    /* server */
    sleep(1) ; /* simple way to ensure client run first */
    printf( "%x: server..\n", getpid() ) ;
    e_ret = execl( "s64", "s64", argv[1], NULL ) ;
    if ( e_ret == -1 ) {
    printf("%x: execl - %s\n", getpid(), strerror(errno) );
    exit(1) ;
    }
    }
    else {
    /* client */
    printf( "%x: client..\n", getpid() ) ;
    }
    }

    /* shm memory part */
    {
    char *data ;
    int i ;

    data = shm_do( argv[1] ) ;

    if ( is_client ) {
    /* client - write */
    printf("%x: writing to segment: \"%s\"\n", getpid(), argv[2]) ;
    strncpy(data, argv[2], SHM_SIZE) ;
    scanf("%d", &i) ; /* to pause */
    }
    else {
    /* server - read */
    printf("%x: segment contains: \"%s\"\n", getpid(), data);
    }

    shm_do( NULL ) ;
    }
    return 0 ;
    }

    ================================================== =======
    Compiling using ANSI C:

    cc +DD64 s.c -o s64
    cc s.c -o c32
    touch k1

    ================================================== =======
    Running without memory window:
    $ c32 k1 hello
    4757: starting c32..
    4757: num of argc - 3
    4757: arg[0] - c32
    4757: arg[1] - k1
    4757: arg[2] - hello
    4757: client..
    4757: path - k1
    4757: key - 1381190066
    4757: writing to segment: "hello"
    4758: server..
    4758: starting s64..
    4758: num of argc - 2
    4758: arg[0] - s64
    4758: arg[1] - k1
    4758: path - k1
    4758: key - 1381190066
    4758: segment contains: "hello"
    4758: exiting..
    1
    4757: exiting..

    ================================================== =======
    Running with memory window:

    $ setmemwindow -i 1 c32 k1 hello
    475d: starting c32..
    475d: num of argc - 3
    475d: arg[0] - c32
    475d: arg[1] - k1
    475d: arg[2] - hello
    475d: client..
    475d: path - k1
    475d: key - 1381190066
    475d: writing to segment: "hello"
    475e: server..
    475e: starting s64..
    475e: num of argc - 2
    475e: arg[0] - s64
    475e: arg[1] - k1
    475e: path - k1
    475e: key - 1381190066
    475e: shmat - Permission denied
    1
    475d: exiting..

  2. Re: HP-UX Shared memory windows in mixed mode

    nkravi wrote:
    > Hi,
    >
    > This question is targeting on HP-UX B11.11 (pa risc 2.0) shared memory
    > memory windowing in mixed mode (32-bit application and 64-bit
    > application) environment.
    >


    I think you'd be better off asking in comp.sys.hp.hpux. Followups set.

    > I notice an issue when 32-bit application acquires a shared memory
    > segment under memory windows and 64-bit application tries to attach to
    > it.
    >


    As one would expect -- 64-bit applications share the Global (Memory
    Window 0) 32-bit window with 32-bit applications. You have to use
    IPC_GLOBAL to put the segment (if it fits) in the Global Q4 window
    which both the 32-bit Memory Windows app and the 64-bit apps will see
    (man 2 shmget, man 1M setmemwindow, Memory Windows White Paper, etc.)

    > Attached below is the sample code and the error information from the
    > run.


    snipped -- this would be entirely expected (you could get lucky and
    end up in Q4 if the Window Q2/Q3 is full... but that's unreliable).

    >
    > This gives me an impression that 64-bit application do not able to
    > 'see' 32-bit application windowing on Q3. Is there any way to get
    > around this?


    Use IPC_GLOBAL as indicated.

    Don
    --
    kernel, n:
    A part of an operating system that preserves the medieval traditions
    of sorcery and black art.

+ Reply to Thread