CreateMutex
까보면 다나와~

CMPXCHG8B and LOCK
The LOCK prefix in assembly is used to assert a special pin on the processor during the execution of the subsequent instruction.
- 어셈블리의 LOCK prefix는 'subsequent instruction'의 실행동안 프로세서에 특별한 핀을 지정하는데 사용된다.

This pin is used to ensure that the processor is the only processor with access to a shared memory area.
- 이 핀은 프로세서가 공유된 메모리영역에 접근하는 단일 프로세서인지 확인하는데 사용되어진다.

The LOCK prefix is used within multi-processor systems that may be affected by processors simultaneously modifying shared memory segments.
- LOCK prefix는 동시에 공유된 메모리 세그먼트들에 영향을 끼칠지 모르는 멀티 프로세서 시스템들에 사용된다.

There is a small subset of instructions that can legally follow a LOCK prefix.
The CMPXCHG8B instruction is a compare instruction that compares values stored in specific registers with a target memory location. If the destination value matches the source value, the source is moved into the targeted memory location, if not, the destination memory data is loaded into the specific registers.
The CMPXCHG8B and LOCK prefix instructions do not operate properly together. If they are executed in succession an invalid instruction error will be generated. If this code is run under a debugger, the debugger will catch the invalid instruction exception and terminate the running process. However; if no debugger exists, we can trap this exception and continue execution gracefully. To do this we set an unhandled exception filter and then execute the instructions in inline assembly.

void error()
{
MessageBox(NULL, L"No Debugger Detected", L"No Debugger", MB_OK);
return;
}
...
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) error);
__asm {
__emit 0xf0;
__emit 0xf0;
__emit 0xc7;
__emit 0xc8;
}
  Comments,     Trackbacks