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

sys_memory: Improve allocation/deallocation syscalls #8403

Merged
merged 1 commit into from
Jun 11, 2020

Conversation

elad335
Copy link
Contributor

@elad335 elad335 commented Jun 11, 2020

  • Do not iterate through all allocations from sys_memory_allocate_from_container everytime sys_memory_free is called in order to search allocation's associated memory container, instead use an atomic lookup table.
  • Remove lv2_memory_alloca which used to track sys_memory_allocate_from_container allocations, no longer needed.
  • Add missing EALIGN error checks in sys_memory_allocate(_from_contao
    iner) syscalls where this error code is returned if size is 0 according to reversing.
  • Fixes a case where sys_memory_free could deallocate PPU stack memory where it shouldn't be able to.
  • Fix race condition in sys_memory_free syscall where the returned memory could get into the main memory container instead of the one selected by sys_memory_allocate_from_container, this race can occure because idm::select container searching was not atomic with deallocation.
    Race example:
u32 addr_thr1;
u32 addr_thr2;

Thread 1:
sys_memory_allocate(..., &addr_thr1);
Thread 2:
sys_memory_free(addr_thr1);
sys_memory_allocate_from_conatiner(..., &addr_thr2);
Thread 1:
sys_memory_free(addr_thr1); // if addr_thr1 == addr_thr2, the race can happen here.

@elad335
Copy link
Contributor Author

elad335 commented Jun 11, 2020

Oh I forgot, this also fixes a case where sys_memory_free could deallocate PPU stack memory where it shouldn't be able to.

@AniLeo AniLeo requested a review from Nekotekina June 11, 2020 16:11
@Nekotekina Nekotekina merged commit b9cb181 into RPCS3:master Jun 11, 2020
@elad335 elad335 deleted the sys_memory branch June 11, 2020 18:17
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.

None yet

2 participants