라벨이 copy-on-write인 게시물 표시

OS/2 codes: How to emulate COPY-ON-WRITE #4 Epilogue

So far, we've researched the basic strucutre of the implementation of the copy-on-write feature. As well as, we've looked into the ways to enable copy-on-write in all threads including a main thread. Nevertheless, this approach has some limitations. Copy-on-write will not work if it is used in a thread started by custom codes using DosCreateThread() not _beginthread() it is used in an alien thread created in DLLs not linked with copy-on-write module source memory blocks are allocated malloc() not DosAllocMem() In the above first two cases, installing/uninstalling an exception handler in the context using copy-on-write manually is needed. In case of malloc(), it may be succeeded, but it's not recommended. Failure possibility is higher. Finally, copy-on-write not supported by Kernel is not optimal and may not be useful due to its efficiency. However, the fact itself that implementation of copy-on-write is possible is meaningful even if it is not actually usefu...

OS/2 codes: How to emulate COPY-ON-WRITE #3 Install exception handler

To activate the exception handler, it's needed to install it. By the way, the handler works only on the thread on which it is installed. After, we should install the handler on every threads. Let's see the way to install a handler first: EXCEPTIONREGISTRATIONRECORD regRec = { 0 }; /* Register an exception handler for SIGSEGV */ regRec.ExceptionHandler = ( ERR )sigsegv; DosSetExceptionHandler( &regRec ); EXCEPTIONREGISTRATIONRECORD is a type to register handler. Generally, it should be initialized to 0 except ExceptionHandler field. ExceptionHandler should be set to the handler to be registered. Finally, register the handler with DosSetExceptionHandler() . Here, note that EXCEPTIONREGISTRATIONRECORD variables should be placed in the stack . Uninstalling the installed handler is simple: /* Deregister an exception handler */ DosUnsetExceptionHandler( &regRec ); regRec is the variable which was used when installing the handler. DosUnsetExceptionHandler() ...

OS/2 codes: How to emulate COPY-ON-WRITE #2 Exception handler

In the previous article, we looked into a basic structure of a main function. In that, the last question was how to catch write access to the registered memory blocks. Here is the answer. It's the exception. We removed WRITE permission of the memory blocks. Because of this, writing to those blocks causes an exception, so called SIGSEGV. To catch such exceptions, we should implement exception handlers. Exception handler is like this: ULONG _System sigsegv( PEXCEPTIONREPORTRECORD p1,                        PEXCEPTIONREGISTRATIONRECORD p2,                        PCONTEXTRECORD p3,                        PVOID pv ); Out of the above parameters, p1 is the most im...

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

A basic principle of copy-on-write is the following. 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(), ma...

OS/2 codes: How to emulate COPY-ON-WRITE #0 Prologue

Copy-On-Write is a feature to improve copy performance. That is, memory blocks share the same contents until copy operation to those blocks really occur. By postponing copy-operations until it is needed really, it's possible to remove initial overheads of copy operation. This was needed to implement mmap(). Espeically, MAP_PRIVATE. On Linux( http://man7.org/linux/man-pages/man2/mmap.2.html ), copy-on-write feature is used. I thought it's not possible without kernel supports. However, Dave Yeo suggested DosAliasMem(). I thought it may be possible. I did implement such a feature. A series of the following articles are records of implementing copy-on-write on OS/2.