From: Martin Stoilov Date: Wed, 10 Oct 2012 05:54:07 +0000 (-0700) Subject: Fixed windows build X-Git-Url: http://rpatk.net/gitweb/?p=rpatk.git;a=commitdiff_plain;h=2654f0ed0ce31b1f986a3c1e375c1c1c3064ceb5 Fixed windows build --- diff --git a/arch/windows/i386/rtypes.h b/arch/windows/i386/rtypes.h index 2581217..b0e431b 100644 --- a/arch/windows/i386/rtypes.h +++ b/arch/windows/i386/rtypes.h @@ -35,11 +35,11 @@ typedef struct {ruint32 p1; ruint32 p2;} rpair_t; #define R_ATOMIC_XCHG(ptr, val) \ do { val = InterlockedExchange (ptr, val); } while (0) -#define R_ATOMIC_ADD(ptr, val) \ - do { InterlockedExchangeAdd (ptr, val); } while (0) +#define R_ATOMIC_ADD(ptr, val, res) \ + do { res = InterlockedExchangeAdd (ptr, val); } while (0) -#define R_ATOMIC_SUB(ptr, val) \ - do { InterlockedExchangeSubtract (ptr, val); } while (0) +#define R_ATOMIC_SUB(ptr, val, res) \ + do { res = InterlockedExchangeAdd (ptr, -val); } while (0) #define R_ATOMIC_GET(ptr, res) \ do { res = *ptr; } while (0) diff --git a/arch/windows/x64/rtypes.h b/arch/windows/x64/rtypes.h index 6aefab9..d3f4267 100644 --- a/arch/windows/x64/rtypes.h +++ b/arch/windows/x64/rtypes.h @@ -30,18 +30,23 @@ typedef struct {ruint32 p1; ruint32 p2;} rpair_t; /* * Atomic operations (Architecture Dependent) */ -#define R_ATOMIC_CMPXCHG(ptr, oldval, newval, resptr) \ - do { InterlockedCompareExchange (ptr, newval, oldval); *resptr = *ptr; } while (0) +#define R_ATOMIC_CMPXCHG(ptr, oldval, newval, res) \ + do { res = InterlockedCompareExchange (ptr, newval, oldval); } while (0) #define R_ATOMIC_XCHG(ptr, val) \ do { val = InterlockedExchange (ptr, val); } while (0) -#define R_ATOMIC_ADD(ptr, val) \ - do { InterlockedExchangeAdd (ptr, val); } while (0) +#define R_ATOMIC_ADD(ptr, val, res) \ + do { res = InterlockedExchangeAdd (ptr, val); } while (0) -#define R_ATOMIC_SUB(ptr, val) \ - do { InterlockedExchangeAdd (ptr, -val); } while (0) +#define R_ATOMIC_SUB(ptr, val, res) \ + do { res = InterlockedExchangeAdd (ptr, -val); } while (0) +#define R_ATOMIC_GET(ptr, res) \ + do { res = *ptr; } while (0) + +#define R_ATOMIC_SET(ptr, val) \ + do { *ptr = val; } while (0) #define R_DEBUG_BRAKE do { __debugbreak(); } while (0) #define R_ASSERT(__a__) do {if (!(__a__)) R_DEBUG_BRAKE; } while (0) diff --git a/rexcc/win32/rexccdep.c b/rexcc/win32/rexccdep.c new file mode 100644 index 0000000..3639e33 --- /dev/null +++ b/rexcc/win32/rexccdep.c @@ -0,0 +1,88 @@ +/* + * Regular Pattern Analyzer Toolkit (RPA/Tk) + * Copyright (c) 2009-2012 Martin Stoilov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Martin Stoilov + */ + +#include +#include +#include +#include "rlib/rbuffer.h" +#include "rexccdep.h" + + +void rex_buffer_unmap_file(rbuffer_t *buf) +{ + HANDLE hFile = INVALID_HANDLE_VALUE; + HANDLE hMapping = 0; + + if (!buf) + return; + hFile = (HANDLE) buf->userdata; + hMapping = (HANDLE) buf->userdata1; + + if (hMapping) + CloseHandle(hMapping); + if (hFile != INVALID_HANDLE_VALUE) + CloseHandle(hFile); + if (buf->s) + UnmapViewOfFile(buf->s); + free(buf); +} + + +rbuffer_t * rex_buffer_map_file(LPCTSTR pFileName) +{ + rbuffer_t *buf; + char *pMappedView = 0; + HANDLE hFile = INVALID_HANDLE_VALUE; + HANDLE hMapping = 0; + unsigned __int64 fileSize; + DWORD sizeLo, sizeHi; + + buf = (rbuffer_t *)malloc(sizeof(rbuffer_t)); + if (!buf) + goto error; + hFile = CreateFile(pFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0); + if (INVALID_HANDLE_VALUE == hFile) + goto error; + sizeLo = GetFileSize(hFile, &sizeHi); + fileSize = (UINT64)sizeLo | ((UINT64)sizeHi << 32); + hMapping = CreateFileMapping(hFile, 0, PAGE_READONLY, sizeHi, sizeLo, 0); + if (!hMapping) + goto error; + pMappedView = (char*)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); + if (NULL == pMappedView) + goto error; + buf->userdata = (void*)hFile; + buf->userdata1 = (void*)hMapping; + buf->s = pMappedView; + buf->size = (unsigned long)fileSize; + buf->alt_destroy = rex_buffer_unmap_file; + return buf; + +error: + if (hMapping) + CloseHandle(hMapping); + if (hFile != INVALID_HANDLE_VALUE) + CloseHandle(hFile); + if (pMappedView) + UnmapViewOfFile(pMappedView); + free(buf); + return (rbuffer_t*)0; +} + diff --git a/rexcc/win32/rexccdep.h b/rexcc/win32/rexccdep.h new file mode 100644 index 0000000..efe157e --- /dev/null +++ b/rexcc/win32/rexccdep.h @@ -0,0 +1,41 @@ +/* + * Regular Pattern Analyzer Toolkit (RPA/Tk) + * Copyright (c) 2009-2012 Martin Stoilov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Martin Stoilov + */ + +#ifndef _REXGREPDEP_H_ +#define _REXGREPDEP_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include "rlib/rbuffer.h" + +rbuffer_t * rex_buffer_map_file(LPCTSTR filename); +void rex_buffer_unmap_file(rbuffer_t *buf); + +#ifdef __cplusplus +} +#endif + +#endif