It seems to work, but it is not thoroughly tested.
Code: Select all
Procedure _PNGSizeCheck_(*MemoryAddress, MaxSize)
Protected result
!__asm__ __volatile__ (".intel_syntax noprefix;"
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!"mov edx, %1;"
!"mov eax, %2;"
!"lea ebx, [eax - 8];"
!"xor eax, eax;"
;!"xor ecx, ecx;"
!"cmp dword ptr [edx], 0x474e5089;"
!"jne locallabel_1;"
!"cmp dword ptr [edx + 4], 0x0a1a0a0d;"
!"jne locallabel_1;"
!"mov eax, 8;"
!"locallabel_0:;"
!"mov ecx, dword ptr [edx + eax];"
!"bswap ecx;"
!"lea eax, [eax + ecx + 12];"
!"cmp eax, ebx;"
!"ja locallabel_1;"
!"cmp dword ptr [edx + eax + 4], 0x444e4549;"
!"jne locallabel_0;"
!"add eax, 12;"
!"locallabel_1:;"
!"mov %[res], eax;"
!".att_syntax"
!: [res] "=r" (v_result)
!: "r" (p_memoryaddress), "r" (v_maxsize)
!: "edx", "eax", "ecx", "ebx"
!);
CompilerElse
!"mov rdx, %1;"
!"mov rax, %2;"
!"lea rbx, [rax - 8];"
!"xor rax, rax;"
!"xor rcx, rcx;"
!"cmp dword ptr [rdx], 0x474e5089;"
!"jne locallabel_1;"
!"cmp dword ptr [rdx + 4], 0x0a1a0a0d;"
!"jne locallabel_1;"
!"mov rax, 8;"
!"locallabel_0:;"
!"mov ecx, dword ptr [rdx + rax];"
!"bswap ecx;"
!"lea rax, [rax + rcx + 12];"
!"cmp eax, ebx;"
!"ja locallabel_1;"
!"cmp dword ptr [rdx + rax + 4], 0x444e4549;"
!"jne locallabel_0;"
!"add rax, 12;"
!"locallabel_1:;"
!"mov %[res], rax;"
!".att_syntax"
!: [res] "=r" (v_result)
!: "r" (p_memoryaddress), "r" (v_maxsize)
!: "rdx", "rax", "rcx", "rbx"
!);
CompilerEndIf
ProcedureReturn result
EndProcedure
Remove the macro.
;- Macros (Windows)
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Macro rax : eax : EndMacro
Macro rbx : ebx : EndMacro
Macro rcx : ecx : EndMacro
Macro rdx : edx : EndMacro
CompilerEndIf
Code: Select all
Procedure.i MStream_AddRef(*this.MStream_Object)
; InterlockedIncrement of *this\refcount
;*this\refcount + 1
!__asm__ __volatile__ (".intel_syntax noprefix;"
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!"mov edx, %0;"
!"lock inc dword ptr [edx + 4];"
!".att_syntax"
!:
!: "r" (p_this)
!: "edx"
!);
CompilerElse
!"mov rdx, %0;"
!"lock inc dword ptr [rdx + 8];"
!".att_syntax"
!:
!: "r" (p_this)
!: "rdx"
!);
CompilerEndIf
ProcedureReturn *this\refcount
EndProcedure
Procedure.i MStream_Release(*this.MStream_Object)
; InterlockedDecrement of *this\refcount
;*this\refcount - 1
!__asm__ __volatile__ (".intel_syntax noprefix;"
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!"mov edx, %0;"
!"lock dec dword ptr [edx + 4];"
!".att_syntax"
!:
!: "r" (p_this)
!: "edx"
!);
CompilerElse
!"mov rdx, %0;"
!"lock dec dword ptr [rdx + 8];"
!".att_syntax"
!:
!: "r" (p_this)
!: "rdx"
!);
CompilerEndIf
; Free memory if refcount = 0
If *this\refcount = 0
FreeMemory(*this)
ProcedureReturn 0
EndIf
ProcedureReturn *this\refcount
EndProcedure