Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/modules/examples/fopsmapper



> Date: Wed, 1 Apr 2020 07:42:53 -0700
> From: Jason Thorpe <thorpej%me.com@localhost>
> 
> If PAGE_SIZE is ostensibly a vsize_t / size_t, why not define it as (1U << PAGE_SHIFT)?

Without running the following program, can you tell me what it will
print?

It might work to define PAGE_SIZE to be ((size_t)1 << PAGE_SHIFT) but
the consequences are not immediately clear to me (and might be tricky
on, e.g., i386pae).


#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

#define	PAGE_SIZE_S	(1 << 12)
#define	PAGE_SIZE_U	(1u << 12)

uint64_t	addr = 0x7fffffff01234567;

int
main(void)
{

	printf("%"PRIx64"\n", addr & ~(PAGE_SIZE_S - 1));
	printf("%"PRIx64"\n", addr & ~(PAGE_SIZE_U - 1));

	fflush(stdout);
	return ferror(stdout);
}


Home | Main Index | Thread Index | Old Index