c++ - Can we assume the last 2 bits of a memory address are 00 and reuse those bits? A windows 7 page fault blue screen -


my friend programming in c++ on 64-bit windows 7 pc , came crazy idea save little bit of memory: observed last 2 bits of memory addresses seemed 00, figured use bits other things , when memory address needed, use bit-mask set last 2 bits 0, either when writing or reading memory. reason why he's using last 2 bits needs work on 32-bit systems too. anyway, on windows 7 64-bit system got following blue screen error when running program:

page_fault_in_non_paged_area

could crazy memory savings idea causing this? i.e., can happen last 2 bits of memory address not 00, , he's accessing memory that's partly on 1 of memory pages, partly off page? in event, needs work on popular operating systems. question applies other operating systems well.

if (in windows 7 64 bit, @ least) scheme guaranteed work (if coded properly), else causing unusual blue screen crash?

your friend taking advantage of feature known tagged pointers. on windows, raymond chen has warning regarding on blog:

there no /8tb flag on 64-bit windows

a customer reported 64-bit application crashing on windows 8.1. traced problem fact user-mode address space 64-bit applications on windows 8.1 128tb, whereas 8tb on earlier versions of windows x64. ...

...

as how ended having dependency on address space being @ 8tb, didn't say, have guess: using unused bits tagging.

if going use tagged pointers, you need put tag bits in least significant bits, since bits control. example, if align objects on 16-byte boundaries, have 4 available bits tagging. if you're going use upper bits tagging, @ least verify upper bits available.

something more important watch out - memory pointer allocated os might aligned in way allows tagging, if intermediate memory manager sits between user's code , os (which case), manager allocates os memory internally , divides app use, pointers manager gives out app might not aligned in way allows tagging. cannot tag arbitrary memory pointer without knowing came or how aligned.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -