read(2) into some addresses doesn't return data on RPi
Peter Jeremy
peter at rulingia.com
Sat Jan 10 08:13:23 UTC 2015
On 2015-Jan-10 17:04:12 +1100, Peter Jeremy <peter at rulingia.com> wrote:
>Running the attached program on /dev/mmcsd0s1 gave me the following results:
Which got stripped (hence the signature failure).
--
Peter Jeremy
-------------- next part --------------
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#define RLEN 512
static void check(int fd, int num, char *buf);
static void initbuf(char *buf);
static void checkbuf(char *buf, int num);
int main(int argc, char **argv) {
char buf[65536];
int fd, off;
fd = open(argv[1], O_RDONLY);
if (fd < 0)
err(1, "open %s failed", argv[1]);
for (off = 2*RLEN; off < sizeof(buf) - 2*RLEN; off += 8)
check(fd, 1, buf + off);
}
static void check(int fd, int num, char *buf) {
initbuf(buf);
if (read(fd, buf, RLEN) != RLEN)
err(1, "read%d failed", num);
checkbuf(buf, num);
}
static void initbuf(char *buf) {
int i;
for (i = -RLEN; i < RLEN*2; i += sizeof(0ULL)) {
*(unsigned long long *)(buf + i) = 0xfeedbabedeadbeefULL;
}
}
#define FAIL (RLEN / sizeof(0ULL))
static void checkbuf(char *buf, int num) {
int i, j;
for (i = -RLEN, j = 0; i < 0; i += sizeof(0ULL)) {
if (*(unsigned long long *)(buf + i) != 0xfeedbabedeadbeefULL)
j++;
}
printf("read%d(%p) pre:%s", num, buf,
(j == 0) ? "OK" : (j == FAIL) ? "FAIL" : "PFAIL");
fprintf(stderr, "read%d(%p) pre:%s", num, buf,
(j == 0) ? "OK" : (j == FAIL) ? "FAIL" : "PFAIL");
for (i = 0, j = 0; i < RLEN; i += sizeof(0ULL)) {
if (*(unsigned long long *)(buf + i) == 0xfeedbabedeadbeefULL)
j++;
}
printf(" buf:%s", (j == 0) ? "OK" : (j == FAIL) ? "FAIL" : "PFAIL");
fprintf(stderr, " buf:%s",
(j == 0) ? "OK" : (j == FAIL) ? "FAIL" : "PFAIL");
for (i = RLEN, j = 0; i < RLEN*2; i += sizeof(0ULL)) {
if (*(unsigned long long *)(buf + i) != 0xfeedbabedeadbeefULL)
j++;
}
printf(" post:%s\n", (j == 0) ? "OK" : (j == FAIL) ? "FAIL" : "PFAIL");
fprintf(stderr, " post:%s\n",
(j == 0) ? "OK" : (j == FAIL) ? "FAIL" : "PFAIL");
fflush(stdout);
fsync(1);
fflush(stderr);
fsync(2);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 949 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20150110/af60ef9e/attachment.sig>
More information about the freebsd-arm
mailing list