Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm64 mac #2877

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions GNUmakefile
Expand Up @@ -2,7 +2,7 @@ ifdef CONFIG
VERSION = 0.100
GIT_LABEL = $(shell echo `git describe --all`-`git rev-parse HEAD`)
BUNDLE = Factor.app
DEBUG ?= 0
DEBUG ?= 1
REPRODUCIBLE ?= 0

SHELL_CC = $(shell printenv CC)
Expand All @@ -12,7 +12,7 @@ ifdef CONFIG
CC = $(SHELL_CC)
endif

# gmake's default CXX is g++, we prefer c++
# gmake's default CXX is g++, we prefer c++
SHELL_CXX = $(shell printenv CXX)
ifeq ($(SHELL_CXX),)
CXX := $(shell which clang++ c++ 2>/dev/null | head -n 1)
Expand All @@ -34,15 +34,15 @@ ifdef CONFIG

CXXFLAGS += -std=c++11

# SANITIZER=address ./build.sh compile
# address,thread,undefined,leak
# SANITIZER=address ./build.sh compile
# address,thread,undefined,leak
ifdef SANITIZER
CFLAGS += -fsanitize=$(SANITIZER)
CXXFLAGS += -fsanitize=$(SANITIZER)
endif

ifneq ($(DEBUG), 0)
CFLAGS += -g -DFACTOR_DEBUG
CFLAGS += -g -O0 -DFACTOR_DEBUG
else
CFLAGS += -O3
endif
Expand Down Expand Up @@ -186,7 +186,7 @@ help:
@echo "SITE_CFLAGS=... additional optimization flags"
@echo "X11=1 force link with X11 libraries instead of Cocoa (only on Mac OS X)"

ALL = factor factor-ffi-test factor-lib
ALL = factor factor-ffi-test factor-lib factor.dSYM

freebsd-x86-32:
$(MAKE) $(ALL) CONFIG=vm/Config.freebsd.x86.32
Expand Down Expand Up @@ -249,6 +249,9 @@ factor: $(EXE_OBJS) $(DLL_OBJS)
$(TOOLCHAIN_PREFIX)$(CXX) -L. $(DLL_OBJS) \
$(CFLAGS) $(CXXFLAGS) -o $(EXECUTABLE) $(LIBS) $(EXE_OBJS)

factor.dSYM: factor
dsymutil $<

factor-console: $(EXE_OBJS) $(DLL_OBJS)
$(TOOLCHAIN_PREFIX)$(CXX) -L. $(DLL_OBJS) \
$(CFLAGS) $(CXXFLAGS) $(CFLAGS_CONSOLE) -o $(CONSOLE_EXECUTABLE) $(LIBS) $(EXE_OBJS)
Expand Down Expand Up @@ -286,7 +289,7 @@ clean:
rm -f factor.dll
rm -f factor.lib
rm -f factor.dll.lib
rm -f libfactor.*
rm -fr libfactor.*
rm -f libfactor-ffi-test.*
rm -f Factor.app/Contents/Frameworks/libfactor.dylib

Expand Down
828 changes: 828 additions & 0 deletions Xcode/factorOSX/factor.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7595E1EC28A1DBDA0031EB24"
BuildableName = "factor"
BlueprintName = "factor"
ReferencedContainer = "container:factor.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7595E1EC28A1DBDA0031EB24"
BuildableName = "factor"
BlueprintName = "factor"
ReferencedContainer = "container:factor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-i=/Users/davec/factor/factorOSX.image"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-i=/Users/davec/factor/boot.unix-arm.64.image"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-i=/Users/davec/factor/factorARM.image"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7595E1EC28A1DBDA0031EB24"
BuildableName = "factor"
BlueprintName = "factor"
ReferencedContainer = "container:factor.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
14 changes: 0 additions & 14 deletions factor.entitlements

This file was deleted.

1 change: 1 addition & 0 deletions factor.entitlements
117 changes: 113 additions & 4 deletions vm/main-unix.cpp
@@ -1,7 +1,116 @@
#include "master.hpp"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>

