microsoft / microsoft/mimalloc

port to iOS

Open
#263 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

I saw the previous iOS issue. I want to get this working on iOS too so I'm game to do any and all code changes and debugging for you if you point me in the right direction.

I tried linking the object file as well as the static library, same crashes.

This below crash is happening before my main.c is called.

myapp`mi_heap_main_init:
    0x104c18b70 <+0>:   stp    x22, x21, [sp, #-0x30]!
    0x104c18b74 <+4>:   stp    x20, x19, [sp, #0x10]
    0x104c18b78 <+8>:   stp    x29, x30, [sp, #0x20]
    0x104c18b7c <+12>:  add    x29, sp, #0x20            ; =0x20 
    0x104c18b80 <+16>:  adrp   x8, 8778
    0x104c18b84 <+20>:  ldr    x8, [x8, #0x2d0]
    0x104c18b88 <+24>:  cbz    x8, 0x104c18b9c           ; <+44>
    0x104c18b8c <+28>:  ldp    x29, x30, [sp, #0x20]
    0x104c18b90 <+32>:  ldp    x20, x19, [sp, #0x10]
    0x104c18b94 <+36>:  ldp    x22, x21, [sp], #0x30
    0x104c18b98 <+40>:  ret    
    0x104c18b9c <+44>:  mrs    x8, TPIDR_EL0
    0x104c18ba0 <+48>:  ldr    x8, [x8]                                 -> EXC_BAD_ACCESS (code=1, address=0x0)
    0x104c18ba4 <+52>:  adrp   x9, 8778
    0x104c18ba8 <+56>:  str    x8, [x9, #0x2c8]
    0x104c18bac <+60>:  bl     0x1051b5ef8               ; symbol stub for: mach_absolute_time
    0x104c18bb0 <+64>:  adr    x8, #-0xcd28              ; _os_random_weak

If you're familiar with Cocoapods, it's an easy way to compile/link a whole bunch of libraries to your iOS app. And I was getting another crash before as well, on the code snippet below, on the @available line in some GoogleDataTransport pod, before I just commented out the code for now. MI_MALLOC_VERSION was printing correctly though.

printf("MI_MALLOC_VERSION = %d\n", mi_version());
      
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
//    if (@available(iOS 13, tvOS 13.0, *)) {
//      [notificationCenter addObserver:self
//                             selector:@selector(iOSApplicationWillEnterForeground:)
//                                 name:UISceneWillEnterForegroundNotification
//                               object:nil];
//      [notificationCenter addObserver:self
//                             selector:@selector(iOSApplicationDidEnterBackground:)
//                                 name:UISceneWillDeactivateNotification
//                               object:nil];
//    }
#endif  // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000

and here was that crash..

myapp`malloc:
    0x100929bdc <+0>:  mov    x1, x0
    0x100929be0 <+4>:  mrs    x8, TPIDR_EL0
   0x100929be4 <+8>:  ldr    x8, [x8, #0x2c8]                     ->  EXC_BAD_ACCESS (code=1, address=0x2c8)
    0x100929be8 <+12>: adrp   x9, 8571
    0x100929bec <+16>: add    x9, x9, #0x988            ; =0x988 
    0x100929bf0 <+20>: cmp    x8, #0x0                  ; =0x0 
    0x100929bf4 <+24>: csel   x0, x9, x8, eq
    0x100929bf8 <+28>: cmp    x1, #0x400                ; =0x400 
    0x100929bfc <+32>: b.hi   0x100929c34               ; <+88>
    0x100929c00 <+36>: add    x8, x1, #0x7              ; =0x7 
    0x100929c04 <+40>: and    x8, x8, #0xfffffffffffffff8
    0x100929c08 <+44>: add    x8, x0, x8
    0x100929c0c <+48>: ldr    x9, [x8, #0x8]
    0x100929c10 <+52>: ldr    x8, [x9, #0x8]
    0x100929c14 <+56>: cbz    x8, 0x100929c34           ; <+88>
    0x100929c18 <+60>: ldr    x10, [x8]
    0x100929c1c <+64>: str    x10, [x9, #0x8]
    0x100929c20 <+68>: ldr    w10, [x9, #0x10]
    0x100929c24 <+72>: add    w10, w10, #0x1            ; =0x1 
    0x100929c28 <+76>: str    w10, [x9, #0x10]
    0x100929c2c <+80>: mov    x0, x8
    0x100929c30 <+84>: ret    
    0x100929c34 <+88>: b      0x10092762c               ; _mi_malloc_generic

where do we start?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported iOS integration and the entry points mi_heap_main_init and malloc, using the CocoaPods setup described in the issue to reproduce the pre-main crashes. Done means mimalloc links as an object file or static library and an iOS app starts without the reported EXC_BAD_ACCESS failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, ios
Domain
mobile-dev, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.