Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Jan 2024 13:43:08 GMT
From:      Jan Beich <jbeich@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 345f32d6dea1 - main - games/openbor7144: add new port
Message-ID:  <202401031343.403Dh8Rh029315@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jbeich:

URL: https://cgit.FreeBSD.org/ports/commit/?id=345f32d6dea1477e59c50faffb1d8f4444bbb464

commit 345f32d6dea1477e59c50faffb1d8f4444bbb464
Author:     Jan Beich <jbeich@FreeBSD.org>
AuthorDate: 2023-11-02 03:00:32 +0000
Commit:     Jan Beich <jbeich@FreeBSD.org>
CommitDate: 2024-01-03 13:42:53 +0000

    games/openbor7144: add new port
    
    An old version tested with ASan before global_beta merge.
---
 games/Makefile                                    |   1 +
 games/openbor7144/Makefile                        |  11 ++
 games/openbor7144/distinfo                        |   3 +
 games/openbor7144/files/patch-openbor.c           |  65 ++++++++
 games/openbor7144/files/patch-sdl_menu.c          |  13 ++
 games/openbor7144/files/patch-sdl_sdlport.c       |  30 ++++
 games/openbor7144/files/patch-source_ramlib_ram.c | 189 ++++++++++++++++++++++
 games/openbor7144/files/patch-source_utils.c      |  19 +++
 8 files changed, 331 insertions(+)

diff --git a/games/Makefile b/games/Makefile
index a31c1abe97f8..dc50fd87e107 100644
--- a/games/Makefile
+++ b/games/Makefile
@@ -703,6 +703,7 @@
     SUBDIR += openbor3711
     SUBDIR += openbor3979
     SUBDIR += openbor4432
+    SUBDIR += openbor7144
     SUBDIR += openbubbles
     SUBDIR += openbve
     SUBDIR += opencity
