Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy android port #1530

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open

Legacy android port #1530

wants to merge 43 commits into from

Conversation

mittorn
Copy link
Member

@mittorn mittorn commented Dec 13, 2023

This restores old non-sdl android port
Fix unstable engine in background mode (mostly, TODO: debug some edge cases, gles3compat will crash on any frame without context)
Workaround showing messageboxes on crash (every jni call from handler silently exited process)
Fix host-clang on recent clang versions
Fix android_sleep mode
Refactor jni code, restore egl support (EGL core now can be reused in other platforms, move to separate platform section if needed)

Enabled with --enable-android-legacy option
To build apk, add game code project and xash3d-android-project(android-legacy branch) with --extra-projects option, otherwise only native libraries enabled

  • Revert "engine: partially remove legacy Android port, in preparation of new port merge"
  • waifulib/xcompile: host clang experiments (ndk ld)
  • platform/android_nosdl: fix build (ndk10, host clang15)
  • wscript: add external projects support (updated waf required)
  • waifulib/xcompile: fix host clang16
  • platform/android: rewrite egl part to separate not android-specific file
  • platform/android: disable swbuffer resize hack, wrong buffer size really is an error that should be fixed on Activity side, not here
  • platform/android: debug surface enabling/disabling, add notification for event_set_pause, fix wrong host.status, prevent rendering while no surface
  • platform/eglutil: prevent rendering while no surface
  • ref_soft,ref_gl: fix unaligned read in sprite code
  • imagelib: fix for loop scope
  • platform/android: implement dumb dladdr fallback (only searches in server library)
  • platform/posix: check for non-zero dladdr ret
  • waf/compiler_optimizations: remove no-semantic-interposition for gcc4
  • waf/xcompile: fix ld path for host clang
  • platform/android: prevent rendering without context, fix android_sleep using surfaceless mode or dummy surface if possible
  • ref_soft: fix crash when y < -height
  • waifu: set external waifulibs for extra-projects
  • wscript: check if extra-projects was set in configuration
  • gl2shim: fix gcc 4.9 build
  • gl2shim: add SOFTFP_LINK support for gles3compat
  • waifulib/xcompile: add android-from-none for new host-clang versions, support hardfloat abi in host-clang
  • gl4es: update submodule
  • waifulib/xcompile: disable stpcpy on host-clang
  • waifulib/xcompile: add objcopy tool to android configuration, allow switching to ndk binutils with host clang
  • ref_gl: workaround using fake arb functions on GLES (Mali400 has stub glBindBufferARB somehow!)
  • crashhandler: set host.crashed before messagebox to allow platform code handle crashed state in different way
  • vid/android: Remove pixelFormat selection code, it only used to set desktop bits per pixel
  • waifulib/compiler_optimizations: disable no-semantic-interposition for gcc4 in release builds too
  • platform/android-nosdl: Move all bindings to XashBindings class, workaround broken messageBox from crashhandler
  • platform/android-nosdl: fix declaration style (werror)
  • platform/android-nosdl: add Platform_Shutdown for preShutdown callback
  • engine/system: add asm-based raise implementation for arm, making Sys_DebugBreak more relevant
  • platform/android-nosdl: optionally wait gdb in nativeInit, enable dumpable flag early as possible
  • engine/system: add aarch64 INLINE_RAISE implementation, use tgkill instead of kill
  • platform/android-nosdl: restore SIGTRAP handler
  • platform/android-nosdl: add workarounds for yama bullshit
  • wscript: fix options in external projects
  • scripts/waifulib: save zip task to make it output reuseable
  • wscript: re-enable xash-extras on android
  • fs/android: only enable aasset code in android+sdl build
  • ref_gl: fix loop scope in ripple code

@a1batross
Copy link
Member

After a quick look, I don't have any objections. Will look further a bit later.

@mittorn
Copy link
Member Author

mittorn commented Dec 14, 2023 via email

if( si->nbucket == 0 )
return NULL;

