All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] posix shm problem
@ 2009-02-04 14:15 Tom Schouten
  2009-02-04 16:19 ` Tom Schouten
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Schouten @ 2009-02-04 14:15 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 1164 bytes --]

Hello,

I've been getting strange behaviour with posix shared memory.  I tried both 
svn revision 4169 and release 2.4.6.1 together with a linux-2.6.25.17 kernel 
and the default adeos patch for both xenomai versions.

I'm building the attached test program with:

cc -g -Wall `xml2-config --cflags` `xeno-config --xeno-cflags \
	--posix-cflags`    -o shm_test.o -c shm_test.c \
cc shm_test.o -o shm_test.app `xml2-config --libs` `xeno-config  
	--xeno-ldflags --posix-ldflags`  -lnative -lrt -lrtdm 

Basicly, some writes don't seem to come true.
(it should be all the same values: notice the zeros at the end.)

Any ideas what this is?


# ./shm_test.app 0x16 && hd 
/tmp/shm-test
logging shm to /tmp/shm-test
filling with 16
00000000  15 15 15 15 15 15 15 15  15 15 15 15 15 15 15 15  
|................|
*
00007040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  
|................|
*
00008000


# ./shm_test.app 0x17 && hd 
/tmp/shm-test
logging shm to /tmp/shm-test
filling with 17
00000000  16 16 16 16 16 16 16 16  16 16 16 16 16 16 16 16  
|................|
*
00007040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  
|................|
*
00008000

[-- Attachment #2: shm_test.c --]
[-- Type: text/x-csrc, Size: 1875 bytes --]

#include <stdlib.h>
#include <stdio.h>

#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>           /* For O_* constants */

#include <string.h>
#include <errno.h>

#include <unistd.h>

#define SHM_NAME "shm-test"

int main(int argc, char **argv) {
    unsigned char *image;
    unsigned char *image_endx;
    int image_fd;
    int bytes = 32 * 1024;
    if (-1 == (image_fd = shm_open(SHM_NAME,
                                   O_CREAT
                                   | O_RDWR 
                                   /* | O_EXCL */
                                   , 0))) {
        fprintf(stderr, "can't create shared memory: %s.\n",
                strerror(errno));
        return -errno;
    }

    if ((-1 == ftruncate(image_fd, bytes))) {
        fprintf(stderr, "ftruncate(): %s\n", strerror(errno));
        return -errno;
    }

    if (-1 == (int)(image =
                    mmap(NULL, bytes, PROT_READ | PROT_WRITE, 
                         MAP_SHARED, image_fd, 0))) {
        fprintf(stderr, "can't mmap shared memory: %s.\n",
                strerror(errno));
        return -1;
    }

    // OK
    image_endx = image + bytes;


    // fprintf(stderr, "got shared memory at %p\n", image);

    // dump image.
    if (1) {
        char filename[100];
        // sprintf(filename, "/tmp/" SHM_NAME ".%d.bin", getpid());
        sprintf(filename, "/tmp/" SHM_NAME);
        fprintf(stderr, "logging shm to %s\n", filename);
        FILE *f = fopen(filename, "w");
        fwrite(image, 1, bytes, f);
        fclose(f);

        double fill;
        if (argc < 2) { exit(1); };
        if (1 != sscanf(argv[1], "%lf", &fill)) exit (1);

        int ifill = fill;
        fprintf(stderr, "filling with %02x\n", ifill);
        int i;
        for(i=0; i<bytes; i++) {
            image[i] = ifill & 0xFF;
        }
        
    }
    return 0;
}

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

end of thread, other threads:[~2009-02-11  0:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-04 14:15 [Xenomai-help] posix shm problem Tom Schouten
2009-02-04 16:19 ` Tom Schouten
2009-02-05  9:35   ` Tom Schouten
2009-02-07  9:39     ` Gilles Chanteperdrix
2009-02-09 16:50       ` Tom Schouten
2009-02-09 19:53         ` Gilles Chanteperdrix
2009-02-11  0:01           ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.