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

GC error encountered in Android runtime environment #553

Open
rainyt opened this issue Jun 29, 2022 · 5 comments
Open

GC error encountered in Android runtime environment #553

rainyt opened this issue Jun 29, 2022 · 5 comments

Comments

@rainyt
Copy link

rainyt commented Jun 29, 2022

21ede72#r77274896

This is the key cause of the problem.

And i chaneg it:

pextra *e = extra_pages, *prev = NULL;
	while( e ) {
		__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "page_ptr=%d ptr=%d", e->page_ptr,ptr);
		if( e->page_ptr == ptr ) {
			if( prev )
				prev->next = e->next;
			else
				extra_pages = e->next;
			munmap(e->base_ptr, size + EXTRA_SIZE);
			return;
		}
		prev = e;
		e = e->next;
	}
	munmap(ptr,size);

Crash log:

V/SDL: page_ptr=1965359104 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969422336 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969881088 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1970536448 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1971322880 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2070740992 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2071134208 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2073100288 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2100232192 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2101739520 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2107703296 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=-37945344 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=-37683200 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=-34406400 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=-33488896 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=-33292288 ptr=0
2022-06-30 06:51:30.315 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=0 ptr=0
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1964441600 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1965359104 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969422336 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969881088 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1970536448 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1971322880 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2070740992 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2071134208 ptr=2071134208
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1964441600 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1965359104 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969422336 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969881088 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1970536448 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1971322880 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=2070740992 ptr=2070740992
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1964441600 ptr=1971322880
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1965359104 ptr=1971322880
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969422336 ptr=1971322880
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1969881088 ptr=1971322880
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1970536448 ptr=1971322880
2022-06-30 06:51:30.318 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1971322880 ptr=1971322880
2022-06-30 06:51:30.322 24219-24255/com.example.heapsandroid.helloworld D/hl: zygame/core/Start.hx:18: Start.initApp
2022-06-30 06:51:30.322 24219-24255/com.example.heapsandroid.helloworld D/hl: 
2022-06-30 06:51:30.349 24219-24219/com.example.heapsandroid.helloworld V/SDL: onWindowFocusChanged(): true
2022-06-30 06:51:30.361 24219-24255/com.example.heapsandroid.helloworld E/libEGL: validate_display:92 error 3008 (EGL_BAD_DISPLAY)
2022-06-30 06:51:30.363 24219-24255/com.example.heapsandroid.helloworld V/SDL: setOrientation() orientation=-1 width=800 height=600 resizable=true hint=
2022-06-30 06:51:30.386 24219-24255/com.example.heapsandroid.helloworld V/SDL: page_ptr=1878355956 ptr=2073100288
2022-06-30 06:51:30.400 24219-24255/com.example.heapsandroid.helloworld A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x6fff6ffe6ffd6ffc in tid 24255 (SDLThread), pid 24219 (roid.helloworld)
@rainyt
Copy link
Author

rainyt commented Jun 29, 2022

@ncannasse Do you need such printf?

@rainyt
Copy link
Author

rainyt commented Jun 29, 2022

read memory from 0x4aaa4aaa4aa94aa8 failed (0 of 8 bytes read)

@rainyt
Copy link
Author

rainyt commented Jun 30, 2022

When I used hashlink1.11 to construct Android, no crash occurred

@RandomityGuy
Copy link

I encountered the same bug and I was able to fix this by doing the following changes:
Changing this line

pextra *inf = (pextra*)(offset > (EXTRA_SIZE>>1) ? ((char*)ptr + EXTRA_SIZE - sizeof(pextra)) : (char*)ptr);

to

        pextra *inf = (pextra*)malloc(sizeof(pextra));

and adding a

    free(e);

after this line

hashlink/src/gc.c

Line 1018 in 21ede72

munmap(e->base_ptr, size + EXTRA_SIZE);

This may not be the correct solution, but it doesn't crash for me anymore.

The error seems to stem from the issue that struct pextra is stored in the ptr memory which is susceptible to being overwritten when writing to that block of memory, making the struct values invalid.

@rainyt
Copy link
Author

rainyt commented Jul 8, 2023

I encountered the same bug and I was able to fix this by doing the following changes: Changing this line

pextra *inf = (pextra*)(offset > (EXTRA_SIZE>>1) ? ((char*)ptr + EXTRA_SIZE - sizeof(pextra)) : (char*)ptr);

to

        pextra *inf = (pextra*)malloc(sizeof(pextra));

and adding a

    free(e);

after this line

hashlink/src/gc.c

Line 1018 in 21ede72

munmap(e->base_ptr, size + EXTRA_SIZE);

This may not be the correct solution, but it doesn't crash for me anymore.
The error seems to stem from the issue that struct pextra is stored in the ptr memory which is susceptible to being overwritten when writing to that block of memory, making the struct values invalid.

Thank you, I will try this change.

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

No branches or pull requests

2 participants