OS/2 codes: How to emulate COPY-ON-WRITE #1 main function
A basic principle of copy-on-write is the following.
Let's see the ways to implement the above sentences.
1. Remove WRITE permission / Alter access protections of memory blocks
To do this, all you have to do is calling DosSetMem() like this:
Where p is the pointer to the source memory block, cb is the size of the blocks, flSrc is the access protection flags of those.
Then, how can we get the protection flags of the source blocks ? Use DosQueryMem():
Where p is the pointer to the memory block, cbSrc is the size to be queried. flSrc is the place where to store access flags.
2. Create an alias memory
An alias memory is an memory sharing same contents with the original memory. For details, see <DosAliasMem(), mapping an address to another address>. This is the underlying feature of copy-on-write.
p is the memory to be aliased, cb is the size and pAlias is the place where to store the aliased memory address.
3. Register information
To maintain memory blocks, it's needed to register infomations for the source memory and the dest memory. Here, we'll use single linked list.
4. Conclusion
The role of main function is to prepare things for later. The most important thing of those is to remove WRITE access of the given memory blocks. Why ? To catch any write access to the registered memory blocks.
Then how can we catch write access to the blocks ? Let's see about this in the next article.
- Remove WRITE permission of source memory blocks
- Create an alias memory without WRITE permission for source memory blocks
- Register information for these
Let's see the ways to implement the above sentences.
1. Remove WRITE permission / Alter access protections of memory blocks
To do this, all you have to do is calling DosSetMem() like this:
DosSetMem( p, cb, flSrc & ~PAG_WRITE ))
Where p is the pointer to the source memory block, cb is the size of the blocks, flSrc is the access protection flags of those.
Then, how can we get the protection flags of the source blocks ? Use DosQueryMem():
DosQueryMem( p, &cbSrc, &flSrc );
Where p is the pointer to the memory block, cbSrc is the size to be queried. flSrc is the place where to store access flags.
2. Create an alias memory
An alias memory is an memory sharing same contents with the original memory. For details, see <DosAliasMem(), mapping an address to another address>. This is the underlying feature of copy-on-write.
DosAliasMem( p, cb, &pAlias, 0 );
p is the memory to be aliased, cb is the size and pAlias is the place where to store the aliased memory address.
3. Register information
To maintain memory blocks, it's needed to register infomations for the source memory and the dest memory. Here, we'll use single linked list.
4. Conclusion
The role of main function is to prepare things for later. The most important thing of those is to remove WRITE access of the given memory blocks. Why ? To catch any write access to the registered memory blocks.
Then how can we catch write access to the blocks ? Let's see about this in the next article.
댓글
댓글 쓰기