Computing > Embedded Computing

[solved] ramspeed crashes with Segmentation fault

(1/1)

DiTBho:
"ramspeed" is a cache and memory benchmarking tool, see here for source and documentation.

The last version is 3.5.0, it compiles fine, but on my computer it immediately crashes

--- Code: ---RAMspeed/SMP (GENERIC) v3.5.0 by Rhett M. Hollander and Paul V. Bolotoff, 2002-09

8Gb per pass mode, 2 processes

Segmentation fault

--- End code ---

Digging into, I found that when shmget () fails its return-value is not checked and the program crashes

--- Code: ------ ramsmp.c.original   2021-09-05 04:27:11.680014453 -0000
+++ ramsmp.c    2021-09-05 04:55:41.180015268 -0000
@@ -334,6 +334,13 @@
     /* initialise the future master process and a segment of shared memory */
     shmkey = masterpid = getpid();
     shmid = shmget(shmkey, (sizeof(STL) << 11), IPC_CREAT | 0666);
+    if (shmid <0)
+    {
+       // On success, a valid shared memory identifier is returned.
+       // On error, -1 is returned, and errno is set to indicate the error.
+       printf("shmget() failed\n");
+       return(1);
+    }
     shm = (UTL *) shmat(shmid, 0, 0);
     for(cnt = 0; cnt < 2048; cnt++) shm[cnt] = 0;
     shmdt(shm);

--- End code ---

So, the problem is related to shmget(), and I wrote this program to isolate the problem


--- Code: ---#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>

int main()
{
    int segment_id;

    segment_id = shmget(04, getpagesize(), IPC_CREAT | 0666);

    printf("segment_id = %d\n", segment_id);
    printf("Page size - %d\n", getpagesize());

    if (segment_id < 0)
    {
        printf("Error %d\n", errno);
        switch (errno)
        {
        case 38:
            printf("    the function shmget() is not implemented\n");
            printf("    enable 'CONFIG_SYSVIPC' in kernel config\n");
            break;
        default:
            printf("dunno, not yet investigated\n");
            break;
        }
    }

    return 0;
}

--- End code ---

And found that  errno=38 corresponds to ENOSYS which means function not implemented.



So the solution is to enable 'CONFIG_SYSVIPC' in kernel config (I am on k5.4.128): problem solved.


--- Code: ---# ramspeed -b3 -m16
RAMspeed/SMP (GENERIC) v3.5.0 by Rhett M. Hollander and Paul V. Bolotoff, 2002-09

8Gb per pass mode, 2 processes

INTEGER   Copy:      673.21 MB/s
INTEGER   Scale:     742.19 MB/s
INTEGER   Add:       278.48 MB/s
INTEGER   Triad:     262.47 MB/s
---
INTEGER   AVERAGE:   489.09 MB/s

--- End code ---

Now it works! I wasted 52 minutes on this issue, hope these notes help people save time :D

SiliconWizard:
This shows the problem with not checking return values, and doing no or lazy error checking. It'll never stop annoying the f*ck out of me.

Somehow, many developers think that a process crashing is an acceptable way of signaling users that an error occured. :-DD

ejeffrey:
You should always check error codes but why the hell was sysv ipc disabled?  That's a standard part of the UNIX api and if you disable it you should expect things to break.

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version