2015-07-22 20:32:54 +02:00
|
|
|
#ifndef INCLUDE_MEM_H
|
|
|
|
#define INCLUDE_MEM_H
|
2012-12-15 01:16:06 +01:00
|
|
|
|
2015-07-23 13:54:26 +02:00
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
|
|
|
|
2020-05-25 16:20:17 +02:00
|
|
|
inline fastcall void mem_init()
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2016-01-01 17:51:53 +01:00
|
|
|
$mov eax, 68
|
|
|
|
$mov ebx, 11
|
|
|
|
$int 0x40
|
2012-11-26 16:26:15 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 16:53:51 +01:00
|
|
|
:dword malloc(dword size)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2016-01-01 17:51:53 +01:00
|
|
|
$push ebx
|
|
|
|
$push ecx
|
|
|
|
|
|
|
|
$mov eax, 68
|
|
|
|
$mov ebx, 12
|
|
|
|
$mov ecx, size
|
|
|
|
$int 0x40
|
|
|
|
|
|
|
|
$pop ecx
|
|
|
|
$pop ebx
|
|
|
|
return EAX;
|
2012-11-26 16:26:15 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 16:53:51 +01:00
|
|
|
:stdcall dword realloc(dword mptr, size)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2016-01-01 17:51:53 +01:00
|
|
|
$push ebx
|
|
|
|
$push ecx
|
|
|
|
$push edx
|
2012-11-26 16:26:15 +01:00
|
|
|
|
2016-01-01 17:51:53 +01:00
|
|
|
$mov eax, 68
|
|
|
|
$mov ebx, 20
|
|
|
|
$mov ecx, size
|
|
|
|
$mov edx, mptr
|
|
|
|
$int 0x40
|
|
|
|
|
|
|
|
$pop edx
|
|
|
|
$pop ecx
|
|
|
|
$pop ebx
|
|
|
|
return EAX;
|
2012-11-26 16:26:15 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 16:53:51 +01:00
|
|
|
:dword free(dword mptr)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2016-01-01 17:51:53 +01:00
|
|
|
$push eax
|
|
|
|
$push ebx
|
|
|
|
$push ecx
|
|
|
|
|
|
|
|
$mov eax, 68
|
|
|
|
$mov ebx, 13
|
|
|
|
$mov ecx, mptr
|
|
|
|
$test ecx, ecx
|
|
|
|
$jz end0
|
|
|
|
$int 0x40
|
2012-11-26 16:26:15 +01:00
|
|
|
@end0:
|
2016-01-01 17:51:53 +01:00
|
|
|
$pop ecx
|
|
|
|
$pop ebx
|
|
|
|
$pop eax
|
|
|
|
return 0;
|
2012-11-26 16:26:15 +01:00
|
|
|
}
|
|
|
|
|
2012-12-15 01:16:06 +01:00
|
|
|
inline fastcall memmov( EDI, ESI, ECX)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
|
|
|
asm {
|
|
|
|
MOV EAX, ECX
|
|
|
|
CMP EDI, ESI
|
|
|
|
JG L1
|
|
|
|
JE L2
|
|
|
|
SAR ECX, 2
|
|
|
|
JS L2
|
|
|
|
REP MOVSD
|
|
|
|
MOV ECX, EAX
|
|
|
|
AND ECX, 3
|
|
|
|
REP MOVSB
|
|
|
|
JMP SHORT L2
|
|
|
|
L1: LEA ESI, DSDWORD[ ESI+ECX-4]
|
|
|
|
LEA EDI, DSDWORD[ EDI+ECX-4]
|
|
|
|
SAR ECX, 2
|
|
|
|
JS L2
|
|
|
|
STD
|
|
|
|
REP MOVSD
|
|
|
|
MOV ECX, EAX
|
|
|
|
AND ECX, 3
|
|
|
|
ADD ESI, 3
|
|
|
|
ADD EDI, 3
|
|
|
|
REP MOVSB
|
|
|
|
CLD
|
|
|
|
L2:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-11 17:48:27 +02:00
|
|
|
#define SHM_OPEN 0x00
|
|
|
|
#define SHM_OPEN_ALWAYS 0x04
|
|
|
|
#define SHM_CREATE 0x08
|
|
|
|
#define SHM_READ 0x00
|
|
|
|
#define SHM_WRITE 0x01
|
2020-04-11 13:00:31 +02:00
|
|
|
inline fastcall dword memopen(ECX, EDX, ESI)
|
|
|
|
{
|
|
|
|
$mov eax, 68
|
|
|
|
$mov ebx, 22
|
|
|
|
// ecx = area name, 31 symbols max
|
|
|
|
// edx = area size for SHM_CREATE SHM_OPEN_ALWAYS
|
|
|
|
// esi = flags, see the list below:
|
|
|
|
$int 0x40
|
|
|
|
// eax, edx - please check system documentation
|
|
|
|
}
|
2012-12-19 18:37:24 +01:00
|
|
|
|
2020-04-11 13:00:31 +02:00
|
|
|
inline fastcall dword memclose(ECX)
|
|
|
|
{
|
|
|
|
$mov eax, 68
|
|
|
|
$mov ebx, 23
|
|
|
|
$int 0x40
|
|
|
|
// eax destroyed
|
|
|
|
}
|
2012-12-19 18:37:24 +01:00
|
|
|
|
2012-12-15 01:16:06 +01:00
|
|
|
#define mem_Alloc malloc
|
|
|
|
#define mem_ReAlloc realloc
|
|
|
|
#define mem_Free free
|
|
|
|
#define mem_Init mem_init
|
2012-11-26 16:26:15 +01:00
|
|
|
|
2015-07-22 20:32:54 +02:00
|
|
|
#endif
|