diff --git a/games/openbor7144/Makefile b/games/openbor7144/Makefile
new file mode 100644
index 000000000000..2143d59faa9f
--- /dev/null
+++ b/games/openbor7144/Makefile
@@ -0,0 +1,11 @@
+PORTVERSION=	7144
+PORTREVISION=	0
+PKGNAMESUFFIX=	${PORTVERSION}
+
+MASTERDIR=	${.CURDIR}/../openbor
+PATCHDIR=	${.CURDIR}/files
+DISTINFO_FILE=	${.CURDIR}/distinfo
+
+GH_TAGNAME=	b8303cce
+
+.include "${MASTERDIR}/Makefile"
diff --git a/games/openbor7144/distinfo b/games/openbor7144/distinfo
new file mode 100644
index 000000000000..159ae24c4263
--- /dev/null
+++ b/games/openbor7144/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1698894032
+SHA256 (DCurrent-openbor-7144-b8303cce_GH0.tar.gz) = 1fdd30b64c009fbe03809d04fa6276cf386bef59696fedb0e3a05b12374c3e8d
+SIZE (DCurrent-openbor-7144-b8303cce_GH0.tar.gz) = 26901256
diff --git a/games/openbor7144/files/patch-openbor.c b/games/openbor7144/files/patch-openbor.c
new file mode 100644
index 000000000000..cec69bb2ff6e
--- /dev/null
+++ b/games/openbor7144/files/patch-openbor.c
@@ -0,0 +1,65 @@
+Fix potential crashes found by ASan/Clang/GCC
+Fix an infinite loop in lcmScriptDeleteMain()
+
+--- openbor.c.orig	2018-07-06 15:13:16 UTC
++++ openbor.c
+@@ -6259,17 +6259,17 @@ s_collision_attack *collision_alloc_attack_instance(s_
+ //
+ // Allocate an empty collision attack list.
+ s_collision_attack **collision_alloc_attack_list()
+ {
+     s_collision_attack **result;
+     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);
+ 
+     // Make sure the list is blank.
+     memset(result, 0, alloc_size);
+ 
+     // return result.
+@@ -6308,17 +6308,17 @@ s_collision_body *collision_alloc_body_instance(s_coll
+ //
+ // Allocate an empty collision attack list.
+ s_collision_body **collision_alloc_body_list()
+ {
+     s_collision_body **result;
+     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);
+ 
+     // Make sure the list is blank.
+     memset(result, 0, alloc_size);
+ 
+     // return result.
+@@ -8743,7 +8743,8 @@ size_t lcmScriptCopyBuffer(ArgList *arglist, char *buf
+ 
+ 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;
+ 
+@@ -15920,6 +15921,11 @@ void bar(int x, int y, int value, int maxvalue, s_bars
+     else
+     {
+         return;
++    }
++
++    if (value < 0)
++    {
++        value = 0;
+     }
+ 
+     if (value > maxvalue)
diff --git a/games/openbor7144/files/patch-sdl_menu.c b/games/openbor7144/files/patch-sdl_menu.c
new file mode 100644
index 000000000000..1fe1fd9529f3
--- /dev/null
+++ b/games/openbor7144/files/patch-sdl_menu.c
@@ -0,0 +1,13 @@
+Don't crash with empty Paks/ directory.
+
+--- sdl/menu.c.orig	2018-07-06 15:13:16 UTC
++++ sdl/menu.c
+@@ -753,7 +753,7 @@ void Menu()
+ 		}
+ 		freeAllLogs();
+ 		termMenu();
+-		if(ctrl == 2)
++		if(dListTotal == 0 || ctrl == 2)
+ 		{
+ 			if (filelist)
+ 			{
diff --git a/games/openbor7144/files/patch-sdl_sdlport.c b/games/openbor7144/files/patch-sdl_sdlport.c
new file mode 100644
index 000000000000..3a6b42660515
--- /dev/null
+++ b/games/openbor7144/files/patch-sdl_sdlport.c
@@ -0,0 +1,30 @@
+Store settings under ~/.openbor instead of current directory
+
+--- sdl/sdlport.c.orig	2018-07-06 15:13:16 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>
+ 
+@@ -135,6 +137,16 @@ int main(int argc, char *argv[])
+     }
+ 	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);
diff --git a/games/openbor7144/files/patch-source_ramlib_ram.c b/games/openbor7144/files/patch-source_ramlib_ram.c
new file mode 100644
index 000000000000..f37ceae0bb48
--- /dev/null
+++ b/games/openbor7144/files/patch-source_ramlib_ram.c
@@ -0,0 +1,189 @@
+Implement Linux-like memory stats for BSDs
+
+--- source/ramlib/ram.c.orig	2018-07-06 15:13:16 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 = 0x00000000;
+ /////////////////////////////////////////////////////////////////////////////
+ // 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,48 @@ 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 = 0, v_inactive_count = 0, v_cache_count = 0;
++    size_t sz = sizeof(u_int);
++    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 +196,29 @@ void setSystemRam()
+     stat.dwLength = sizeof(MEMORYSTATUSEX);
+     GlobalMemoryStatusEx(&stat);
+     systemRam = stat.ullTotalPhys;
+-#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,7 +264,10 @@ void setSystemRam()
+     stackSize = 0x00000000;
+     systemRam = getFreeRam(BYTES);
+ #endif
+-#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__))
+     stackSize = (int)&_end - (int)&_start + ((int)&_start - elfOffset);
+ #endif
+     getRamStatus(BYTES);
+@@ -215,6 +299,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");
diff --git a/games/openbor7144/files/patch-source_utils.c b/games/openbor7144/files/patch-source_utils.c
new file mode 100644
index 000000000000..65fb72c0c7ed
--- /dev/null
+++ b/games/openbor7144/files/patch-source_utils.c
@@ -0,0 +1,19 @@
+source/utils.c:303:54: error: implicit declaration of function 'mallinfo' is invalid in C99
+      [-Werror,-Wimplicit-function-declaration]
+        writeToLogFile("Memory usage at exit: %u\n", mallinfo().arena);
+                                                     ^
+source/utils.c:303:64: error: member reference base type 'int' is not a structure or union
+        writeToLogFile("Memory usage at exit: %u\n", mallinfo().arena);
+                                                     ~~~~~~~~~~^~~~~~
+
+--- source/utils.c.orig	2018-07-06 15:13:16 UTC
++++ source/utils.c
+@@ -303,7 +303,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
+         borExit(2);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401031343.403Dh8Rh029315>