extern "C" {
const char *getBuild() { //Get current architecture, detectx nearly every architecture. Coded by Freak
#if defined(__x86_64__) || defined(_M_X64)
return "x86_64";
#elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
return "x86_32";
#elif defined(__ARM_ARCH_2__)
return "ARM2";
#elif defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__)
return "ARM3";
#elif defined(__ARM_ARCH_4T__) || defined(__TARGET_ARM_4T)
return "ARM4T";
#elif defined(__ARM_ARCH_5_) || defined(__ARM_ARCH_5E_)
return "ARM5"
#elif defined(__ARM_ARCH_6T2_) || defined(__ARM_ARCH_6T2_)
return "ARM6T2";
#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__)
return "ARM6";
#elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
return "ARM7";
#elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
return "ARM7A";
#elif defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
return "ARM7R";
#elif defined(__ARM_ARCH_7M__)
return "ARM7M";
#elif defined(__ARM_ARCH_7S__)
return "ARM7S";
#elif defined(__aarch64__) || defined(_M_ARM64)
return "ARM64";
#elif defined(mips) || defined(__mips__) || defined(__mips)
return "MIPS";
#elif defined(__sh__)
return "SUPERH";
#elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
return "POWERPC";
#elif defined(__PPC64__) || defined(__ppc64__) || defined(_ARCH_PPC64)
return "POWERPC64";
#elif defined(__sparc__) || defined(__sparc)
return "SPARC";
#elif defined(__m68k__)
return "M68K";
#else
return "UNKNOWN";
#endif
}
}

void print_prot_bits(int prot) {
printf((prot & PROT_READ) == 0 ? "-" : "R");
printf((prot & PROT_WRITE) == 0 ? "-" : "W");
printf((prot & PROT_EXEC) == 0 ? "-" : "X");
}
void *try_mmap_jit(size_t size, int prot) {
int map_flags = MAP_ANON | MAP_PRIVATE | MAP_JIT;
printf("Try mmap with MAP_JIT: ");
print_prot_bits(prot);
void *mem = mmap(NULL, size, prot, map_flags, -1, 0);
if (mem == MAP_FAILED || mem == NULL) {
printf(" FAIL: %s", strerror(errno));
int map_flags = MAP_ANON | MAP_PRIVATE ;
printf(" mmap without MAP_JIT: ");
mem = mmap(NULL, size, prot, map_flags, -1, 0);

if (mem == MAP_FAILED || mem == NULL) {
printf(" FAIL: %s", strerror(errno));
return NULL;
}
}
printf(" PASS: %p", mem);
return mem;
}

void try_mprotect(void *mem, size_t size, int prot) {
printf("Try mprotect: %p ", mem);
print_prot_bits(prot);
int status = mprotect(mem, size, prot);
if (status)
printf(" FAIL: %s", strerror(errno));
else
printf(" PASS");
}

void try_mmap_jit_and_mprotect(size_t size, int prot_mmap, int prot_mprotect) {
void *addr = try_mmap_jit(size, prot_mmap);
printf(" -> ");
if (addr) {
try_mprotect(addr, size, prot_mprotect);
}
putchar('\n');
}

void trymmap() {
const char *arch = getBuild();
printf("ARCH: %s\n", arch);
printf("Using map flags MAP_ANON | MAP_PRIVATE\n");
for (int prot_mmap = 0; prot_mmap < 8; prot_mmap++) {
for (int prot_mprotect = 0; prot_mprotect < 8; prot_mprotect++) {
try_mmap_jit_and_mprotect(4096, prot_mmap, prot_mprotect);
}
}
}

#include "master.hpp"
int main(int argc, char** argv) {
factor::init_mvm();
factor::start_standalone_factor(argc, argv);
return 0;
// trymmap();
factor::init_mvm();
factor::start_standalone_factor(argc, argv);
return 0;
}