OS/2 codes: How to emulate COPY-ON-WRITE #1 main function

A basic principle of copy-on-write is the following.

  1. Remove WRITE permission of source memory blocks
  2. Create an alias memory without WRITE permission for source memory blocks
  3. 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.

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