| 510 | */ |
| 511 | |
| 512 | txMachine *modCloneMachine(xsCreation *creationIn, const char *name) |
| 513 | { |
| 514 | txMachine *the; |
| 515 | xsCreation *creation = creationIn; |
| 516 | void *preparation = xsPreparationAndCreation(creation ? NULL : &creation); |
| 517 | |
| 518 | if (!name) |
| 519 | name = ((txPreparation *)preparation)->main; |
| 520 | |
| 521 | #if pebble |
| 522 | kernelRemaining = 32 * 1024; |
| 523 | unsigned int used, free, max_free; |
| 524 | heap_calc_totals(kernel_heap_get(), &used, &free, &max_free); |
| 525 | if (max_free < kernelRemaining) |
| 526 | kernelRemaining = max_free; |
| 527 | #endif |
| 528 | |
| 529 | if (creation->staticSize) { |
| 530 | uint8_t *context[2]; |
| 531 | |
| 532 | context[0] = machine_alloc(creation->staticSize, -1); |
| 533 | if (NULL == context[0]) { |
| 534 | modLog("failed to allocate xs block"); |
| 535 | return NULL; |
| 536 | } |
| 537 | context[1] = context[0] + creation->staticSize; |
| 538 | |
| 539 | the = xsPrepareMachine(creation, preparation, (char *)name, context, NULL); |
| 540 | if (NULL == the) { |
| 541 | if (context[0]) |
| 542 | machine_free(context[0]); |
| 543 | return NULL; |
| 544 | } |
| 545 | |
| 546 | xsSetContext(the, NULL); |
| 547 | } |
| 548 | else { |
| 549 | the = xsPrepareMachine(creation, preparation, (char *)name, NULL, NULL); |
| 550 | if (NULL == the) |
| 551 | return NULL; |
| 552 | } |
| 553 | |
| 554 | #if pebble |
| 555 | kernelRemaining = 0; |
| 556 | #endif |
| 557 | |
| 558 | #if MODDEF_XS_MODS |
| 559 | uint8_t modStatus = 0; |
| 560 | modInstallMods(the, preparation, &modStatus); |
| 561 | if (modStatus) |
| 562 | xsLog("Mod failed: %s\n", fxAbortString(modStatus)); |
| 563 | #endif |
| 564 | |
| 565 | return the; |
| 566 | } |
| 567 | |
| 568 | static uint16_t gSetupPending = 0; |
| 569 |
no test coverage detected