All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Moreau <thierry.moreau@connotech.com>
To: linux-kernel@vger.kernel.org
Subject: Bus error on shm_open/ftruncate/mmap after changing kernel boot partition
Date: Tue, 01 Nov 2016 19:57:14 +0000	[thread overview]
Message-ID: <5818F39A.30702@connotech.com> (raw)

Strange bug after changing the boot partition (the previous was on a 
hard disk with a few media errors).

I must apologize that the old partition is re-formatted. (As an excuse 
the other services on this server system work fine with the new partition.)

Anyway, the bogus code sequence is below. Should work fine everywhere, 
modulo write permission on /dev/shm.

Same observation with privileged execution.

uname -a reports:

Linux hostname 4.1.3 #15 SMP Sun Aug 30 03:01:12 UTC 2015 x86_64 
Intel(R) Pentium(R) CPU G3250 @ 3.20GHz GenuineIntel GNU/Linux

Obviously, any help appreciated.

Regards

- Thierry Moreau


============
/* mmap_test.cpp --
*/

#include <cstdio>
#include <cstring>
#include <cerrno>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
   int shm_fd;
   shm_fd=shm_open(/*"/dev/shm/"*/"test",
          O_RDWR | O_CREAT | O_EXCL,
          S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP);
   if (shm_fd>=0) {
     if (ftruncate(shm_fd,0x20000)==0) {
       void *region=mmap(0,0x20000,
                    PROT_READ|PROT_WRITE,MAP_SHARED,
                    shm_fd,0);
       if (MAP_FAILED!=region) {
	fprintf(stderr,"%d %p\n",__LINE__,region);
	fprintf(stderr,"%d %d\n",__LINE__,*((int *)region));
         /* ===== this triggers a bus error on the kernel instance */
       }
       else {
	fprintf(stderr,"%d %d %s\n",__LINE__,errno,strerror(errno));
       }
     }
     else {
       fprintf(stderr,"%d %d %s\n",__LINE__,errno,strerror(errno));
     }
   }
   else {
     fprintf(stderr,"%d %d %s\n",__LINE__,errno,strerror(errno));
   }
return errno;
}
============

             reply	other threads:[~2016-11-01 20:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-01 19:57 Thierry Moreau [this message]
2016-11-01 23:34 ` Bus error on shm_open/ftruncate/mmap after changing kernel boot partition: FIXED Thierry Moreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5818F39A.30702@connotech.com \
    --to=thierry.moreau@connotech.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.