summaryrefslogtreecommitdiff
path: root/ldmicro/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/lib')
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.cpp112
-rw-r--r--ldmicro/lib/linuxUI/linuxLD.h96
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.cpp3
-rw-r--r--ldmicro/lib/linuxUI/linuxUI.h1
4 files changed, 199 insertions, 13 deletions
diff --git a/ldmicro/lib/linuxUI/linuxLD.cpp b/ldmicro/lib/linuxUI/linuxLD.cpp
index 69c5f6e..e4fd018 100644
--- a/ldmicro/lib/linuxUI/linuxLD.cpp
+++ b/ldmicro/lib/linuxUI/linuxLD.cpp
@@ -1,2 +1,114 @@
#include "linuxUI.h"
+std::vector<HEAPRECORD> HeapRecords;
+
+HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
+{
+ HANDLE hHeap = NULL;
+ HEAPRECORD hHeapRecord;
+ hHeapRecord.dwMaximumSize = dwMaximumSize;
+ hHeap = malloc(dwInitialSize);
+
+ if (hHeap == NULL)
+ return NULL;
+
+ hHeapRecord.dwSize = dwInitialSize;
+ hHeapRecord.hHeap = hHeap;
+ hHeapRecord.dwAllocatedSizeOffset = 0;
+ hHeapRecord.HeapID = HeapRecords.size()+1;
+ HeapRecords.push_back(hHeapRecord);
+
+ return hHeap;
+}
+
+LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
+{
+ if (hHeap == NULL)
+ {
+ printf("Alloc**********NULL HEAP***************\n");
+ LPVOID p = malloc(dwBytes);
+ return p;
+ }
+
+ auto it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; });
+
+ if (it == HeapRecords.end())
+ return NULL;
+
+ if ((*it).dwAllocatedSizeOffset + dwBytes > (*it).dwSize)
+ {
+ if ((*it).dwMaximumSize != 0)
+ if((*it).dwAllocatedSizeOffset + dwBytes > (*it).dwMaximumSize)
+ return NULL;
+
+ (*it).hHeap = realloc((*it).hHeap, (*it).dwAllocatedSizeOffset + dwBytes);
+ hHeap = (*it).hHeap;
+ }
+
+ /// HEAP_ZERO_MEMORY is set by default
+ DWORD flags = MAP_ANONYMOUS;
+
+ // if ( !((dwFlags & HEAP_ZERO_MEMORY) == HEAP_ZERO_MEMORY) )
+ // flags = MAP_ANONYMOUS | MAP_UNINITIALIZED;
+
+ /* Use for setting a meamory chunck with some value
+ * void * memset ( void * ptr, int value, size_t num );
+ */
+ LPVOID p = mmap(hHeap + (*it).dwAllocatedSizeOffset, dwBytes, PROT_EXEC, flags, -1, 0);
+
+ if (p == NULL)
+ return NULL;
+
+ (*it).dwAllocatedSizeOffset += dwBytes;
+ HEAPCHUNCK chunck;
+ chunck.Chunck = p;
+ chunck.dwSize = dwBytes;
+ (*it).Element.push_back(chunck);
+
+ return p;
+}
+
+BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
+{
+ /// if NULL free()
+ if (hHeap == NULL)
+ {
+ printf("free*********NULL HEAP***************\n");
+ free(lpMem);
+ return TRUE;
+ }
+ auto heap_it = std::find_if(HeapRecords.begin(), HeapRecords.end(), [&hHeap](HEAPRECORD &Record) { return Record.hHeap == hHeap; });
+
+ if (heap_it == HeapRecords.end())
+ return FALSE;
+
+ auto chunck_it = std::find_if((*heap_it).Element.begin(), (*heap_it).Element.end(), [&lpMem](HEAPCHUNCK &Chunck) { return Chunck.Chunck == lpMem; });
+
+ if (chunck_it == (*heap_it).Element.end())
+ return FALSE;
+
+ int result = munmap((*chunck_it).Chunck, (*chunck_it).dwSize);
+
+ if (result == 0)
+ {
+ (*heap_it).Element.erase(chunck_it);
+ return TRUE;
+ }
+ else
+ return FALSE;
+
+}
+
+void OutputDebugString(char* str)
+{
+
+}
+
+double GetTickCount(void)
+{
+// timespec now;
+// clock_gettime()
+// if (clock_gettime(CLOCK_MONOTONIC, &now))
+// return 0;
+ return 10.2;//now.tv_sec * 1000.0 + now.tv_nsec / 1000000.0;
+} \ No newline at end of file
diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h
index 0e4f682..e204c63 100644
--- a/ldmicro/lib/linuxUI/linuxLD.h
+++ b/ldmicro/lib/linuxUI/linuxLD.h
@@ -2,6 +2,10 @@
#define __LINUX_LD__
#include "linuxUI.h"
+#include <ctype.h>
+#include <vector>
+#include <algorithm>
+#include <sys/mman.h>
/// common windows referances for linux
@@ -10,14 +14,21 @@
/// CALLBACK or __stdcall os defined empty
#define CALLBACK
#define CONST const
-/// typedefs
+
+#define HEAP_ZERO_MEMORY 0x00000008
+
+/// Typedefs
//typedef int64_t __int64;
typedef bool BOOL;
typedef unsigned char BYTE;
+typedef unsigned short WORD;
typedef unsigned int DWORD;
+typedef unsigned int UINT;
+typedef size_t SIZE_T;
typedef long LONG;
typedef wchar_t WCHAR;
typedef char CHAR;
+
typedef CONST WCHAR *LPCWSTR;
typedef CONST CHAR *LPCSTR; /// should be __nullterminated
@@ -36,16 +47,21 @@ typedef CHAR *LPSTR;
typedef LPSTR LPTSTR;
#endif
-/// all handles will hold a GtkWindow* type
-typedef void* PVOID;
+typedef void *PVOID;
+typedef void *LPVOID;
+typedef PVOID HFONT;
+typedef PVOID HMODULE;
+typedef PVOID HHOOK;
+typedef PVOID HBRUSH;
+typedef PVOID HFONT;
typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
typedef HANDLE HDC;
-typedef GtkWidget* HWID;
-typedef GtkWidget* HMENU;
-typedef GtkWindow* HWND;
-typedef GtkApplication* HAPP;
+typedef GtkWidget *HWID;
+typedef GtkWidget *HMENU;
+typedef GtkWindow *HWND;
+typedef GtkApplication *HAPP;
/// Check if system is x64 or x86
#if defined(__UNIX64)
@@ -55,9 +71,17 @@ typedef unsigned int UINT_PTR;
#endif
typedef UINT_PTR WPARAM;
-typedef unsigned int UINT;
-/// custom classes
+#if defined(__UNIX64)
+ typedef __int64_t LONG_PTR;
+#else
+ typedef long LONG_PTR;
+#endif
+
+typedef LONG_PTR LPARAM;
+typedef LONG_PTR LRESULT;
+
+/// Custom classes
class COLORREF : public GdkRGBA{
public:
COLORREF()
@@ -76,6 +100,58 @@ class COLORREF : public GdkRGBA{
}
};
-/// functions
+/// Custom structures
+typedef struct HeapRecordChunckTag{
+ PVOID Chunck;
+ SIZE_T dwSize;
+} HEAPCHUNCK;
+
+typedef struct HeapRecordTag{
+ PVOID hHeap;
+ DWORD HeapID;
+ std::vector<HEAPCHUNCK> Element;
+ SIZE_T dwMaximumSize;
+ SIZE_T dwSize;
+ SIZE_T dwAllocatedSizeOffset;
+} HEAPRECORD;
+
+typedef struct tagSCROLLINFO {
+ UINT cbSize;
+ UINT fMask;
+ int nMin;
+ int nMax;
+ UINT nPage;
+ int nPos;
+ int nTrackPos;
+} SCROLLINFO, *LPCSCROLLINFO;
+
+typedef struct tagNMHDR {
+ HWND hwndFrom;
+ UINT_PTR idFrom;
+ UINT code;
+} NMHDR;
+
+/// Variables
+extern std::vector<HEAPRECORD> HeapRecord;
+
+/// Functions
+HANDLE HeapCreate(
+ DWORD flOptions,
+ SIZE_T dwInitialSize,
+ SIZE_T dwMaximumSize);
+
+LPVOID HeapAlloc(
+ HANDLE hHeap,
+ DWORD dwFlags,
+ SIZE_T dwBytes);
+
+BOOL HeapFree(
+ HANDLE hHeap,
+ DWORD dwFlags,
+ LPVOID lpMem);
+
+/// functions to be ported
+void OutputDebugString(char*);
+double GetTickCount(void);
#endif \ No newline at end of file
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp
index 349408f..3bebf6d 100644
--- a/ldmicro/lib/linuxUI/linuxUI.cpp
+++ b/ldmicro/lib/linuxUI/linuxUI.cpp
@@ -1,8 +1,5 @@
#include "linuxUI.h"
-/// Menu Variables
- HWID window;
-
/// EnableMenuItem Variables
const UINT MF_ENABLED = 0;
const UINT MF_GRAYED = 1;
diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h
index 8efb6ef..c6bb1ac 100644
--- a/ldmicro/lib/linuxUI/linuxUI.h
+++ b/ldmicro/lib/linuxUI/linuxUI.h
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <inttypes.h>
#include "linuxLD.h"
+//#include "windows.h"
/// version control
#define LDMicro_VERSION_MAJOR 1