games/openbor: update to 3.0.r4504

- Add old slaves for some games (e.g. Ghosts'n Demons) based on
  http://www.chronocrash.com/forum/index.php?topic=2360.0
- Annotate .desktop file with build version
- Drop v3.0 from package version
- s/module/game/ in pkg-message for less ambiguity

Changes:	ba1eb4f...4dfdb66
This commit is contained in:
Jan Beich 2017-05-09 20:57:05 +00:00
parent 309e6c96ce
commit 68a8fbed3e
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=440514
36 changed files with 1189 additions and 78 deletions

View File

@ -684,6 +684,10 @@
SUBDIR += openarena-server
SUBDIR += openastromenace
SUBDIR += openbor
SUBDIR += openbor3482
SUBDIR += openbor3711
SUBDIR += openbor3979
SUBDIR += openbor4432
SUBDIR += openbubbles
SUBDIR += opencity
SUBDIR += openclonk

View File

@ -2,28 +2,39 @@
PORTNAME= openbor
# Hint: svn revision is git rev-list --count ${GH_TAGNAME}
PORTVERSION= 3.0.r4432
PORTVERSION?= 4504
CATEGORIES= games
MAINTAINER= jbeich@FreeBSD.org
COMMENT= Moddable fighting game engine (aka Beats of Rage)
LICENSE= BSD3CLAUSE GPLv2+ ISCL
LICENSE= BSD3CLAUSE GPLv2+
.if ${PORTVERSION} >= 4134
LICENSE+= ISCL
.endif
LICENSE_COMB= multi
LICENSE_FILE_BSD3CLAUSE=${WRKSRC}/LICENSE
LICENSE_FILE_GPLv2+ = ${_LICENSE_STORE}/GPLv2 # source/gfxlib/hq2x.c
LICENSE_FILE_ISCL= ${WRKSRC}/source/webmlib/nestegg/LICENSE
LIB_DEPENDS= libpng.so:graphics/png \
libvpx.so:multimedia/libvpx
LIB_DEPENDS= libpng.so:graphics/png
.if ${PORTVERSION} >= 4134
LIB_DEPENDS+= libvpx.so:multimedia/libvpx
.endif
USE_GITHUB= yes
GH_ACCOUNT= DCurrent
GH_TAGNAME= ba1eb4f # git v4432 is actually svn r4437
GH_TAGNAME?= 4dfdb66
USES= gmake pkgconfig
USES+= gmake pkgconfig
.if ${PORTVERSION} < 4433
USE_CSTD= gnu89
.endif
.if ${PORTVERSION} < 4108
USE_SDL= gfx
.else
USE_SDL= gfx2
.endif
WRKSRC_SUBDIR= engine
MAKE_ENV= BUILD_LINUX=1 SDKPATH="${LOCALBASE}" \
GCC_TARGET="${CONFIGURE_TARGET:S/amd64/x86_64/}"
@ -31,14 +42,17 @@ MAKE_ARGS= CC="${CC}" LIBRARIES="${LOCALBASE}/lib" \
TARGET_ARCH=${ARCH:S/i386/x86/} ARCHFLAGS="" \
TARGET_FINAL='${TARGET}' BUILD_MMX="" ECHO="${ECHO}"
LDFLAGS+= -Wl,--as-needed # ogg, pthread, zlib
PLIST_FILES= bin/${PORTNAME} \
share/pixmaps/${PORTNAME}.png
SUB_FILES= pkg-message
SUB_LIST= PKGBASE=${PKGBASE}
PLIST_FILES= bin/${PKGBASE} \
share/pixmaps/${PKGBASE}.png
DOCSDIR= ${PREFIX}/share/doc/${PKGBASE}
PORTDOCS= README
DESKTOP_ENTRIES="OpenBOR" \
DESKTOP_ENTRIES="OpenBOR v3.0 Build ${PORTVERSION}" \
"" \
"${PORTNAME}" \
"${PORTNAME}" \
"${PKGBASE}" \
"${PKGBASE}" \
"Game;ArcadeGame;" \
""
@ -63,10 +77,12 @@ post-patch:
-e 's/@echo/@$$(ECHO)/' \
-e 's/$$(LIBS)/$$(LDFLAGS) &/' \
${WRKSRC}/Makefile
@${REINPLACE_CMD} -e 's/\.openbor/.${PKGBASE}/' \
${WRKSRC}/sdl/sdlport.c
@${GREP} -Flr 'malloc.h' ${WRKSRC} | ${XARGS} ${REINPLACE_CMD} \
's,malloc\.h,stdlib.h,'
@${REINPLACE_CMD} -e 's/^function \(.*\) {/\1() {/' \
-e 's/^get_revnum$$/VERSION_BUILD=${PORTVERSION:E:S/^r//}/' \
-e 's/^get_revnum$$/VERSION_BUILD=${PORTVERSION}/' \
${WRKSRC}/version.sh
do-configure:
@ -74,9 +90,9 @@ do-configure:
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/OpenBOR.elf \
${STAGEDIR}${PREFIX}/bin/${PORTNAME}
${STAGEDIR}${PREFIX}/bin/${PKGBASE}
${INSTALL_DATA} ${WRKSRC}/resources/OpenBOR_Icon_128x128.png \
${STAGEDIR}${PREFIX}/share/pixmaps/${PORTNAME}.png
${STAGEDIR}${PREFIX}/share/pixmaps/${PKGBASE}.png
(cd ${WRKSRC} && ${COPYTREE_SHARE} \
"${PORTDOCS}" ${STAGEDIR}${DOCSDIR})

View File

@ -1,3 +1,3 @@
TIMESTAMP = 1485387608
SHA256 (DCurrent-openbor-3.0.r4432-ba1eb4f_GH0.tar.gz) = 0c26130127d1ec1d98c6c5e68b38a11df3e405ed7e43b7c61762f6ae862538c5
SIZE (DCurrent-openbor-3.0.r4432-ba1eb4f_GH0.tar.gz) = 6087650
TIMESTAMP = 1494074450
SHA256 (DCurrent-openbor-4504-4dfdb66_GH0.tar.gz) = 1387fe221642c109d209f35c711222a6718028e7d435ef56f83668f90d69ca3c
SIZE (DCurrent-openbor-4504-4dfdb66_GH0.tar.gz) = 66890491

View File

@ -2,36 +2,36 @@ Fix potential crashes found by ASan/Clang/GCC
Fix an infinite loop in lcmScriptDeleteMain()
Avoid accidental rounding from abs()
--- openbor.c.orig 2016-12-22 13:02:02 UTC
--- openbor.c.orig 2017-04-22 14:20:08 UTC
+++ openbor.c
@@ -5810,7 +5810,7 @@ s_collision_attack **collision_alloc_att
size_t alloc_size;
// Get amount of memory we'll need.
- alloc_size = sizeof(*result);
+ alloc_size = max_collisons * sizeof(*result);
// Allocate memory and get pointer.
result = malloc(alloc_size);
size_t alloc_size;
// Get amount of memory we'll need.
- alloc_size = sizeof(*result);
+ alloc_size = max_collisons * sizeof(*result);
// Allocate memory and get pointer.
result = malloc(alloc_size);
@@ -5859,7 +5859,7 @@ s_collision_body **collision_alloc_body_
size_t alloc_size;
// Get amount of memory we'll need.
- alloc_size = sizeof(*result);
+ alloc_size = max_collisons * sizeof(*result);
// Allocate memory and get pointer.
result = malloc(alloc_size);
size_t alloc_size;
// Get amount of memory we'll need.
- alloc_size = sizeof(*result);
+ alloc_size = max_collisons * sizeof(*result);
// Allocate memory and get pointer.
result = malloc(alloc_size);
@@ -8204,7 +8204,8 @@ size_t lcmScriptCopyBuffer(ArgList *argl
size_t lcmScriptDeleteMain(char **buf)
{
- size_t len = 0, i = 0;
+ size_t len = 0;
+ long i = 0;
ptrdiff_t pos = 0;
char *newbuf = NULL;
size_t lcmScriptDeleteMain(char **buf)
{
- size_t len = 0, i = 0;
+ size_t len = 0;
+ long i = 0;
ptrdiff_t pos = 0;
char *newbuf = NULL;
@@ -13933,7 +13933,7 @@ void generate_basemap(int map_index, flo
void load_level(char *filename)
@ -53,30 +53,21 @@ Avoid accidental rounding from abs()
if (value > maxvalue)
{
value = maxvalue;
@@ -20471,7 +20476,7 @@ void common_dot()
entity *eOpp; //Owner of dot effect.
s_collision_attack attack; //Attack struct.
@@ -21710,8 +21716,8 @@ int reset_backpain(entity *ent)
if (ent->normaldamageflipdir == DIRECTION_RIGHT) ent->direction = DIRECTION_RIGHT;
else ent->direction = DIRECTION_LEFT;
- for(iIndex = 0; iIndex <= MAX_DOTS; iIndex++) //Loop through all DOT indexes.
+ for(iIndex = 0; iIndex < MAX_DOTS; iIndex++) //Loop through all DOT indexes.
{
iDot_time = self->dot_time[iIndex]; //Get expire time.
iDot_cnt = self->dot_cnt[iIndex]; //Get next tick time.
@@ -21710,8 +21716,8 @@ int reset_backpain(entity *ent)
if (ent->normaldamageflipdir == DIRECTION_RIGHT) ent->direction = DIRECTION_RIGHT;
else ent->direction = DIRECTION_LEFT;
- if(ent->direction == DIRECTION_RIGHT) ent->velocity.x = -1*abs(ent->velocity.x);
- else ent->velocity.x = abs(ent->velocity.x);
+ if(ent->direction == DIRECTION_RIGHT) ent->velocity.x = -1*ABS(ent->velocity.x);
+ else ent->velocity.x = ABS(ent->velocity.x);
return 1;
}
- if(ent->direction == DIRECTION_RIGHT) ent->velocity.x = -1*abs(ent->velocity.x);
- else ent->velocity.x = abs(ent->velocity.x);
+ if(ent->direction == DIRECTION_RIGHT) ent->velocity.x = -1*ABS(ent->velocity.x);
+ else ent->velocity.x = ABS(ent->velocity.x);
return 1;
}
@@ -25831,7 +25837,7 @@ int common_try_wander(entity *target, in
mod = -mod;
}
//if ((self->sortid / 100) % 2)
//if ((self->sortid / 100) % 2)
- if (abs(rand32()) % 2)
+ if (rand32() % 2)
{
@ -85,7 +76,7 @@ Avoid accidental rounding from abs()
@@ -34607,7 +34612,7 @@ void keyboard_setup(int player)
strncpy(buttonnames[SDID_SPECIAL], "Special", 16);
strncpy(buttonnames[SDID_START], "Start", 16);
strncpy(buttonnames[SDID_SCREENSHOT], "Screenshot", 16);
strncpy(buttonnames[SDID_SCREENSHOT], "Screenshot", 16);
- strncpy(buttonnames[SDID_ESC], "Exit", 16);
+ //strncpy(buttonnames[SDID_ESC], "Exit", 16);

View File

@ -1,6 +1,6 @@
Implement Linux-like memory stats for BSDs
--- source/ramlib/ram.c.orig 2015-04-18 21:21:56 UTC
--- source/ramlib/ram.c.orig 2017-04-22 14:20:08 UTC
+++ source/ramlib/ram.c
@@ -25,6 +25,21 @@
#include <mach/task.h>
@ -133,12 +133,12 @@ Implement Linux-like memory stats for BSDs
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -180,7 +262,10 @@ void setSystemRam()
@@ -183,7 +265,10 @@ void setSystemRam()
stackSize = 0x00000000;
systemRam = getFreeRam(BYTES);
#endif
-#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || defined(SYMBIAN))
+#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || defined(SYMBIAN) || \
-#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || defined(SYMBIAN) || defined(VITA))
+#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || defined(SYMBIAN) || defined(VITA) || \
+ defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
+ defined(__OpenBSD__))

View File

@ -0,0 +1,11 @@
--- source/utils.c.bak 2017-04-22 14:20:08 UTC
+++ source/utils.c
@@ -295,7 +295,7 @@ void *checkAlloc(void *ptr, size_t size, const char *f
"\n* Shutting Down *\n\n");
writeToLogFile("Out of memory!\n");
writeToLogFile("Allocation of size %i failed in function '%s' at %s:%i.\n", size, func, file, line);
-#ifndef WIN
+#if defined(__GLIBC__) || defined(ANDROID) || defined(VITA)
writeToLogFile("Memory usage at exit: %u\n", mallinfo().arena);
#endif
exit(2);

View File

@ -0,0 +1,10 @@
To play a game copy its .pak file under ~/.%%PKGBASE%%/Paks/ directory.
If only one file is there OpenBOR would run the game on startup,
otherwise game launcher would appear.
In case a game has data/ directory unpacked you may need to run it
as follows:
$ cd /path/to/game
$ cp -R ~/.%%PKGBASE%%/Saves .
$ OPENBOR_USE_CURDIR=1 %%PKGBASE%%

View File

@ -1,10 +0,0 @@
To play a module copy its .pak file under ~/.openbor/Paks/ directory.
If only one file is there OpenBOR would run the module on startup,
otherwise module launcher would appear.
In case a module has data/ directory unpacked you may need to run it
as follows:
$ cd /path/to/module
$ cp -R ~/.openbor/Saves .
$ OPENBOR_USE_CURDIR=1 openbor

View File

@ -0,0 +1,12 @@
# $FreeBSD$
PORTVERSION= 3482
PKGNAMESUFFIX= ${PORTVERSION}
MASTERDIR= ${.CURDIR}/../openbor
PATCHDIR= ${.CURDIR}/files
DISTINFO_FILE= ${.CURDIR}/distinfo
GH_TAGNAME= 2c1ecd7
.include "${MASTERDIR}/Makefile"

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1317171905
SHA256 (DCurrent-openbor-3482-2c1ecd7_GH0.tar.gz) = 9e92378bd1f97f9d3c6af05faabe9372cbc36f82d41dfa4e1083f9ff2bcf51d3
SIZE (DCurrent-openbor-3482-2c1ecd7_GH0.tar.gz) = 3024595

View File

@ -0,0 +1,30 @@
Fix potential crashes found by ASan/Clang/GCC
--- openbor.c.orig 2011-09-28 01:05:05 UTC
+++ openbor.c
@@ -8843,7 +8843,7 @@ char* llHandleCommandSpawnscript(ArgList
void load_level(char *filename){
- char *buf;
+ char *buf = NULL;
size_t size, len;
ptrdiff_t pos, oldpos;
char *command;
@@ -9820,6 +9820,7 @@ void bar(int x, int y, int value, int ma
else if(pstatus->orientation==verticalbar) max = pstatus->sizey;
else return;
+ if (value < 0) value = 0;
if (value > maxvalue) value = maxvalue;
if(pstatus->type==valuebar)
@@ -12884,7 +12885,7 @@ void common_dot()
entity* eOpp; //Owner of dot effect.
s_attack attack; //Attack struct.
- for(iIndex=0; iIndex<=MAX_DOTS; iIndex++) //Loop through all DOT indexes.
+ for(iIndex=0; iIndex<MAX_DOTS; iIndex++) //Loop through all DOT indexes.
{
iDot_time = self->dot_time[iIndex]; //Get expire time.
iDot_cnt = self->dot_cnt[iIndex]; //Get next tick time.

View File

@ -0,0 +1,13 @@
Don't crash with empty Paks/ directory.
--- sdl/menu.c.orig 2015-04-18 21:21:56 UTC
+++ sdl/menu.c
@@ -747,7 +747,7 @@ void Menu()
}
freeAllLogs();
termMenu();
- if(ctrl == 2)
+ if(dListTotal == 0 || ctrl == 2)
{
if (filelist)
{

View File

@ -0,0 +1,30 @@
Store settings under ~/.openbor instead of current directory
--- sdl/sdlport.c.orig 2011-04-08 16:22:58 UTC
+++ sdl/sdlport.c
@@ -11,6 +11,9 @@
#include "ram.h"
#include "video.h"
#include "menu.h"
+#include <sys/stat.h>
+#include <err.h>
+#include <unistd.h>
#ifdef DARWIN
#include <CoreFoundation/CoreFoundation.h>
@@ -83,6 +86,15 @@ int main(int argc, char *argv[])
packfile_mode(0);
+ if(!getenv("OPENBOR_USE_CURDIR"))
+ {
+ if (chdir(getenv("HOME")) != 0)
+ err(1, "cannot cd to $HOME");
+ if (mkdir(".openbor", 0755) != 0 && errno != EEXIST)
+ err(1, "cannot mkdir $HOME/.openbor");
+ if (chdir(".openbor") != 0)
+ err(1, "cannot cd to $HOME/.openbor");
+ }
dirExists(paksDir, 1);
dirExists(savesDir, 1);
dirExists(logsDir, 1);

View File

@ -0,0 +1,13 @@
Reset seek position for BGM with more than 64 tracks
--- source/gamelib/packfile.c.orig 2011-09-28 01:05:05 UTC
+++ source/gamelib/packfile.c
@@ -1137,7 +1137,7 @@ void packfile_music_read(fileliststruct *filelist, int
getBasePath(packfile, filelist[i].filename, 1);
if(stristr(packfile, ".pak"))
{
- memset(filelist[i].bgmTracks, 0, 256);
+ memset(filelist[i].bgmTracks, 0, sizeof(filelist[i].bgmTracks));
filelist[i].nTracks = 0;
fd = fopen(packfile, "rb");
if(fd == NULL) continue;

View File

@ -0,0 +1,13 @@
Don't crash with > 80 tracks.
--- source/gamelib/packfile.h.orig 2011-04-08 16:22:58 UTC
+++ source/gamelib/packfile.h
@@ -40,7 +40,7 @@ typedef struct pnamestruct{
typedef struct fileliststruct{
char filename[128];
int nTracks;
- char bgmFileName[80][256];
+ char bgmFileName[256][80];
int bgmTrack;
unsigned int bgmTracks[256];
#ifdef SDL

View File

@ -0,0 +1,224 @@
Implement Linux-like memory stats for BSDs
--- source/ramlib/ram.c.orig 2011-04-08 16:22:58 UTC
+++ source/ramlib/ram.c
@@ -27,6 +27,21 @@
#include <mach/task.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <unistd.h>
+# if defined(__DragonFly__)
+#include <sys/kinfo.h> // struct kinfo_proc
+#include <sys/vmmeter.h> // struct vmstats
+# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/user.h> // struct kinfo_proc
+# elif defined(__NetBSD__)
+#include <uvm/uvm_extern.h> // struct uvmexp_sysctl
+# elif defined(__OpenBSD__)
+#include <uvm/uvmexp.h> // struct uvmexp
+# endif
#elif LINUX
#include <sys/sysinfo.h>
#include <unistd.h>
@@ -54,12 +69,22 @@ static u64 systemRam = 0x00000000;
#ifndef WIN
#ifndef XBOX
#ifndef LINUX
+#ifndef __DragonFly__
+#ifndef __FreeBSD__
+#ifndef __FreeBSD_kernel__
+#ifndef __NetBSD__
+#ifndef __OpenBSD__
static unsigned long elfOffset = 0x00000000;
static unsigned long stackSize = 0x00000000;
#endif
#endif
#endif
#endif
+#endif
+#endif
+#endif
+#endif
+#endif
/////////////////////////////////////////////////////////////////////////////
// Symbols
@@ -68,6 +93,11 @@ static unsigned long stackSize = 0x00000
#ifndef WIN
#ifndef XBOX
#ifndef LINUX
+#ifndef __DragonFly__
+#ifndef __FreeBSD__
+#ifndef __FreeBSD_kernel__
+#ifndef __NetBSD__
+#ifndef __OpenBSD__
#if (__GNUC__ > 3)
extern unsigned long _end;
extern unsigned long _start;
@@ -81,6 +111,11 @@ extern unsigned long start;
#endif
#endif
#endif
+#endif
+#endif
+#endif
+#endif
+#endif
/////////////////////////////////////////////////////////////////////////////
// Functions
@@ -101,6 +136,49 @@ u64 getFreeRam(int byte_size)
if(host_page_size(hostPort, &size) != KERN_SUCCESS) return 0;
if(host_statistics(hostPort, HOST_VM_INFO, (host_info_t)&vms, &count) != KERN_SUCCESS) return 0;
return (u64)(((vms.inactive_count+vms.free_count)*size)/byte_size);
+#elif defined(__DragonFly__)
+ struct vmstats vms;
+ size_t sz = sizeof(vms);
+ if (sysctlbyname("vm.vmstats", &vms, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)((vms.v_free_count + vms.v_inactive_count
+ + vms.v_cache_count) * getpagesize()) / byte_size;
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ u_int v_free_count, v_inactive_count, v_cache_count;
+ size_t sz = sizeof(u_int);
+ v_free_count = v_inactive_count = v_cache_count = 0;
+ sysctlbyname("vm.stats.vm.v_free_count",
+ &v_free_count, &sz, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_inactive_count",
+ &v_inactive_count, &sz, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_cache_count",
+ &v_cache_count, &sz, NULL, 0);
+ return (u64)((v_free_count + v_inactive_count + v_cache_count)
+ * getpagesize()) / byte_size;
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(__NetBSD__)
+#undef VM_UVMEXP
+#define VM_UVMEXP VM_UVMEXP2
+#define uvmexp uvmexp_sysctl
+# else
+#define filepages vnodepages
+#define execpages vtextpages
+# endif
+ int mib[] = {
+ CTL_VM,
+ VM_UVMEXP,
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ struct uvmexp uvmexp;
+ size_t sz = sizeof(uvmexp);
+ if (sysctl(mib, miblen, &uvmexp, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)((uvmexp.free + uvmexp.inactive + uvmexp.filepages
+ + uvmexp.execpages) * uvmexp.pagesize) / byte_size;
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -138,11 +216,29 @@ void setSystemRam()
stat.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&stat);
systemRam = stat.dwTotalPhys;
-#elif DARWIN
- u64 mem;
- size_t len = sizeof(mem);
- sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
- systemRam = mem;
+#elif defined(DARWIN) || defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(HW_MEMSIZE) || defined(HW_PHYSMEM64)
+ uint64_t physmem;
+# else
+ u_long physmem;
+# endif
+ int mib[] = {
+ CTL_HW,
+# if defined(HW_MEMSIZE)
+ HW_MEMSIZE,
+# elif defined(HW_PHYSMEM64)
+ HW_PHYSMEM64,
+# else
+ HW_PHYSMEM,
+# endif
+ };
+ size_t sz = sizeof(physmem);
+ if (sysctl(mib, 2, &physmem, &sz, NULL, 0))
+ {
+ physmem = 0;
+ }
+ systemRam = physmem;
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -183,12 +279,22 @@ void setSystemRam()
#ifndef XBOX
#ifndef LINUX
#ifndef SYMBIAN
+#ifndef __DragonFly__
+#ifndef __FreeBSD__
+#ifndef __FreeBSD_kernel__
+#ifndef __NetBSD__
+#ifndef __OpenBSD__
stackSize = (int)&_end - (int)&_start + ((int)&_start - elfOffset);
#endif
#endif
#endif
#endif
#endif
+#endif
+#endif
+#endif
+#endif
+#endif
getRamStatus(BYTES);
}
@@ -215,6 +321,42 @@ u64 getUsedRam(int byte_size)
rval = task_info(task, TASK_BASIC_INFO, tptr, &tcnt);
if (!(rval == KERN_SUCCESS)) return 0;
return info.resident_size/byte_size;
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(__NetBSD__)
+#undef KERN_PROC
+#define KERN_PROC KERN_PROC2
+#define KINFO_PROC struct kinfo_proc2
+# else
+#define KINFO_PROC struct kinfo_proc
+# endif
+# if defined(__DragonFly__)
+#define KP_RSS(kp) (kp.kp_vm_rssize * getpagesize())
+# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#define KP_RSS(kp) (kp.ki_rssize * getpagesize())
+# elif defined(__NetBSD__)
+#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
+# elif defined(__OpenBSD__)
+#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
+# endif
+ int mib[] = {
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_PID,
+ getpid(),
+# if defined(__NetBSD__) || defined(__OpenBSD__)
+ sizeof(KINFO_PROC),
+ 1,
+# endif
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ KINFO_PROC kp;
+ size_t sz = sizeof(KINFO_PROC);
+ if (sysctl(mib, miblen, &kp, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)KP_RSS(kp) / byte_size;
#elif LINUX
unsigned long vm = 0;
FILE *file = fopen("/proc/self/statm", "r");

View File

@ -0,0 +1,12 @@
# $FreeBSD$
PORTVERSION= 3711
PKGNAMESUFFIX= ${PORTVERSION}
MASTERDIR= ${.CURDIR}/../openbor
PATCHDIR= ${.CURDIR}/../openbor3482/files
DISTINFO_FILE= ${.CURDIR}/distinfo
GH_TAGNAME= 6ec17fa
.include "${MASTERDIR}/Makefile"

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1341365279
SHA256 (DCurrent-openbor-3711-6ec17fa_GH0.tar.gz) = adaebfb09d48c6a3bef6c11fce038cac63070fb47660bf1c63b72ccaeaa20e0c
SIZE (DCurrent-openbor-3711-6ec17fa_GH0.tar.gz) = 3029909

View File

@ -0,0 +1,12 @@
# $FreeBSD$
PORTVERSION= 3979
PKGNAMESUFFIX= ${PORTVERSION}
MASTERDIR= ${.CURDIR}/../openbor
PATCHDIR= ${.CURDIR}/files
DISTINFO_FILE= ${.CURDIR}/distinfo
GH_TAGNAME= 2bcf25b
.include "${MASTERDIR}/Makefile"

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1377224669
SHA256 (DCurrent-openbor-3979-2bcf25b_GH0.tar.gz) = 089a07e7a2ac921167687f8b21d637f85f1e6fcd56862f3d63be54e333358cc5
SIZE (DCurrent-openbor-3979-2bcf25b_GH0.tar.gz) = 5683070

View File

@ -0,0 +1,34 @@
Fix potential crashes found by ASan/Clang/GCC
--- openbor.c.orig 2016-12-22 13:02:02 UTC
+++ openbor.c
@@ -13933,7 +13933,7 @@ void generate_basemap(int map_index, flo
void load_level(char *filename)
{
- char *buf;
+ char *buf = NULL;
size_t size, len, sblen;
ptrdiff_t pos, oldpos;
char *command;
@@ -15210,6 +15210,11 @@ void bar(int x, int y, int value, int ma
return;
}
+ if (value < 0)
+ {
+ value = 0;
+ }
+
if (value > maxvalue)
{
value = maxvalue;
@@ -20471,7 +20476,7 @@ void common_dot()
entity *eOpp; //Owner of dot effect.
s_collision_attack attack; //Attack struct.
- for(iIndex = 0; iIndex <= MAX_DOTS; iIndex++) //Loop through all DOT indexes.
+ for(iIndex = 0; iIndex < MAX_DOTS; iIndex++) //Loop through all DOT indexes.
{
iDot_time = self->dot_time[iIndex]; //Get expire time.
iDot_cnt = self->dot_cnt[iIndex]; //Get next tick time.

View File

@ -0,0 +1,13 @@
Don't crash with empty Paks/ directory.
--- sdl/menu.c.orig 2015-04-18 21:21:56 UTC
+++ sdl/menu.c
@@ -747,7 +747,7 @@ void Menu()
}
freeAllLogs();
termMenu();
- if(ctrl == 2)
+ if(dListTotal == 0 || ctrl == 2)
{
if (filelist)
{

View File

@ -0,0 +1,31 @@
Store settings under ~/.openbor instead of current directory
--- sdl/sdlport.c.orig 2015-04-18 21:21:56 UTC
+++ sdl/sdlport.c
@@ -11,6 +11,9 @@
#include "ram.h"
#include "video.h"
#include "menu.h"
+#include <sys/stat.h>
+#include <err.h>
+#include <unistd.h>
#ifdef DARWIN
#include <CoreFoundation/CoreFoundation.h>
@@ -103,6 +105,16 @@ int main(int argc, char *argv[])
#ifdef ANDROID
dirExists(rootDir, 1);
chdir(rootDir);
+#else
+ if(!getenv("OPENBOR_USE_CURDIR"))
+ {
+ if (chdir(getenv("HOME")) != 0)
+ err(1, "cannot cd to $HOME");
+ if (mkdir(".openbor", 0755) != 0 && errno != EEXIST)
+ err(1, "cannot mkdir $HOME/.openbor");
+ if (chdir(".openbor") != 0)
+ err(1, "cannot cd to $HOME/.openbor");
+ }
#endif
dirExists(paksDir, 1);
dirExists(savesDir, 1);

View File

@ -0,0 +1,13 @@
Reset seek position for BGM with more than 64 tracks
--- source/gamelib/packfile.c.orig 2015-04-18 21:22:03 UTC
+++ source/gamelib/packfile.c
@@ -1399,7 +1399,7 @@ void packfile_music_read(fileliststruct
getBasePath(packfile, filelist[i].filename, 1);
if(stristr(packfile, ".pak"))
{
- memset(filelist[i].bgmTracks, 0, 256);
+ memset(filelist[i].bgmTracks, 0, sizeof(filelist[i].bgmTracks));
filelist[i].nTracks = 0;
fd = fopen(packfile, "rb");
if(fd == NULL)

View File

@ -0,0 +1,13 @@
Don't crash with > 80 tracks.
--- source/gamelib/packfile.h.orig 2015-04-18 21:22:03 UTC
+++ source/gamelib/packfile.h
@@ -42,7 +42,7 @@ typedef struct fileliststruct
{
char filename[128];
int nTracks;
- char bgmFileName[80][256];
+ char bgmFileName[256][80];
int bgmTrack;
unsigned int bgmTracks[256];
#ifdef SDL

View File

@ -0,0 +1,224 @@
Implement Linux-like memory stats for BSDs
--- source/ramlib/ram.c.orig 2013-12-29 14:05:10 UTC
+++ source/ramlib/ram.c
@@ -27,6 +27,21 @@
#include <mach/task.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <unistd.h>
+# if defined(__DragonFly__)
+#include <sys/kinfo.h> // struct kinfo_proc
+#include <sys/vmmeter.h> // struct vmstats
+# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/user.h> // struct kinfo_proc
+# elif defined(__NetBSD__)
+#include <uvm/uvm_extern.h> // struct uvmexp_sysctl
+# elif defined(__OpenBSD__)
+#include <uvm/uvmexp.h> // struct uvmexp
+# endif
#elif LINUX
#include <sys/sysinfo.h>
#include <unistd.h>
@@ -54,12 +69,22 @@ static u64 systemRam = 0x00000000;
#ifndef WIN
#ifndef XBOX
#ifndef LINUX
+#ifndef __DragonFly__
+#ifndef __FreeBSD__
+#ifndef __FreeBSD_kernel__
+#ifndef __NetBSD__
+#ifndef __OpenBSD__
static unsigned long elfOffset = 0x00000000;
static unsigned long stackSize = 0x00000000;
#endif
#endif
#endif
#endif
+#endif
+#endif
+#endif
+#endif
+#endif
/////////////////////////////////////////////////////////////////////////////
// Symbols
@@ -68,6 +93,11 @@ static unsigned long stackSize = 0x00000
#ifndef WIN
#ifndef XBOX
#ifndef LINUX
+#ifndef __DragonFly__
+#ifndef __FreeBSD__
+#ifndef __FreeBSD_kernel__
+#ifndef __NetBSD__
+#ifndef __OpenBSD__
#if (__GNUC__ > 3)
extern unsigned long _end;
extern unsigned long _start;
@@ -81,6 +111,11 @@ extern unsigned long start;
#endif
#endif
#endif
+#endif
+#endif
+#endif
+#endif
+#endif
/////////////////////////////////////////////////////////////////////////////
// Functions
@@ -107,6 +142,49 @@ u64 getFreeRam(int byte_size)
return 0;
}
return (u64)(((vms.inactive_count + vms.free_count) * size) / byte_size);
+#elif defined(__DragonFly__)
+ struct vmstats vms;
+ size_t sz = sizeof(vms);
+ if (sysctlbyname("vm.vmstats", &vms, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)((vms.v_free_count + vms.v_inactive_count
+ + vms.v_cache_count) * getpagesize()) / byte_size;
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ u_int v_free_count, v_inactive_count, v_cache_count;
+ size_t sz = sizeof(u_int);
+ v_free_count = v_inactive_count = v_cache_count = 0;
+ sysctlbyname("vm.stats.vm.v_free_count",
+ &v_free_count, &sz, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_inactive_count",
+ &v_inactive_count, &sz, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_cache_count",
+ &v_cache_count, &sz, NULL, 0);
+ return (u64)((v_free_count + v_inactive_count + v_cache_count)
+ * getpagesize()) / byte_size;
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(__NetBSD__)
+#undef VM_UVMEXP
+#define VM_UVMEXP VM_UVMEXP2
+#define uvmexp uvmexp_sysctl
+# else
+#define filepages vnodepages
+#define execpages vtextpages
+# endif
+ int mib[] = {
+ CTL_VM,
+ VM_UVMEXP,
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ struct uvmexp uvmexp;
+ size_t sz = sizeof(uvmexp);
+ if (sysctl(mib, miblen, &uvmexp, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)((uvmexp.free + uvmexp.inactive + uvmexp.filepages
+ + uvmexp.execpages) * uvmexp.pagesize) / byte_size;
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -147,11 +225,29 @@ void setSystemRam()
stat.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&stat);
systemRam = stat.dwTotalPhys;
-#elif DARWIN
- u64 mem;
- size_t len = sizeof(mem);
- sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
- systemRam = mem;
+#elif defined(DARWIN) || defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(HW_MEMSIZE) || defined(HW_PHYSMEM64)
+ uint64_t physmem;
+# else
+ u_long physmem;
+# endif
+ int mib[] = {
+ CTL_HW,
+# if defined(HW_MEMSIZE)
+ HW_MEMSIZE,
+# elif defined(HW_PHYSMEM64)
+ HW_PHYSMEM64,
+# else
+ HW_PHYSMEM,
+# endif
+ };
+ size_t sz = sizeof(physmem);
+ if (sysctl(mib, 2, &physmem, &sz, NULL, 0))
+ {
+ physmem = 0;
+ }
+ systemRam = physmem;
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -199,12 +295,22 @@ void setSystemRam()
#ifndef XBOX
#ifndef LINUX
#ifndef SYMBIAN
+#ifndef __DragonFly__
+#ifndef __FreeBSD__
+#ifndef __FreeBSD_kernel__
+#ifndef __NetBSD__
+#ifndef __OpenBSD__
stackSize = (int)&_end - (int)&_start + ((int)&_start - elfOffset);
#endif
#endif
#endif
#endif
#endif
+#endif
+#endif
+#endif
+#endif
+#endif
getRamStatus(BYTES);
}
@@ -234,6 +340,42 @@ u64 getUsedRam(int byte_size)
return 0;
}
return info.resident_size / byte_size;
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(__NetBSD__)
+#undef KERN_PROC
+#define KERN_PROC KERN_PROC2
+#define KINFO_PROC struct kinfo_proc2
+# else
+#define KINFO_PROC struct kinfo_proc
+# endif
+# if defined(__DragonFly__)
+#define KP_RSS(kp) (kp.kp_vm_rssize * getpagesize())
+# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#define KP_RSS(kp) (kp.ki_rssize * getpagesize())
+# elif defined(__NetBSD__)
+#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
+# elif defined(__OpenBSD__)
+#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
+# endif
+ int mib[] = {
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_PID,
+ getpid(),
+# if defined(__NetBSD__) || defined(__OpenBSD__)
+ sizeof(KINFO_PROC),
+ 1,
+# endif
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ KINFO_PROC kp;
+ size_t sz = sizeof(KINFO_PROC);
+ if (sysctl(mib, miblen, &kp, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)KP_RSS(kp) / byte_size;
#elif LINUX
unsigned long vm = 0;
FILE *file = fopen("/proc/self/statm", "r");

View File

@ -0,0 +1,13 @@
Make room for terminating NUL added by sprintf()
--- source/scriptlib/Parser.c.orig 2016-12-15 02:16:03 UTC
+++ source/scriptlib/Parser.c
@@ -1828,7 +1828,7 @@ void Parser_Mult_expr2(Parser *pparser )
void Parser_Unary_expr(Parser *pparser )
{
- static CHAR buf[MAX_TOKEN_LENGTH + 1];
+ static CHAR buf[MAX_TOKEN_LENGTH + 2];
Instruction *pInstruction = NULL;
if (ParserSet_First(&(pparser->theParserSet), postfix_expr, pparser->theNextToken.theType ))

View File

@ -0,0 +1,12 @@
# $FreeBSD$
PORTVERSION= 4432
PKGNAMESUFFIX= ${PORTVERSION}
MASTERDIR= ${.CURDIR}/../openbor
PATCHDIR= ${.CURDIR}/files
DISTINFO_FILE= ${.CURDIR}/distinfo
GH_TAGNAME= ba1eb4f
.include "${MASTERDIR}/Makefile"

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1485387608
SHA256 (DCurrent-openbor-4432-ba1eb4f_GH0.tar.gz) = 0c26130127d1ec1d98c6c5e68b38a11df3e405ed7e43b7c61762f6ae862538c5
SIZE (DCurrent-openbor-4432-ba1eb4f_GH0.tar.gz) = 6087650

View File

@ -0,0 +1,93 @@
Fix potential crashes found by ASan/Clang/GCC
Fix an infinite loop in lcmScriptDeleteMain()
Avoid accidental rounding from abs()
--- openbor.c.orig 2016-12-22 13:02:02 UTC
+++ openbor.c
@@ -5810,7 +5810,7 @@ s_collision_attack **collision_alloc_att
size_t alloc_size;
// Get amount of memory we'll need.
- alloc_size = sizeof(*result);
+ alloc_size = max_collisons * sizeof(*result);
// Allocate memory and get pointer.
result = malloc(alloc_size);
@@ -5859,7 +5859,7 @@ s_collision_body **collision_alloc_body_
size_t alloc_size;
// Get amount of memory we'll need.
- alloc_size = sizeof(*result);
+ alloc_size = max_collisons * sizeof(*result);
// Allocate memory and get pointer.
result = malloc(alloc_size);
@@ -8204,7 +8204,8 @@ size_t lcmScriptCopyBuffer(ArgList *argl
size_t lcmScriptDeleteMain(char **buf)
{
- size_t len = 0, i = 0;
+ size_t len = 0;
+ long i = 0;
ptrdiff_t pos = 0;
char *newbuf = NULL;
@@ -13933,7 +13933,7 @@ void generate_basemap(int map_index, flo
void load_level(char *filename)
{
- char *buf;
+ char *buf = NULL;
size_t size, len, sblen;
ptrdiff_t pos, oldpos;
char *command;
@@ -15210,6 +15210,11 @@ void bar(int x, int y, int value, int ma
return;
}
+ if (value < 0)
+ {
+ value = 0;
+ }
+
if (value > maxvalue)
{
value = maxvalue;
@@ -20471,7 +20476,7 @@ void common_dot()
entity *eOpp; //Owner of dot effect.
s_collision_attack attack; //Attack struct.
- for(iIndex = 0; iIndex <= MAX_DOTS; iIndex++) //Loop through all DOT indexes.
+ for(iIndex = 0; iIndex < MAX_DOTS; iIndex++) //Loop through all DOT indexes.
{
iDot_time = self->dot_time[iIndex]; //Get expire time.
iDot_cnt = self->dot_cnt[iIndex]; //Get next tick time.
@@ -21710,8 +21716,8 @@ int reset_backpain(entity *ent)
if (ent->normaldamageflipdir == DIRECTION_RIGHT) ent->direction = DIRECTION_RIGHT;
else ent->direction = DIRECTION_LEFT;
- if(ent->direction == DIRECTION_RIGHT) ent->velocity.x = -1*abs(ent->velocity.x);
- else ent->velocity.x = abs(ent->velocity.x);
+ if(ent->direction == DIRECTION_RIGHT) ent->velocity.x = -1*ABS(ent->velocity.x);
+ else ent->velocity.x = ABS(ent->velocity.x);
return 1;
}
@@ -25831,7 +25837,7 @@ int common_try_wander(entity *target, in
mod = -mod;
}
//if ((self->sortid / 100) % 2)
- if (abs(rand32()) % 2)
+ if (rand32() % 2)
{
mod = 3 - mod;
}
@@ -34607,7 +34612,7 @@ void keyboard_setup(int player)
strncpy(buttonnames[SDID_SPECIAL], "Special", 16);
strncpy(buttonnames[SDID_START], "Start", 16);
strncpy(buttonnames[SDID_SCREENSHOT], "Screenshot", 16);
- strncpy(buttonnames[SDID_ESC], "Exit", 16);
+ //strncpy(buttonnames[SDID_ESC], "Exit", 16);
savesettings();
bothnewkeys = 0;

View File

@ -0,0 +1,13 @@
Don't crash with empty Paks/ directory.
--- sdl/menu.c.orig 2015-04-18 21:21:56 UTC
+++ sdl/menu.c
@@ -747,7 +747,7 @@ void Menu()
}
freeAllLogs();
termMenu();
- if(ctrl == 2)
+ if(dListTotal == 0 || ctrl == 2)
{
if (filelist)
{

View File

@ -0,0 +1,30 @@
Store settings under ~/.openbor instead of current directory
--- sdl/sdlport.c.orig 2015-04-18 21:21:56 UTC
+++ sdl/sdlport.c
@@ -11,6 +11,8 @@
#include "ram.h"
#include "video.h"
#include "menu.h"
+#include <sys/stat.h>
+#include <err.h>
#include <time.h>
#include <unistd.h>
@@ -103,6 +105,16 @@ int main(int argc, char *argv[])
#ifdef ANDROID
dirExists(rootDir, 1);
chdir(rootDir);
+#else
+ if(!getenv("OPENBOR_USE_CURDIR"))
+ {
+ if (chdir(getenv("HOME")) != 0)
+ err(1, "cannot cd to $HOME");
+ if (mkdir(".openbor", 0755) != 0 && errno != EEXIST)
+ err(1, "cannot mkdir $HOME/.openbor");
+ if (chdir(".openbor") != 0)
+ err(1, "cannot cd to $HOME/.openbor");
+ }
#endif
dirExists(paksDir, 1);
dirExists(savesDir, 1);

View File

@ -0,0 +1,13 @@
Reset seek position for BGM with more than 64 tracks
--- source/gamelib/packfile.c.orig 2015-04-18 21:22:03 UTC
+++ source/gamelib/packfile.c
@@ -1399,7 +1399,7 @@ void packfile_music_read(fileliststruct
getBasePath(packfile, filelist[i].filename, 1);
if(stristr(packfile, ".pak"))
{
- memset(filelist[i].bgmTracks, 0, 256);
+ memset(filelist[i].bgmTracks, 0, sizeof(filelist[i].bgmTracks));
filelist[i].nTracks = 0;
fd = fopen(packfile, "rb");
if(fd == NULL)

View File

@ -0,0 +1,13 @@
Don't crash with > 80 tracks.
--- source/gamelib/packfile.h.orig 2015-04-18 21:22:03 UTC
+++ source/gamelib/packfile.h
@@ -42,7 +42,7 @@ typedef struct fileliststruct
{
char filename[128];
int nTracks;
- char bgmFileName[80][256];
+ char bgmFileName[256][80];
int bgmTrack;
unsigned int bgmTracks[256];
#ifdef SDL

View File

@ -0,0 +1,190 @@
Implement Linux-like memory stats for BSDs
--- source/ramlib/ram.c.orig 2015-04-18 21:21:56 UTC
+++ source/ramlib/ram.c
@@ -25,6 +25,21 @@
#include <mach/task.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <unistd.h>
+# if defined(__DragonFly__)
+#include <sys/kinfo.h> // struct kinfo_proc
+#include <sys/vmmeter.h> // struct vmstats
+# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/user.h> // struct kinfo_proc
+# elif defined(__NetBSD__)
+#include <uvm/uvm_extern.h> // struct uvmexp_sysctl
+# elif defined(__OpenBSD__)
+#include <uvm/uvmexp.h> // struct uvmexp
+# endif
#elif LINUX
#include <sys/sysinfo.h>
#include <unistd.h>
@@ -48,7 +63,10 @@
static u64 systemRam = 0x00000000;
-#if !(defined(WIN) || defined(LINUX) || defined(DARWIN))
+#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || \
+ defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
+ defined(__OpenBSD__))
static unsigned long elfOffset = 0x00000000;
static unsigned long stackSize = 0x00000000;
#endif
@@ -56,7 +74,10 @@ static unsigned long stackSize = 0x00000
/////////////////////////////////////////////////////////////////////////////
// Symbols
-#if !(defined(WIN) || defined(LINUX) || defined(DARWIN))
+#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || \
+ defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
+ defined(__OpenBSD__))
#if (__GNUC__ > 3)
extern unsigned long _end;
extern unsigned long _start;
@@ -93,6 +114,49 @@ u64 getFreeRam(int byte_size)
return 0;
}
return (u64)(((vms.inactive_count + vms.free_count) * size) / byte_size);
+#elif defined(__DragonFly__)
+ struct vmstats vms;
+ size_t sz = sizeof(vms);
+ if (sysctlbyname("vm.vmstats", &vms, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)((vms.v_free_count + vms.v_inactive_count
+ + vms.v_cache_count) * getpagesize()) / byte_size;
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ u_int v_free_count, v_inactive_count, v_cache_count;
+ size_t sz = sizeof(u_int);
+ v_free_count = v_inactive_count = v_cache_count = 0;
+ sysctlbyname("vm.stats.vm.v_free_count",
+ &v_free_count, &sz, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_inactive_count",
+ &v_inactive_count, &sz, NULL, 0);
+ sysctlbyname("vm.stats.vm.v_cache_count",
+ &v_cache_count, &sz, NULL, 0);
+ return (u64)((v_free_count + v_inactive_count + v_cache_count)
+ * getpagesize()) / byte_size;
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(__NetBSD__)
+#undef VM_UVMEXP
+#define VM_UVMEXP VM_UVMEXP2
+#define uvmexp uvmexp_sysctl
+# else
+#define filepages vnodepages
+#define execpages vtextpages
+# endif
+ int mib[] = {
+ CTL_VM,
+ VM_UVMEXP,
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ struct uvmexp uvmexp;
+ size_t sz = sizeof(uvmexp);
+ if (sysctl(mib, miblen, &uvmexp, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)((uvmexp.free + uvmexp.inactive + uvmexp.filepages
+ + uvmexp.execpages) * uvmexp.pagesize) / byte_size;
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -133,11 +197,29 @@ void setSystemRam()
stat.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&stat);
systemRam = stat.dwTotalPhys;
-#elif DARWIN
- u64 mem;
- size_t len = sizeof(mem);
- sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
- systemRam = mem;
+#elif defined(DARWIN) || defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(HW_MEMSIZE) || defined(HW_PHYSMEM64)
+ uint64_t physmem;
+# else
+ u_long physmem;
+# endif
+ int mib[] = {
+ CTL_HW,
+# if defined(HW_MEMSIZE)
+ HW_MEMSIZE,
+# elif defined(HW_PHYSMEM64)
+ HW_PHYSMEM64,
+# else
+ HW_PHYSMEM,
+# endif
+ };
+ size_t sz = sizeof(physmem);
+ if (sysctl(mib, 2, &physmem, &sz, NULL, 0))
+ {
+ physmem = 0;
+ }
+ systemRam = physmem;
#elif LINUX
struct sysinfo info;
sysinfo(&info);
@@ -180,7 +262,10 @@ void setSystemRam()
stackSize = 0x00000000;
systemRam = getFreeRam(BYTES);
#endif
-#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || defined(SYMBIAN))
+#if !(defined(WIN) || defined(LINUX) || defined(DARWIN) || defined(SYMBIAN) || \
+ defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
+ defined(__OpenBSD__))
stackSize = (int)&_end - (int)&_start + ((int)&_start - elfOffset);
#endif
getRamStatus(BYTES);
@@ -212,6 +297,42 @@ u64 getUsedRam(int byte_size)
return 0;
}
return info.resident_size / byte_size;
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# if defined(__NetBSD__)
+#undef KERN_PROC
+#define KERN_PROC KERN_PROC2
+#define KINFO_PROC struct kinfo_proc2
+# else
+#define KINFO_PROC struct kinfo_proc
+# endif
+# if defined(__DragonFly__)
+#define KP_RSS(kp) (kp.kp_vm_rssize * getpagesize())
+# elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#define KP_RSS(kp) (kp.ki_rssize * getpagesize())
+# elif defined(__NetBSD__)
+#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
+# elif defined(__OpenBSD__)
+#define KP_RSS(kp) (kp.p_vm_rssize * getpagesize())
+# endif
+ int mib[] = {
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_PID,
+ getpid(),
+# if defined(__NetBSD__) || defined(__OpenBSD__)
+ sizeof(KINFO_PROC),
+ 1,
+# endif
+ };
+ u_int miblen = sizeof(mib) / sizeof(mib[0]);
+ KINFO_PROC kp;
+ size_t sz = sizeof(KINFO_PROC);
+ if (sysctl(mib, miblen, &kp, &sz, NULL, 0))
+ {
+ return 0;
+ }
+ return (u64)KP_RSS(kp) / byte_size;
#elif LINUX
unsigned long vm = 0;
FILE *file = fopen("/proc/self/statm", "r");

View File

@ -0,0 +1,13 @@
Make room for terminating NUL added by sprintf()
--- source/scriptlib/Parser.c.orig 2016-12-15 02:16:03 UTC
+++ source/scriptlib/Parser.c
@@ -1828,7 +1828,7 @@ void Parser_Mult_expr2(Parser *pparser )
void Parser_Unary_expr(Parser *pparser )
{
- static CHAR buf[MAX_TOKEN_LENGTH + 1];
+ static CHAR buf[MAX_TOKEN_LENGTH + 2];
Instruction *pInstruction = NULL;
if (ParserSet_First(&(pparser->theParserSet), postfix_expr, pparser->theNextToken.theType ))