--- /dev/null
+#
+#
+
+ifeq ($(PLATFORM),)
+ PLATFORM := lin
+endif
+
+OBJ := main.o syscalls.o request.o memory.o exports.o
+OBJ := $(addprefix obj-$(PLATFORM)/,$(OBJ))
+
+ifeq ($(PLATFORM),win)
+ BIN := ../ld-acess.dll
+ LDFLAGS += -lws2_32
+endif
+ifeq ($(PLATFORM),lin)
+ BIN := ../ld-acess.so
+endif
+
+CFLAGS += -Wall
+CFLAGS += -Werror
+CFLAGS += -g -shared -fPIC
+CPPFLAGS += -DARCHDIR_is_x86_64=1
+LDFLAGS += -g -shared -Wl,--no-undefined
+
+DEPFILES = $(filter %.o,$(OBJ))
+DEPFILES := $(DEPFILES:%=%.dep)
+
+.PHONY: all clean
+
+all: $(BIN)
+
+clean:
+ $(RM) $(BIN) $(OBJ) $(DEPFILES)
+
+$(BIN): $(OBJ)
+ $(CC) -o $@ $(OBJ) $(LDFLAGS)
+
+obj-$(PLATFORM)/%.o: %.c
+ @mkdir -p $(dir $@)
+ @echo [CC] -o $@
+ @$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+
+-include $(DEPFILES)
+
--- /dev/null
+/*
+ */
+#include <stdarg.h>
+#include <stdio.h>
+
+#ifdef __WINDOWS__
+int DllMain(void)
+{
+ return 0;
+}
+
+#endif
+
+#ifdef __linux__
+int main(int argc, char *argv[], char **envp)
+{
+ return 0;
+}
+#endif
+
+
+void Debug(const char *format, ...)
+{
+ va_list args;
+ printf("Debug: ");
+ va_start(args, format);
+ vfprintf(stdout, format, args);
+ va_end(args);
+ printf("\n");
+}
+
+void Warning(const char *format, ...)
+{
+ va_list args;
+ printf("Warning: ");
+ va_start(args, format);
+ vfprintf(stdout, format, args);
+ va_end(args);
+ printf("\n");
+}
+
--- /dev/null
+/*
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#if __WIN32__
+# include <windows.h>
+#else
+# include <sys/mman.h>
+# include <errno.h>
+#endif
+
+// === PROTOTYPES ===
+ int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount);
+uintptr_t FindFreeRange(size_t ByteCount, int MaxBits);
+
+// === CODE ===
+int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount)
+{
+ uintptr_t base = (VirtAddr >> 12) << 12;
+ size_t size = (VirtAddr & 0xFFF) + ByteCount;
+ void *tmp;
+ #if __WIN32__
+ do
+ {
+ MEMORY_BASIC_INFORMATION info;
+ VirtualQuery( (void*)base, &info, sizeof(info) );
+ if( info.State != MEM_FREE ) {
+ printf("ERROR: Unable to allocate memory %p+0x%x, already allocated\n",
+ (void*)base, size);
+ base += 0x1000;
+ if( size < 0x1000 )
+ return 0;
+ size -= 0x1000;
+ }
+ else
+ break;
+ } while( size >= 0x1000 );
+ tmp = VirtualAlloc((void*)base, size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ if( tmp == NULL ) {
+ printf("ERROR: Unable to allocate memory %p+%x (0x%x)\n",
+ (void*)base, size,
+ (int)GetLastError());
+ return -1;
+ }
+ #else
+// printf("AllocateMemory: mmap(%p, 0x%lx, ...)\n", (void*)base, ByteCount);
+ tmp = mmap((void*)base, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
+ if( tmp == MAP_FAILED ) {
+ printf("ERROR: Unable to allocate memory\n");
+ perror("AllocateMemory");
+ return -1;
+ }
+// printf("AllocateMemory: RETURN 0\n");
+ #endif
+ return 0;
+}
+
+uintptr_t FindFreeRange(size_t ByteCount, int MaxBits)
+{
+ uintptr_t base, ofs, size;
+ uintptr_t end = -1;
+ static const int PAGE_SIZE = 0x1000;
+
+ size = (ByteCount + PAGE_SIZE - 1) / PAGE_SIZE;
+ size *= PAGE_SIZE;
+
+ end <<= (sizeof(intptr_t)*8-MaxBits);
+ end >>= (sizeof(intptr_t)*8-MaxBits);
+// printf("end = %p\n", (void*)end);
+
+// for( base = 0; base < end - size; base -= PAGE_SIZE )
+ for( base = end - size + 1; base > 0; base -= PAGE_SIZE )
+ {
+ for( ofs = 0; ofs < size; ofs += PAGE_SIZE ) {
+ #if __WIN32__
+ MEMORY_BASIC_INFORMATION info;
+ VirtualQuery( (void*)(base + ofs), &info, sizeof(info) );
+ if( info.State != MEM_FREE )
+ break;
+ #else
+ if( msync( (void*)(base+ofs), 1, 0) == 0 )
+ break;
+ if( errno != ENOMEM )
+ perror("FindFreeRange, msync");
+ #endif
+ }
+ if( ofs >= size ) {
+ return base;
+ }
+ }
+ return 0;
+}
OBJ += arch/$(ARCHDIR).ao_
BIN = ld-acess.so
EXTRABIN := libld-acess.so
-EXTRACLEAN := $(_OBJPREFIX)_stublib.o
+EXTRACLEAN = $(_OBJPREFIX)_stublib.o
INCFILES := sys/sys.h
CFLAGS = -g -Wall -fno-builtin -fno-stack-protector -fPIC
CFLAGS += $(CPPFLAGS) -Werror
LDFLAGS = -g -T arch/$(ARCHDIR).ld -Map map.txt --export-dynamic
+ifeq ($(ARCH),native)
+XBIN := $(addprefix $(OUTPUTDIR)Libs/,$(EXTRABIN))
+$(XBIN): obj-$(ARCH)/_stublib.o
+all: $(XBIN)
+LDFLAGS :=
+BIN :=
+OBJ :=
+endif
+
include ../Makefile.tpl
# create libld-acess.so