for(int j = 0; j < si->nbucket; j++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing code block and indentation.


extern "C" int __attribute__((visibility("hidden"))) dladdr( const void *addr, Dl_info *info )
{
static int (*pDladdr)( const void *addr, Dl_info *info );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a bit more readable and beautiful:

typedef int (*PFNDLADDR)( const void *addr, Dl_info *info );
PFNDLADDR pfn_dladdr;

if( !pfn_dladdr )
{
<-->void *lib = dlopen( "libdl.so", RTLD_NOW );
<-->if( lib )
<--><-->pfn_dladdr = (PFNDLADDR)dlsym( lib, "dladdr" );
<-->if( pfn_dladdr == (PFNDLADDR)dladdr )
<--><-->pfn_dladdr = 0;
<-->if( !pfn_dladdr )
<--><-->pfn_dladdr = (PFNDLADDR)dladdr_fallback;
}
return pfn_dladdr( addr, info );

Also, do you really need to dlopen libdl.so here? Wouldn't dlsym( RTLD_NEXT, ... be sufficient?

engine/platform/android/dlsym-weak.cpp Outdated Show resolved Hide resolved
return NULL;

for(int j = 0; j < si->nbucket; j++)
for (unsigned n = si->bucket[j]; n != 0; n = si->chain[n]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this file is in C++, why not use auto?

common/defaults.h Outdated Show resolved Hide resolved
@@ -585,6 +589,9 @@ qboolean GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char
if(( f = gEngfuncs.GL_GetProcAddress( name )))
{
// GL_GetProcAddress prints errors about missing functions, so tell user that we found it with different name
#ifdef XASH_GLES
if(i != 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so ugly. I don't know what to do about this, but this better be refactored somehow.

frametype_t frametype = pframetype->type;
frametype_t frametype;

memcpy( &dframetype, pframetype, sizeof( dframetype ));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need dframetype in outer scope?

Maybe its scope could be lowered to this block?

frametype_t frametype = pframetype->type;
frametype_t frametype;

memcpy( &dframetype, pframetype, sizeof( dframetype ));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in ref_gl.

@@ -240,9 +241,22 @@ def strip(self):
return os.path.join(self.gen_binutils_path(), 'llvm-strip')
return os.path.join(self.gen_binutils_path(), 'strip')

def objcopy(self):
if self.is_host() and not self.ndk_binutils:
environ = getattr(self.ctx, 'environ', os.environ)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need getattr here.

Context already should have environ (we're literally overriding compilers and tools through it)

@@ -102,6 +102,42 @@ REFDLLS = [
RefDll('gles3compat', False),
]

def process_extra_projects_opts(ctx):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO extra projects thing should migrate to waifulib/subproject.py after a while...

@TheKingFireS
Copy link

Crash report on HTC Desire 610.
Engine: android-legacy-port (Not only this, also very same exactly happened to all Xash3D forks that use FWGS's xash3d-android-project)
To reproduce crash: Just tap on Xash3D app icon to launch, then it crashed instantly.
ROM: HTC Sense 6.0
OS: Android 4.4.2
Logcat: cat.log (That repeated same xash activity is me attempt to launch Xash3D multiple times.)

@mittorn
Copy link
Member Author

mittorn commented Dec 16, 2023 via email

@mittorn
Copy link
Member Author

mittorn commented Dec 16, 2023 via email

}

extern "C" void* dlsym_weak(void* handle, const char* symbol) {
#include "lib_android.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Includes better be at the start of the file.

Elf_Sym *sym;

if( !server_info )
server_info = ( soinfo* )ANDROID_GetServerLibrary();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You called ANDROID_ here when the function is called Android_.

I think it won't compile.

// libc builds with -fomit-frame-pointer may just eat stack frame (hello, glibc), making this useless
// calling syscalls directly allows to make break like if it was asm("int $3") on x86
#ifdef __arm__
// this multi-line macro hides single line under it, multi-line macro will be expanded to single-line anyway
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unuseful comment. Everybody who ever looked into gcc -E output knows how C preprocessor works.

"svc 0\n\t" \
: \
:"r"(raise_pid), "r"(raise_tid), "r"(raise_sig) \
: "r0", "r1", "r2", "r7", "memory"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten \ at the end of line.

@ghost
Copy link

ghost commented Feb 22, 2024

When will you release it officially?
Delete the old version

@a1batross
Copy link
Member

@amirwolf512lo what do you even mean

@ghost
Copy link

ghost commented Feb 22, 2024

@amirwolf512lo what do you even mean

You do not have players statistics
They all use this version
If you restrict access to it, they will be forced to install the new version
Or you don't do it on purpose

@nekonomicon
Copy link
Member

nekonomicon commented Feb 22, 2024

They all use this version

We know.

@amirwolf512lo
Probably in the next half year after stable release will be disabled access to an old servers.

@a1batross
Copy link
Member

It will be decided after a first truly stable Android release of the new engine.

It depends on how soon players and server owners will migrate to the new protocol. I hope for some cooperation in this.

@a1batross
Copy link
Member

Anyway, it's not the place to discuss such things. If you want to give your ideas on post-first-Android-stable-release, make a new issue.

@a1batross a1batross force-pushed the android-legacy-rebase branch 2 times, most recently from 5bbe02d to 9f4aa27 Compare February 27, 2024 01:58
mittorn and others added 27 commits February 27, 2024 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants