[Vm-dev] Minheadless trial
Ben Coman
btc at openinworld.com
Wed Dec 5 12:56:15 UTC 2018
On Wed, 5 Dec 2018 at 18:45, Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:
>
> Hi Ben,
> I did not follow all the thread in detail, but a lot of missing
> definitions like alloca were in platform specific support headers:
>
>
> https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/platforms/win32/vm/sqPlatformSpecific.h
>
> The fact that minheadless seems a (better ?) re-organisation of sources (I
> guess with a better separation of concerns) does not mean that we have to
> re-invent everything.
> It's just there under our hands.
>
I don't think much is being reinvented. Its just minheadless branched
before much work on 64-bit Windows.
sqPlatformSpecific.h is very much reused, as borne out by this diff...
.../platforms/win32/vm/sqPlatformSpecific.h
.../platforms/minheadless/windows/sqPlatformSpecific-Win32.h
/* win32 sqPlatformSpecific.h -- Platform-specific prototypes /* win32
sqPlatformSpecific.h -- Platform-specific prototypes
/* How to use this file: /* How to
use this file:
This file is for general platform-specific macros and decl This
file is for general platform-specific macros and decl
The goal is to keep most of the other header files generic The goal
is to keep most of the other header files generic
To override a definition or macro from sq.h, you must firs To
override a definition or macro from sq.h, you must firs
provide the new definition. provide
the new definition.
*/ */
#if _WIN32 || _WIN64 | #ifdef WIN32
/* Override necessary definitions */ /* Override
necessary definitions */
#undef putchar #undef
putchar
#include "sqWin32Alloc.h" #include
"sqWin32Alloc.h"
#ifdef _MSC_VER #ifdef
_MSC_VER
#include <windows.h> #include
<windows.h>
#define HAVE_BOOLEAN 1 /* for jpegReaderWriter plugin compati #define
HAVE_BOOLEAN 1 /* for jpegReaderWriter plugin compati
#endif #endif
#ifdef _MSC_VER #ifdef
_MSC_VER
#define squeakFileOffsetType __int64 #define
squeakFileOffsetType __int64
#else #else
#define squeakFileOffsetType unsigned long long #define
squeakFileOffsetType unsigned long long
#endif #endif
#ifdef WIN32_FILE_SUPPORT #ifdef
WIN32_FILE_SUPPORT
#undef sqImageFile #undef
sqImageFile
#undef sqImageFileClose #undef
sqImageFileClose
#undef sqImageFileOpen #undef
sqImageFileOpen
#undef sqImageFilePosition #undef
sqImageFilePosition
#undef sqImageFileRead #undef
sqImageFileRead
#undef sqImageFileSeek #undef
sqImageFileSeek
#undef sqImageFileSeekEnd #undef
sqImageFileSeekEnd
#undef sqImageFileWrite #undef
sqImageFileWrite
#define sqImageFile usqIntptr_t #define
sqImageFile usqIntptr_t
sqInt sqImageFileClose(sqImageFile h); sqInt
sqImageFileClose(sqImageFile h);
sqImageFile sqImageFileOpen(const char *fileName, const char sqImageFile
sqImageFileOpen(const char *fileName, const char
squeakFileOffsetType sqImageFilePosition(sqImageFile h);
squeakFileOffsetType sqImageFilePosition(sqImageFile h);
size_t sqImageFileRead(void *ptr, size_t sz, size_t count, sq size_t
sqImageFileRead(void *ptr, size_t sz, size_t count, sq
squeakFileOffsetType sqImageFileSeek(sqImageFile h, squeakFil
squeakFileOffsetType sqImageFileSeek(sqImageFile h, squeakFil
squeakFileOffsetType sqImageFileSeekEnd(sqImageFile h, squeak
squeakFileOffsetType sqImageFileSeekEnd(sqImageFile h, squeak
size_t sqImageFileWrite(const void *ptr, size_t sz, size_t co size_t
sqImageFileWrite(const void *ptr, size_t sz, size_t co
#else /* when no WIN32_FILE_SUPPORT, add necessary stub for u #else /*
when no WIN32_FILE_SUPPORT, add necessary stub for u
#include <stdlib.h> #include
<stdlib.h>
#include <io.h> /* _get_osfhandle */ #include
<io.h> /* _get_osfhandle */
> #ifndef
PATH_MAX
#define PATH_MAX _MAX_PATH #define
PATH_MAX _MAX_PATH
> #endif
#define fsync(filenumber) FlushFileBuffers((HANDLE)_get_osfha #define
fsync(filenumber) FlushFileBuffers((HANDLE)_get_osfha
#endif /* WIN32_FILE_SUPPORT */ #endif /*
WIN32_FILE_SUPPORT */
/* pluggable primitive support */ /*
pluggable primitive support */
#if defined(_MSC_VER) || defined(__MINGW32__) #if
defined(_MSC_VER) || defined(__MINGW32__)
# undef EXPORT # undef
EXPORT
# define EXPORT(returnType) __declspec( dllexport ) returnTy # define
EXPORT(returnType) __declspec( dllexport ) returnTy
# undef VM_EXPORT # undef
VM_EXPORT
# define VM_EXPORT __declspec( dllexport ) # define
VM_EXPORT __declspec( dllexport )
> # if
defined(BUILD_VM_CORE) && !defined(VM_CORE_STATIC)
> # undef
VM_FUNCTION_EXPORT
> # define
VM_FUNCTION_EXPORT(returnType) __declspec( dllexport ) returnType
> # else
> # undef
VM_FUNCTION_EXPORT
> # define
VM_FUNCTION_EXPORT(returnType) __declspec( dllimport ) returnType
> # endif
#endif #endif
/* missing functions */ /* missing
functions */
#ifdef _MSC_VER #ifdef
_MSC_VER
/* see on msdn the list of functions available /* see on
msdn the list of functions available
* CRT Alphabetical Function Reference * CRT
Alphabetical Function Reference
* https://msdn.microsoft.com/en-US/library/634ca0c2.aspx */ *
https://msdn.microsoft.com/en-US/library/634ca0c2.aspx */
# include <malloc.h> # include
<malloc.h>
# include <float.h> # include
<float.h>
# ifndef alloca # ifndef
alloca
# define alloca _alloca # define
alloca _alloca
# endif # endif
# if _MSC_VER < 1800 /* not available before MSVC 2013 */ # if
_MSC_VER < 1800 /* not available before MSVC 2013 */
# define atoll(x) _atoi64(x) # define
atoll(x) _atoi64(x)
# define strtoll(beg,end,base) _strtoi64(beg,end,base) # define
strtoll(beg,end,base) _strtoi64(beg,end,base)
double round(double); double
round(double);
# endif # endif
# if _MSC_VER < 1900 /* not available before MSVC 2015 */ # if
_MSC_VER < 1900 /* not available before MSVC 2015 */
# define snprintf _snprintf # define
snprintf _snprintf
# ifndef isnan # ifndef
isnan
# define isnan _isnan #
define isnan _isnan
# endif # endif
# endif # endif
# if _MSC_VER < 1300 /* maybe not available before MSVC 7.0 # if
_MSC_VER < 1300 /* maybe not available before MSVC 7.0
# define fabsf(x) ((float)fabs((double)(x))) # define
fabsf(x) ((float)fabs((double)(x)))
# endif # endif
# define bzero(pointer,size) ZeroMemory(pointer,size) # define
bzero(pointer,size) ZeroMemory(pointer,size)
> #else
> # include
<string.h>
> # define
bzero(pointer,size) memset(pointer, 0, size)
#endif #endif
#ifdef __GNUC__ #ifdef
__GNUC__
# if __GNUC__ < 3 # if
__GNUC__ < 3
# define fabsf(x) ((float)fabs((double)(x))) /* not sur # define
fabsf(x) ((float)fabs((double)(x))) /* not sur
# endif # endif
#endif #endif
#else #else
error "Not Win32 or Win64!" | error "Not
Win32!"
#endif /* _WIN32 || _WIN64 */ | #endif /*
WIN32 */
int ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt int
ioSetCursorARGB(sqInt bitsIndex, sqInt w, sqInt h, sqInt
/* poll and profile thread priorities. The stack vm uses a t /* poll and
profile thread priorities. The stack vm uses a t
* VM to poll for I/O, check for delay expiry et al at regula * VM to
poll for I/O, check for delay expiry et al at regula
* VMs use a thread to sample the pc for VM profiling. The p * VMs use
a thread to sample the pc for VM profiling. The p
* to have a priority higher than the main VM thread and the * to have
a priority higher than the main VM thread and the
* to have a priority higher than the poll thread to be able * to have
a priority higher than the poll thread to be able
* We would like POLL_THREAD_PRIORITY to be THREAD_PRIORITY_T * We would
like POLL_THREAD_PRIORITY to be THREAD_PRIORITY_T
* but SetThreadPriority fails with this value on Windows XP. * but
SetThreadPriority fails with this value on Windows XP.
* *
* N.B. THREAD_PRIORITY_TIME_CRITICAL a.k.a. THREAD_BASE_PRIO * N.B.
THREAD_PRIORITY_TIME_CRITICAL a.k.a. THREAD_BASE_PRIO
* THREAD_PRIORITY_MAX a.k.a. THREAD_BASE_PRIORITY_MAX *
THREAD_PRIORITY_MAX a.k.a. THREAD_BASE_PRIORITY_MAX
* See WinBase.h & WinNT.h. * See
WinBase.h & WinNT.h.
*/ */
#if STACKVM #if STACKVM
# define POLL_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST # define
POLL_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST
#endif /* STACKVM */ #endif /*
STACKVM */
#define PROF_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL #define
PROF_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL
#if COGVM #if COGVM
extern void sqMakeMemoryExecutableFromTo(usqIntptr_t, usqIntp extern void
sqMakeMemoryExecutableFromTo(usqIntptr_t, usqIntp
extern void sqMakeMemoryNotExecutableFromTo(usqIntptr_t, usqI extern void
sqMakeMemoryNotExecutableFromTo(usqIntptr_t, usqI
extern int isCFramePointerInUse(void); extern int
isCFramePointerInUse(void);
extern int osCogStackPageHeadroom(void); extern int
osCogStackPageHeadroom(void);
extern void reportMinimumUnusedHeadroom(void); extern void
reportMinimumUnusedHeadroom(void);
#endif #endif
/* Thread support for thread-safe signalSemaphoreWithIndex an /* Thread
support for thread-safe signalSemaphoreWithIndex an
#if STACKVM || NewspeakVM #if STACKVM
|| NewspeakVM
# define sqLowLevelYield() Sleep(0) # define
sqLowLevelYield() Sleep(0)
/* these are used both in the STACKVM & the COGMTVM */ /* these
are used both in the STACKVM & the COGMTVM */
# define sqOSThread void * # define
sqOSThread void *
# define ioOSThreadsEqual(a,b) ((a) == (b)) # define
ioOSThreadsEqual(a,b) ((a) == (b))
# if COGMTVM # if COGMTVM
/* Please read the comment for CogThreadManager in the VMMake /* Please
read the comment for CogThreadManager in the VMMake
* documentation of this API. *
documentation of this API.
*/ */
# define sqOSSemaphore void * # define
sqOSSemaphore void *
# if !ForCOGMTVMImplementation /* this is a read-only export # if
!ForCOGMTVMImplementation /* this is a read-only export
extern const unsigned long tltiIndex; extern
const unsigned long tltiIndex;
# endif # endif
# define ioGetThreadLocalThreadIndex() ((long)TlsGetValue(tl # define
ioGetThreadLocalThreadIndex() ((long)TlsGetValue(tl
# define ioSetThreadLocalThreadIndex(v) (TlsSetValue(tltiInd # define
ioSetThreadLocalThreadIndex(v) (TlsSetValue(tltiInd
# define ioTransferTimeslice() Sleep(0) # define
ioTransferTimeslice() Sleep(0)
# define ioMilliSleep(ms) Sleep(ms) # define
ioMilliSleep(ms) Sleep(ms)
# endif /* COGMTVM */ # endif /*
COGMTVM */
#endif /* STACKVM || NewspeakVM */ #endif /*
STACKVM || NewspeakVM */
#if defined(__GNUC__) #if
defined(__GNUC__)
# if !defined(VM_LABEL) # if
!defined(VM_LABEL)
# define VM_LABEL(foo) asm("\n.globl L" #foo "\nL" #foo #
define VM_LABEL(foo) asm("\n.globl L" #foo "\nL" #foo
# endif # endif
#endif #endif
#if !defined(VM_LABEL) || COGVM #if
!defined(VM_LABEL) || COGVM
# undef VM_LABEL # undef
VM_LABEL
# define VM_LABEL(foo) ((void)0) | # define
VM_LABEL(foo) 0
#endif #endif
/* Define the fields in a struct _CONTEXT as returned by GetThreadContext
that
* represent the program counter and frame pointer on the current
architecture.
*/
#if defined(_M_IX86) || defined(_M_I386) || defined(_X86_) || defined(i386)
|| defined(__i386__)
# define CONTEXT_PC Eip
# define CONTEXT_FP Ebp
# define CONTEXT_SP Esp
#elif defined(x86_64) || defined(__x86_64) || defined(__x86_64__) ||
defined(__amd64) || defined(__amd64__) || defined(x64) || defined(_M_AMD64)
|| defined(_M_X64) || defined(_M_IA64)
# define CONTEXT_PC Rip
# define CONTEXT_FP Rbp
# define CONTEXT_SP Rsp
#else
# error "unknown architecture, program counter field undefined"
#endif
> #ifdef
_MSC_VER
> /* disable
"function XXXX: no return value" */
> #pragma
warning(disable:4035)
> /* optional
C SEH macros */
> #define TRY
__try
> #define
EXCEPT(filter) __except(filter)
> #define
FINALLY __finally
> #else
> /* optional
C SEH macros */
> #define TRY
> #define
EXCEPT(filter) if (0)
> #define
FINALLY
> #endif
But perhaps instead of my change to
"platforms/Cross/plugins/IA32ABI/x64win64abicc.c" here...
https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/313/files#diff-00b8ad306e9c6bb4c8dab2e5b65a1ff8R41
it would have been better to include "sqPlatformSpecific.h" ? Or would
that be heavy handed? I don't know.
At the time it seemed reasonable to echo the similar define here...
platforms/Cross/plugins/IA32ABI/ia32abicc.c: # define alloca _alloca
cheers -ben
P.S. It might be good to reconcile the two files, but I don't know enough
about all the changes myself.
And to avoid divergence maybe(??) one file should #include the other
instead of being a copy.
Or would that be a bad??
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20181205/3c1456fa/attachment-0001.html>
More information about the Vm-dev
mailing list