Exemplo n.º 1
0
int main(int argc, char *argv[])
{
	volatile int a __attribute__((__unused__));
	char *buffer = "HELLO WORLD!";
	char *data;
	int fd, err, ret = 0;

	if (argc < 2) {
		printf("Usage: %s <pmem file>\n", basename(argv[0]));
		exit(0);
	}

	fd = open(argv[1], O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
	if (fd < 0)
		err_exit("fd");

	/*
	 * This allows us to map a huge zero page, and we do it at a non-zero
	 * offset for a little additional testing.
	 */
	ftruncate(fd, 0);
	ftruncate(fd, MiB(4));

	data = mmap(NULL, MiB(2), PROT_READ, MAP_SHARED, fd, MiB(2));

	/*
	 * This faults in a 2MiB zero page to satisfy the read.
	 * 'a' is volatile so this read doesn't get optimized out.
	 */
	a = data[0];

	pwrite(fd, buffer, strlen(buffer), MiB(2));

	/*
	 * Try and use the mmap to read back the data we just wrote with
	 * pwrite().  If the kernel bug is present the mapping from the 2MiB
	 * zero page will still be intact, and we'll read back zeros instead.
	 */
	if (strncmp(buffer, data, strlen(buffer))) {
		fprintf(stderr, "strncmp mismatch: '%s' vs '%s'\n", buffer,
				data);
		ret = 1;
	}

	err = munmap(data, MiB(2));
	if (err < 0)
		err_exit("munmap");

	err = close(fd);
	if (err < 0)
		err_exit("close");

	return ret;
}
Exemplo n.º 2
0
#define MAX_LOGIC_BLK_PER_ZONE	1000
#define MAX_PHYS_BLK_PER_ZONE	1024

#define KiB(x)	( (x) * 1024L )
#define MiB(x)	( KiB(x) * 1024L )


typedef struct {
	unsigned long size;
	unsigned short cyl;
	unsigned char head;
	unsigned char sec;
} chs_entry_t;

static const chs_entry_t chs_table[] = {
	{ MiB(  1), 125,  4,  4 },
	{ MiB(  2), 125,  4,  8 },
	{ MiB(  4), 250,  4,  8 },
	{ MiB(  8), 250,  4, 16 },
	{ MiB( 16), 500,  4, 16 },
	{ MiB( 32), 500,  8, 16 },
	{ MiB( 64), 500,  8, 32 },
	{ MiB(128), 500, 16, 32 },
	{ 0 },
};

static int get_chs(unsigned long size, unsigned short *cyl, unsigned char *head,
			unsigned char *sec)
{
	int k;
	int found = 0;
Exemplo n.º 3
0
inline U32 GiB(U32 x) {
    return MiB(x) * 1024;
}