From: "Andrew V. Samoilov" <kai@cmail.ru>
To: linux-kernel@vger.kernel.org
Subject: mmap successed but SIGBUS generated on access
Date: Wed, 19 Sep 2001 14:36:10 +0400 [thread overview]
Message-ID: <200109191036.f8JAa9J20856@cmail.ru> (raw)
Hi!
I have bad CD-R with a some number of unreadable files.
Then user-space program use mmap system it returns ok but any
attempt to access a memory pointed by this system call finishes
with SIGBUS. So Midnight Commander internal file viewer faults.
This error is 100 % reproduceable at 2.2.19 and 2.4.2 kernels.
Is there any way to detect such problem in user-space without signal handlers ?
Lines from /var/log/messages:
Sep 19 12:20:05 sav kernel: attempt to access beyond end of device
Sep 19 12:20:05 sav kernel: 16:00: rw=0, want=657860, limit=386954
Sep 19 12:20:05 sav kernel: dev 16:00 blksize=2048 blocknr=328929 sector=1315716 size=2048
count=1
Test program:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
int main (int argc, char ** argv) {
int fd;
struct stat st;
void * p;
while (--argc) {
argv++;
if (stat (*argv, &st)) {
fprintf (stderr, "stat (%s) -- %s\n", *argv, strerror (errno));
continue;
}
if ((fd = open (*argv, O_RDONLY)) == -1) {
fprintf (stderr, "open (%s) -- %s\n", *argv, strerror (errno));
continue;
}
fprintf (stderr, "mmap (%d) called...\n", st.st_size);
if ((p = mmap (0, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (void*) -1) {
fprintf (stderr, "mmap (%s) -- %s\n", *argv, strerror (errno));
close (fd);
continue;
}
fputs ("mmap done...\n", stderr);
write (2, p, st.st_size);
fputs ("munmap called...\n", stderr);
if (munmap (p, st.st_size) == -1) {
fprintf (stderr, "munmap (%s) -- %s\n", *argv, strerror (errno));
}
fputs ("munmap done...\n", stderr);
close (fd);
}
}
This program output:
mmap (8) called...
mmap done...
Bus error
--
Regards,
Andrew.
____________________________________________
Играй в шахматы в Интернет на InstantChess.com!
Play chess on InstantChess.com !
www.instantchess.com
next reply other threads:[~2001-09-19 10:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-19 10:36 Andrew V. Samoilov [this message]
2001-09-19 13:00 ` Jamie Lokier
2001-09-19 16:57 Andrew V. Samoilov
2001-09-19 22:51 ` Jamie Lokier
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=200109191036.f8JAa9J20856@cmail.ru \
--to=kai@cmail.ru \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®