aboutsummaryrefslogtreecommitdiff
path: root/Src/replicant/foundation
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/foundation
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/replicant/foundation')
-rw-r--r--Src/replicant/foundation/align.h9
-rw-r--r--Src/replicant/foundation/atomics.h20
-rw-r--r--Src/replicant/foundation/dispatch.h74
-rw-r--r--Src/replicant/foundation/error.h88
-rw-r--r--Src/replicant/foundation/export.h18
-rw-r--r--Src/replicant/foundation/foundation.h7
-rw-r--r--Src/replicant/foundation/guid.h35
-rw-r--r--Src/replicant/foundation/mkncc.h12
-rw-r--r--Src/replicant/foundation/types.h16
-rw-r--r--Src/replicant/foundation/win-amd64/atomics.h104
-rw-r--r--Src/replicant/foundation/win-amd64/types.h92
-rw-r--r--Src/replicant/foundation/win-x86/atomics.h61
-rw-r--r--Src/replicant/foundation/win-x86/types.h98
13 files changed, 634 insertions, 0 deletions
diff --git a/Src/replicant/foundation/align.h b/Src/replicant/foundation/align.h
new file mode 100644
index 00000000..dc232fa7
--- /dev/null
+++ b/Src/replicant/foundation/align.h
@@ -0,0 +1,9 @@
+#pragma once
+
+# if defined(__GNUC__)
+#include <stdlib.h> // for posix_memalign
+#define NALIGN(x) __attribute__((aligned(x)))
+#elif defined(_MSC_VER)
+#include <malloc.h> // for _aligned_malloc
+#define NALIGN(x) __declspec (align(x))
+#endif
diff --git a/Src/replicant/foundation/atomics.h b/Src/replicant/foundation/atomics.h
new file mode 100644
index 00000000..79982232
--- /dev/null
+++ b/Src/replicant/foundation/atomics.h
@@ -0,0 +1,20 @@
+#pragma once
+#if defined(_WIN64) && defined(_M_X64)
+#include "win-amd64/atomics.h"
+#elif defined(_WIN32) && defined(_M_IX86)
+#include "win-x86/atomics.h"
+#elif defined(__APPLE__) && defined(__amd64__)
+#include "osx-amd64/atomics.h"
+#elif defined(__APPLE__) && defined(__i386__)
+#include "osx-x86/atomics.h"
+#elif defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
+#include "android-armv7/atomics.h"
+#elif defined(__ANDROID__) && (defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__))
+#include "android-arm/atomics.h"
+#elif defined(__ANDROID__) && defined(__i386__)
+#include "android-x86/atomics.h"
+#elif defined(__linux__) && defined(__x86_64)
+#include "linux-amd64/atomics.h"
+#else
+#error Port Me!
+#endif
diff --git a/Src/replicant/foundation/dispatch.h b/Src/replicant/foundation/dispatch.h
new file mode 100644
index 00000000..81af541b
--- /dev/null
+++ b/Src/replicant/foundation/dispatch.h
@@ -0,0 +1,74 @@
+#pragma once
+
+#include "guid.h"
+
+#ifdef WIN32
+#ifndef NOVTABLE
+#define NOVTABLE __declspec(novtable)
+#endif
+#else
+#define NOVTABLE
+#endif
+
+
+#if defined(__GNUC__) && (defined(__x86_32__) || defined(__i386__))
+#define WASABICALL __attribute__((stdcall))
+#elif defined (_WIN32)
+#define WASABICALL __stdcall
+#else
+#define WASABICALL
+#endif
+
+namespace Wasabi2
+{
+ class NOVTABLE Dispatchable
+ {
+ protected:
+ Dispatchable(size_t _dispatchable_version) : dispatchable_version(_dispatchable_version) {}
+ ~Dispatchable() {}
+ public:
+#define dispatch_call(code, default_return, func) (DispatchValid(code))?(default_return):func
+#define dispatch_voidcall(code, func) if (DispatchValid(code)) func
+
+ bool DispatchValid(size_t code) const
+ {
+ return code < dispatchable_version;
+ }
+
+ size_t Retain()
+ {
+ return Dispatchable_Retain();
+ }
+
+ size_t Release()
+ {
+ return Dispatchable_Release();
+ }
+
+ int QueryInterface(GUID interface_guid, void **object)
+ {
+ return Dispatchable_QueryInterface(interface_guid, object);
+ }
+
+ template <class ifc_t>
+ int QueryInterface(ifc_t **object)
+ {
+ return Dispatchable_QueryInterface(ifc_t::GetInterfaceGUID(), (void **)object);
+ }
+
+ protected:
+ virtual size_t WASABICALL Dispatchable_Retain() { return 0; }
+ virtual size_t WASABICALL Dispatchable_Release() { return 0; }
+ virtual int WASABICALL Dispatchable_QueryInterface(GUID interface_guid, void **object) { return 1; }
+
+ size_t dispatchable_version;
+ };
+}
+
+#ifndef DECLARE_EXTERNAL_SERVICE
+#define DECLARE_EXTERNAL_SERVICE(_type, _name) extern _type *_name
+#endif
+
+#ifndef DEFINE_EXTERNAL_SERVICE
+#define DEFINE_EXTERNAL_SERVICE(_type, _name) _type *_name=0
+#endif
diff --git a/Src/replicant/foundation/error.h b/Src/replicant/foundation/error.h
new file mode 100644
index 00000000..7ae61211
--- /dev/null
+++ b/Src/replicant/foundation/error.h
@@ -0,0 +1,88 @@
+#pragma once
+#ifdef __cplusplus
+extern "C" {
+#endif
+enum
+{
+ NErr_Success = 0,
+ NErr_True = 0,
+ NErr_Error = 1, // generic error
+ NErr_OutOfMemory = 2,
+ NErr_FileNotFound = 3,
+ NErr_NullPointer = 4,
+ NErr_NotImplemented = 5,// I'm a lazy programmer
+ NErr_EndOfFile = 6, // also used for "end of enumeration"
+ NErr_NeedMoreData = 7, // input buffer was too small to provide useful output. Use this instead of NErr_ReadTruncated when it is expected that the caller can call the function again with more data
+ NErr_False = 8, // returned from a bool-like function to indicate "false" as opposed to "i had an error while figuring it out"
+ NErr_FailedCreate = 9, // Object could not be created
+ NErr_Closed = 10,
+ NErr_TryAgain = 11, // often used in round-robin "isMine()" loops to indicate that you'll take it if no one else wants it first. can also be used for device I/O when the device is busy
+ NErr_NoDevice = 12,
+ NErr_UnsupportedFormat = 13,
+ NErr_Unknown = 14, // NOT meant to be "some unknown error". Usually returned when some passed in enumeration or keyword was an unknown, unexpected or unsupported value
+ NErr_Insufficient = 15, // output buffer was too small
+ NErr_Empty = 16,
+ NErr_LostSynchronization = 17,
+ NErr_TimedOut = 19,
+ NErr_BadParameter = 20,
+ NErr_NoAction = 21, // Returned when no action performed, for example when initializing but something has already been initialized
+
+ // Test case related values
+ NErr_TestFailed = 18, // Result on a test failure, typically used by unit tests and other test cases.
+ NErr_TestPassed = 0, // Result on a test success, typically used by unit tests and other test cases.
+ NErr_TestError = 1, // Result on a test error, typically used by unit tests and other test cases.
+ NErr_TestNotComplete = 22, // Result on a premature stop, typically used by unit tests and other test cases. This is to protect against a scenerio where a test case is in a 'PASSED' state up to a certain point but cannot finish execution due to data missing, environmental issues, etc.
+
+ NErr_Malformed = 23, // some peice of data was malformed or had unexpected value (typically returned by parsers)
+ NErr_WrongFormat = 24, // data was understood but is indicating a different format than expected. e.g. an layer 2 header being encountered by a layer 3 parser
+ NErr_Reserved = 25, // typically returned when a parser encounters data with a reserved flag set to true
+ NErr_Changed = 26, // something changed. e.g. samplerate changed mid-stream
+ NErr_Interrupted = 27,
+ NErr_ConnectionFailed = 28, // generic "can't connect" error
+ NErr_DNS = 29, // no DNS entry for the host
+
+ /* the follow map NError codes to HTTP error codes. but they can be used for other purposes, too */
+ NErr_BadRequest = 30, // aka HTTP 400
+ NErr_Unauthorized = 31, // aka HTTP 401
+ NErr_Forbidden = 32, // aka HTTP 403
+ NErr_NotFound = 33, // aka HTTP 404, differentiated from NErr_FileNotFound
+ NErr_BadMethod = 34, // aka HTTP 405
+ NErr_NotAcceptable = 35, // aka HTTP 406
+ NErr_ProxyAuthenticationRequired = 36, // aka HTTP 407
+ NErr_RequestTimeout = 37, // aka HTTP 408
+ NErr_Conflict = 38, // aka HTTP 409
+ NErr_Gone = 39, // aka HTTP 410
+ NErr_InternalServerError = 40, // aka HTTP 500
+ NErr_ServiceUnavailable = 41, // aka HTTP 503
+
+ NErr_Exception = 42, // Underlying library returns an error or exception that wasn't understood
+ NErr_Underrun = 43, // Asynchronous thread not supplying data fast enough, buffer has insufficient data
+ NErr_NoMatchingImplementation = 44, // Returned when a function that delegates functionality to a matching component is unable to find one e.g. api_playlistmanager::Load
+ NErr_IntegerOverflow = 45,
+ NErr_IncompatibleVersion = 46, // returned e.g. when a "size" field in a passed struct was larger than expected, or when a flag was set that's not understood
+ NErr_Disabled = 47,
+ NErr_ParameterOutOfRange = 48, // Used to signify that a paramater was passed in that is out of bounds for valid values.
+ NErr_OSNotSupported = 49, // something is not supported on this OS (e.g. WASAPI audio on Windows XP)
+ NErr_UnsupportedInterface = 50, // used for some APIs (notably svc_decode). It means that you can provide the requested functionality for the provided data (e.g. filename) but don't support the requested interface
+ NErr_DirectPointer = 51,
+ NErr_ReadOnly = 52,
+ NErr_EndOfEnumeration = NErr_EndOfFile, // we'll eventually make this its own number
+ NErr_ReadTruncated = 54, // somewhat similar to NErr_NeedMoreData. Meant to be used e.g. when a file or input buffer is shorter than expected. Use this instead of NErr_NeedMoreData when the caller cannot provide more data.
+ NErr_Aborted = 55,
+ NErr_BadReturnValue = 56, // e.g. a callback function returns an unexpected value
+ NErr_MaximumDepth = 57,
+ NErr_Stopped = 58,
+ NErr_LengthRequired = 59, // aka HTTP 411
+ NErr_PreconditionFailed = 60, // aka HTTP 411
+ NErr_TooLarge = 61, // aka HTTP 413
+};
+
+typedef int NError;
+typedef int ns_error_t; // TODO: eventually make this the name of the enum
+
+#ifdef __cplusplus
+}
+#endif
+
+// be careful. only use this if your stack variables self-destruct
+#define NSERROR_RETURN_ON_FAILURE(x) { int local_ret = x; if (local_ret != NErr_Success) return local_ret; }
diff --git a/Src/replicant/foundation/export.h b/Src/replicant/foundation/export.h
new file mode 100644
index 00000000..4454075d
--- /dev/null
+++ b/Src/replicant/foundation/export.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#ifdef _MSC_VER
+#define DLLEXPORT __declspec(dllexport)
+#elif defined(__GNUC__)
+#define DLLEXPORT __attribute__ ((visibility("default")))
+#else
+#error port me!
+#endif
+
+#ifdef _MSC_VER
+#define DLLIMPORT __declspec(dllimport)
+#elif defined(__GNUC__)
+#define DLLIMPORT
+#else
+#error port me!
+#endif
+
diff --git a/Src/replicant/foundation/foundation.h b/Src/replicant/foundation/foundation.h
new file mode 100644
index 00000000..85db7dea
--- /dev/null
+++ b/Src/replicant/foundation/foundation.h
@@ -0,0 +1,7 @@
+#pragma once
+#include "dispatch.h"
+#include "atomics.h"
+#include "error.h"
+#include "guid.h"
+#include "mkncc.h"
+#include "types.h"
diff --git a/Src/replicant/foundation/guid.h b/Src/replicant/foundation/guid.h
new file mode 100644
index 00000000..7e638c7d
--- /dev/null
+++ b/Src/replicant/foundation/guid.h
@@ -0,0 +1,35 @@
+#ifndef WASABI2_FOUNDATION_GUID_H
+#define WASABI2_FOUNDATION_GUID_H
+#pragma once
+
+#include "types.h"
+
+#if !defined(_WIN32)
+#ifdef __cplusplus
+#if !defined(GUID_EQUALS_DEFINED) || !defined(_SYS_GUID_OPERATOR_EQ_)
+#define GUID_EQUALS_DEFINED
+#include <memory.h>
+#include <string.h>
+static __inline int operator ==(const GUID &a, const GUID &b) {
+ return !memcmp(&a, &b, sizeof(GUID));
+}
+static __inline int operator !=(const GUID &a, const GUID &b) {
+ return !!memcmp(&a, &b, sizeof(GUID));
+}
+#endif //GUID_EQUALS_DEFINED
+#endif //__cplusplus
+#else
+#include <guiddef.h>
+#endif
+
+#ifdef __cplusplus
+static __inline int operator <(const GUID &a, const GUID &b) {
+ return memcmp(&a, &b, sizeof(GUID)) < 0;
+}
+#endif
+
+
+static const GUID INVALID_GUID = { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} };
+static const GUID GENERIC_GUID = { 0xFFFFFFFF, 0xFFFF, 0xFFFF, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
+
+#endif
diff --git a/Src/replicant/foundation/mkncc.h b/Src/replicant/foundation/mkncc.h
new file mode 100644
index 00000000..461e3a9a
--- /dev/null
+++ b/Src/replicant/foundation/mkncc.h
@@ -0,0 +1,12 @@
+#ifndef WASABI2_FOUNDATION_MKNCC_H
+#define WASABI2_FOUNDATION_MKNCC_H
+#pragma once
+
+// note: this is endian-incompatible with win32's MAKEFOURCC
+// otoh, it shows up nicely in a debug register ;)
+
+#define MK4CC(a, b, c, d) ( (((unsigned long)a)<<24)|(((unsigned long)b)<<16)|(((unsigned long)c)<<8)|((unsigned long)d) )
+#define MK3CC(b, c, d) ( (((unsigned long)b)<<16)|(((unsigned long)c)<<8)|((unsigned long)d) )
+#define MK2CC(c, d) ( (((unsigned long)c)<<8)|((unsigned long)d) )
+
+#endif
diff --git a/Src/replicant/foundation/types.h b/Src/replicant/foundation/types.h
new file mode 100644
index 00000000..b9788fdc
--- /dev/null
+++ b/Src/replicant/foundation/types.h
@@ -0,0 +1,16 @@
+#pragma once
+#if defined(_WIN64) && defined(_M_X64)
+#include "win-amd64/types.h"
+#elif defined(_WIN32) && defined(_M_IX86)
+#include "win-x86/types.h"
+#elif defined(__APPLE__) && defined(__LP64__)
+#include "osx-amd64/types.h"
+#elif defined(__APPLE__) // TODO: && defined(__LP32__)
+#include "osx-x86/types.h"
+#elif defined(__ANDROID__)
+#include "android-arm/types.h"
+#elif defined(__linux__) && defined(__x86_64)
+#include "linux-amd64/types.h"
+#else
+#error port me!
+#endif
diff --git a/Src/replicant/foundation/win-amd64/atomics.h b/Src/replicant/foundation/win-amd64/atomics.h
new file mode 100644
index 00000000..97b24d91
--- /dev/null
+++ b/Src/replicant/foundation/win-amd64/atomics.h
@@ -0,0 +1,104 @@
+/*
+
+ Win64 (amd64) implementation
+
+*/
+
+#pragma once
+#include "../../foundation/types.h"
+#include <Windows.h>
+#include <intrin.h>
+
+#ifdef __cplusplus
+#define NX_ATOMIC_INLINE inline
+#else
+#define NX_ATOMIC_INLINE
+#endif
+
+NX_ATOMIC_INLINE static size_t nx_atomic_inc(volatile size_t *addr)
+{
+ return (size_t)_InterlockedIncrement64((volatile LONGLONG *)addr);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_dec(volatile size_t *addr)
+{
+ return (size_t)_InterlockedDecrement64((volatile LONGLONG *)addr);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_dec_release(volatile size_t *addr)
+{
+ return (size_t)_InterlockedDecrement64((volatile LONGLONG *)addr);
+}
+
+NX_ATOMIC_INLINE static void nx_atomic_write(size_t value, volatile size_t *addr)
+{
+ InterlockedExchange64((volatile LONG64 *)addr, value);
+}
+
+NX_ATOMIC_INLINE static void nx_atomic_write_pointer(void *value, void* volatile *addr)
+{
+ InterlockedExchangePointer(addr, value);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_add(size_t value, volatile size_t* addr)
+{
+ return (size_t)InterlockedExchangeAdd64 ((volatile LONGLONG *)addr, (LONGLONG)value);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_sub(size_t value, volatile size_t* addr)
+{
+ return (size_t)InterlockedExchangeAdd64((volatile LONGLONG *)addr, -(LONGLONG)value);
+}
+
+NX_ATOMIC_INLINE static void *nx_atomic_swap_pointer(void *value, void* volatile *addr)
+{
+ return InterlockedExchangePointer(addr, value);
+}
+
+NX_ATOMIC_INLINE static int nx_atomic_cmpxchg_pointer(void *oldvalue, void *newvalue, void* volatile *addr)
+{
+ return InterlockedCompareExchangePointer(addr, newvalue, oldvalue) == oldvalue;
+}
+/*
+NX_ATOMIC_INLINE static int nx_atomic_cmpxchg2(size_t *oldvalue, size_t *newvalue, volatile size_t *addr)
+{
+ return InterlockedCompare64Exchange128((LONG64 volatile *)addr, (LONG64)newvalue[1], (LONG64)newvalue[0], (LONG64)oldvalue[0]) == oldvalue[0];
+}
+*/
+#if 0
+NX_ATOMIC_INLINE static size_t atomic_increment(volatile size_t *val)
+{
+ return (size_t)InterlockedIncrement((volatile LONG *)val);
+}
+
+NX_ATOMIC_INLINE static size_t atomic_decrement(volatile size_t *val)
+{
+ return (size_t)InterlockedDecrement((volatile LONG *)val);
+}
+
+NX_ATOMIC_INLINE static void atomic_add(volatile size_t *val, size_t add)
+{
+ InterlockedExchangeAdd64((volatile LONGLONG *)val, (LONGLONG)add);
+}
+
+NX_ATOMIC_INLINE static void atomic_sub(volatile size_t *val, size_t sub)
+{
+ InterlockedExchangeAdd64((volatile LONGLONG *)val, -((LONGLONG)sub));
+}
+
+NX_ATOMIC_INLINE static void *atomic_exchange_pointer(void* volatile *target, void *value)
+{
+ return InterlockedExchangePointer(target, value);
+}
+
+NX_ATOMIC_INLINE static bool atomic_compare_exchange_pointer(void* volatile *destination, void *exchange, void *compare)
+{
+ return InterlockedCompareExchangePointer(destination, exchange, compare) == compare;
+}
+
+NX_ATOMIC_INLINE static void atomic_write(volatile size_t *dest, size_t src)
+{
+ InterlockedExchange64((volatile LONG64 *)dest, src);
+}
+
+#endif \ No newline at end of file
diff --git a/Src/replicant/foundation/win-amd64/types.h b/Src/replicant/foundation/win-amd64/types.h
new file mode 100644
index 00000000..2b176f0f
--- /dev/null
+++ b/Src/replicant/foundation/win-amd64/types.h
@@ -0,0 +1,92 @@
+#pragma once
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+
+#include <wchar.h>
+// first, some standard int types
+typedef unsigned int UINT;
+typedef signed int SINT;
+
+typedef unsigned char UCHAR;
+typedef signed char SCHAR;
+
+typedef unsigned long ARGB32;
+typedef unsigned long RGB32;
+
+typedef unsigned long ARGB24;
+typedef unsigned long RGB24;
+
+typedef unsigned short ARGB16;
+typedef unsigned short RGB16;
+
+typedef unsigned long FOURCC;
+
+typedef wchar_t nsxml_char_t;
+typedef wchar_t ns_char_t;
+typedef wchar_t nsfilename_char_t;
+
+typedef int socklen_t;
+
+#if defined(_WIN64) && !defined(__GNUC__)
+#include <stddef.h>
+#include <stdint.h>
+
+ // since windows doesn't have stdint.h
+ typedef unsigned __int64 uint64_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int8 uint8_t;
+ typedef __int64 int64_t;
+ typedef __int32 int32_t;
+ typedef __int16 int16_t;
+
+#ifdef _M_IX86
+ typedef int64_t intptr2_t;
+#elif defined(_M_IX64)
+ typedef unsigned __int128 uint128_t;
+ typedef __int128 int128_t;
+ typedef int128_t intptr2_t
+#endif
+#else
+#include <stdint.h>
+#include <stddef.h>
+#include <inttypes.h>
+#endif
+
+ #ifndef GUID_DEFINED
+ #define GUID_DEFINED
+
+ typedef struct _GUID
+ {
+ uint32_t Data1;
+ uint16_t Data2;
+ uint16_t Data3;
+ uint8_t Data4[8];
+ } GUID;
+/*
+#ifndef _REFCLSID_DEFINED
+#define REFGUID const GUID &
+#define _REFCLSID_DEFINED
+#endif
+*/
+#endif
+
+// this is for GUID == and !=
+#include <objbase.h>
+#ifndef GUID_EQUALS_DEFINED
+ #define GUID_EQUALS_DEFINED
+#endif
+
+ typedef SSIZE_T ssize_t;
+#ifdef NULL
+ #undef NULL
+#endif
+#ifndef NULL
+ #define NULL 0
+#endif
+
+#ifdef _WIN32_WCE
+typedef int intptr_t;
+#endif
diff --git a/Src/replicant/foundation/win-x86/atomics.h b/Src/replicant/foundation/win-x86/atomics.h
new file mode 100644
index 00000000..f61f46d5
--- /dev/null
+++ b/Src/replicant/foundation/win-x86/atomics.h
@@ -0,0 +1,61 @@
+#pragma once
+#include "../../foundation/types.h"
+#include <Windows.h>
+#include <intrin.h>
+
+#ifdef __cplusplus
+#define NX_ATOMIC_INLINE inline
+#else
+#define NX_ATOMIC_INLINE
+#endif
+
+NX_ATOMIC_INLINE static size_t nx_atomic_inc(volatile size_t *addr)
+{
+ return (size_t)_InterlockedIncrement((volatile LONG *)addr);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_dec(volatile size_t *addr)
+{
+ return (size_t)_InterlockedDecrement((volatile LONG *)addr);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_dec_release(volatile size_t *addr)
+{
+ return (size_t)_InterlockedDecrement((volatile LONG *)addr);
+}
+
+NX_ATOMIC_INLINE static void nx_atomic_write(size_t value, volatile size_t *addr)
+{
+ InterlockedExchange((LONG *)addr, value);
+}
+
+NX_ATOMIC_INLINE static void nx_atomic_write_pointer(void *value, void* volatile *addr)
+{
+ InterlockedExchangePointer(addr, value);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_add(size_t value, volatile size_t* addr)
+{
+ return (size_t)InterlockedExchangeAdd((volatile LONG *)addr, (LONG)value);
+}
+
+NX_ATOMIC_INLINE static size_t nx_atomic_sub(size_t value, volatile size_t* addr)
+{
+ return (size_t)InterlockedExchangeAdd((volatile LONG *)addr, -(LONG)value);
+}
+
+NX_ATOMIC_INLINE static void *nx_atomic_swap_pointer(const void *value, void* volatile *addr)
+{
+ return InterlockedExchangePointer(addr, (PVOID)value);
+}
+
+NX_ATOMIC_INLINE static int nx_atomic_cmpxchg_pointer(void *oldvalue, void *newvalue, void* volatile *addr)
+{
+ return InterlockedCompareExchangePointer(addr, newvalue, oldvalue) == oldvalue;
+}
+
+#pragma intrinsic(_InterlockedCompareExchange64)
+NX_ATOMIC_INLINE static int nx_atomic_cmpxchg2(int64_t oldvalue, int64_t newvalue, volatile int64_t *addr)
+{
+ return _InterlockedCompareExchange64(addr, newvalue, oldvalue) == oldvalue;
+}
diff --git a/Src/replicant/foundation/win-x86/types.h b/Src/replicant/foundation/win-x86/types.h
new file mode 100644
index 00000000..156f009a
--- /dev/null
+++ b/Src/replicant/foundation/win-x86/types.h
@@ -0,0 +1,98 @@
+#pragma once
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+
+#include <wchar.h>
+// first, some standard int types
+typedef unsigned int UINT;
+typedef signed int SINT;
+
+typedef unsigned char UCHAR;
+typedef signed char SCHAR;
+
+typedef unsigned long ARGB32;
+typedef unsigned long RGB32;
+
+typedef unsigned long ARGB24;
+typedef unsigned long RGB24;
+
+typedef unsigned short ARGB16;
+typedef unsigned short RGB16;
+
+typedef unsigned long FOURCC;
+
+typedef wchar_t nsxml_char_t;
+typedef wchar_t ns_char_t;
+typedef wchar_t nsfilename_char_t;
+
+typedef int socklen_t;
+
+#if defined(_WIN32) && !defined(__GNUC__)
+#include <stddef.h>
+#if _MSC_VER >= 1600
+#include <stdint.h>
+#else
+ // since windows doesn't have stdint.h
+ typedef unsigned __int64 uint64_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int8 uint8_t;
+ typedef signed __int64 int64_t;
+ typedef signed __int32 int32_t;
+ typedef signed __int16 int16_t;
+ typedef signed __int8 int8_t;
+#ifdef _M_IX86
+ typedef int64_t intptr2_t;
+#else if defined(_M_IX64)
+ typedef unsigned __int128 uint128_t;
+ typedef __int128 int128_t;
+ typedef int128_t intptr2_t
+#endif
+#endif
+#else
+#include <stdint.h>
+#include <stddef.h>
+#include <inttypes.h>
+#endif
+
+#ifndef GUID_DEFINED
+#define GUID_DEFINED
+
+ typedef struct _GUID
+ {
+ uint32_t Data1;
+ uint16_t Data2;
+ uint16_t Data3;
+ uint8_t Data4[8];
+ } GUID;
+/*
+#ifndef _REFCLSID_DEFINED
+#define REFGUID const GUID &
+#define _REFCLSID_DEFINED
+#endif
+*/
+#endif
+
+// this is for GUID == and !=
+#include <objbase.h>
+#ifndef GUID_EQUALS_DEFINED
+ #define GUID_EQUALS_DEFINED
+#endif
+
+#if defined(_MSC_VER)
+#include <BaseTsd.h>
+ typedef SSIZE_T ssize_t;
+#endif
+
+#ifdef NULL
+ #undef NULL
+#endif
+#ifndef NULL
+ #define NULL 0
+#endif
+
+#ifdef _WIN32_WCE
+typedef int intptr_t;
+#endif