mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-21 09:47:01 +02:00
1 parent
ff94a8281d
commit
d9dfefadcb
6 files changed
+34
-32
No files matched your search
+2
-6
@@ -153,8 +153,6 @@ typedef unsigned char niarelap_file_t[];
|
|||||||
|
|
||||||
extern unsigned int verbose;
|
extern unsigned int verbose;
|
||||||
|
|
||||||
pthread_cond_t spin;
|
|
||||||
|
|
||||||
extern char* pongo_path;
|
extern char* pongo_path;
|
||||||
#ifdef TUI
|
#ifdef TUI
|
||||||
extern bool tui_started;
|
extern bool tui_started;
|
||||||
@@ -174,7 +172,6 @@ extern uint64_t palerain_flags;
|
|||||||
extern pthread_mutex_t log_mutex;
|
extern pthread_mutex_t log_mutex;
|
||||||
|
|
||||||
extern pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
extern pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
||||||
pthread_cond_t spin;
|
|
||||||
|
|
||||||
extern int pongo_thr_running, dfuhelper_thr_running;
|
extern int pongo_thr_running, dfuhelper_thr_running;
|
||||||
extern bool device_has_booted;
|
extern bool device_has_booted;
|
||||||
@@ -216,8 +213,8 @@ int issue_pongo_command(usb_device_handle_t, char*);
|
|||||||
int tui(void);
|
int tui(void);
|
||||||
int optparse(int argc, char* argv[]);
|
int optparse(int argc, char* argv[]);
|
||||||
|
|
||||||
bool palerain_unblock(void);
|
bool get_spin(void);
|
||||||
bool palerain_block(void);
|
bool set_spin(bool val);
|
||||||
bool get_found_pongo(void);
|
bool get_found_pongo(void);
|
||||||
void* pongo_helper(void* _);
|
void* pongo_helper(void* _);
|
||||||
bool set_found_pongo(bool val);
|
bool set_found_pongo(bool val);
|
||||||
@@ -230,5 +227,4 @@ void io_stop(stuff_t *stuff);
|
|||||||
|
|
||||||
void print_credits(void);
|
void print_credits(void);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+11
-8
@@ -100,7 +100,7 @@ int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
|
|||||||
printf("DisplayName: %s\n", dev.displayName);
|
printf("DisplayName: %s\n", dev.displayName);
|
||||||
|
|
||||||
device_has_booted = true;
|
device_has_booted = true;
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
|
|||||||
devinfo_free(&dev);
|
devinfo_free(&dev);
|
||||||
if ((palerain_flags & palerain_option_enter_recovery)) {
|
if ((palerain_flags & palerain_option_enter_recovery)) {
|
||||||
device_has_booted = true;
|
device_has_booted = true;
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -226,7 +226,7 @@ void* connected_dfu_mode(struct irecv_device_info* info) {
|
|||||||
if (IS_APPLE_HOME) {
|
if (IS_APPLE_HOME) {
|
||||||
step(2, 0, "Put device in upright orientation", NULL, 0);
|
step(2, 0, "Put device in upright orientation", NULL, 0);
|
||||||
}
|
}
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -243,7 +243,7 @@ void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
|
|||||||
int ret = reboot_cmd(event->device.udid);
|
int ret = reboot_cmd(event->device.udid);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
LOG(LOG_INFO, "Restarted device");
|
LOG(LOG_INFO, "Restarted device");
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
}
|
}
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
@@ -274,7 +274,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
|
|||||||
if (!ret) {
|
if (!ret) {
|
||||||
LOG(LOG_INFO, "Exited recovery mode");
|
LOG(LOG_INFO, "Exited recovery mode");
|
||||||
device_has_booted = true;
|
device_has_booted = true;
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
} else {
|
} else {
|
||||||
LOG(LOG_WARNING, "Could not exit recovery mode");
|
LOG(LOG_WARNING, "Could not exit recovery mode");
|
||||||
@@ -295,7 +295,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
|
|||||||
printf("DisplayName: %s\n", info.display_name);
|
printf("DisplayName: %s\n", info.display_name);
|
||||||
|
|
||||||
device_has_booted = true;
|
device_has_booted = true;
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
}
|
}
|
||||||
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
||||||
@@ -321,7 +321,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
|
|||||||
printf("DisplayName: %s\n", info.display_name);
|
printf("DisplayName: %s\n", info.display_name);
|
||||||
|
|
||||||
device_has_booted = true;
|
device_has_booted = true;
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
unsubscribe_cmd();
|
unsubscribe_cmd();
|
||||||
}
|
}
|
||||||
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
||||||
@@ -346,8 +346,11 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
|
|||||||
|
|
||||||
void *dfuhelper(void* ptr) {
|
void *dfuhelper(void* ptr) {
|
||||||
dfuhelper_thr_running = true;
|
dfuhelper_thr_running = true;
|
||||||
|
set_spin(1);
|
||||||
subscribe_cmd(device_event_cb, irecv_device_event_cb);
|
subscribe_cmd(device_event_cb, irecv_device_event_cb);
|
||||||
palerain_block();
|
while (get_spin()) {
|
||||||
|
sleep(1);
|
||||||
|
};
|
||||||
dfuhelper_thr_running = false;
|
dfuhelper_thr_running = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+5
-8
@@ -30,9 +30,8 @@
|
|||||||
#include <paleinfo.h>
|
#include <paleinfo.h>
|
||||||
|
|
||||||
pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
||||||
pthread_cond_t spin;
|
|
||||||
|
|
||||||
bool found_pongo = 0;
|
bool spin, found_pongo = 0;
|
||||||
uint64_t ecid_wait_for_dfu = 0;
|
uint64_t ecid_wait_for_dfu = 0;
|
||||||
|
|
||||||
static bool get_locked_bool(bool* val, pthread_mutex_t* mutex) {
|
static bool get_locked_bool(bool* val, pthread_mutex_t* mutex) {
|
||||||
@@ -51,14 +50,12 @@ static bool set_locked_bool(bool* val, bool newval, pthread_mutex_t* mutex) {
|
|||||||
return newval;
|
return newval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool palerain_block(void) {
|
bool get_spin(void) {
|
||||||
pthread_mutex_lock(&spin_mutex);
|
return get_locked_bool(&spin, &spin_mutex);
|
||||||
pthread_cond_wait(&spin, &spin_mutex);
|
|
||||||
pthread_mutex_unlock(&spin_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool palerain_unblock(void) {
|
bool set_spin(bool newval) {
|
||||||
pthread_cond_broadcast(&spin);
|
return set_locked_bool(&spin, newval, &spin_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_found_pongo(void) {
|
bool get_found_pongo(void) {
|
||||||
|
|||||||
+6
-4
@@ -107,7 +107,6 @@ int palera1n(int argc, char *argv[], char *envp[]) {
|
|||||||
pthread_mutex_init(&spin_mutex, NULL);
|
pthread_mutex_init(&spin_mutex, NULL);
|
||||||
pthread_mutex_init(&found_pongo_mutex, NULL);
|
pthread_mutex_init(&found_pongo_mutex, NULL);
|
||||||
pthread_mutex_init(&ecid_dfu_wait_mutex, NULL);
|
pthread_mutex_init(&ecid_dfu_wait_mutex, NULL);
|
||||||
pthread_cond_init(&spin, NULL);
|
|
||||||
if ((ret = build_checks())) return ret;
|
if ((ret = build_checks())) return ret;
|
||||||
if ((ret = optparse(argc, argv))) goto cleanup;
|
if ((ret = optparse(argc, argv))) goto cleanup;
|
||||||
if (!(palerain_flags & palerain_option_device_info) && (palerain_flags & palerain_option_palerain_version)) goto normal_exit;
|
if (!(palerain_flags & palerain_option_device_info) && (palerain_flags & palerain_option_palerain_version)) goto normal_exit;
|
||||||
@@ -141,7 +140,7 @@ int palera1n(int argc, char *argv[], char *envp[]) {
|
|||||||
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
|
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
|
||||||
pthread_create(&dfuhelper_thread, NULL, dfuhelper, NULL);
|
pthread_create(&dfuhelper_thread, NULL, dfuhelper, NULL);
|
||||||
pthread_join(dfuhelper_thread, NULL);
|
pthread_join(dfuhelper_thread, NULL);
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
if ((palerain_flags & (palerain_option_dfuhelper_only |
|
if ((palerain_flags & (palerain_option_dfuhelper_only |
|
||||||
palerain_option_reboot_device |
|
palerain_option_reboot_device |
|
||||||
palerain_option_exit_recovery |
|
palerain_option_exit_recovery |
|
||||||
@@ -155,10 +154,14 @@ int palera1n(int argc, char *argv[], char *envp[]) {
|
|||||||
|
|
||||||
if ((palerain_flags & (palerain_option_pongo_exit | palerain_option_demote)))
|
if ((palerain_flags & (palerain_option_pongo_exit | palerain_option_demote)))
|
||||||
goto normal_exit;
|
goto normal_exit;
|
||||||
|
set_spin(1);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
|
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
|
||||||
pthread_join(pongo_thread, NULL);
|
pthread_join(pongo_thread, NULL);
|
||||||
palerain_block();
|
while (get_spin())
|
||||||
|
{
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
normal_exit:
|
normal_exit:
|
||||||
cleanup:
|
cleanup:
|
||||||
if (override_kpf.magic == OVERRIDE_MAGIC) {
|
if (override_kpf.magic == OVERRIDE_MAGIC) {
|
||||||
@@ -178,7 +181,6 @@ cleanup:
|
|||||||
pthread_mutex_destroy(&spin_mutex);
|
pthread_mutex_destroy(&spin_mutex);
|
||||||
pthread_mutex_destroy(&found_pongo_mutex);
|
pthread_mutex_destroy(&found_pongo_mutex);
|
||||||
pthread_mutex_destroy(&ecid_dfu_wait_mutex);
|
pthread_mutex_destroy(&ecid_dfu_wait_mutex);
|
||||||
pthread_cond_destroy(&spin);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -25,7 +25,9 @@ void* pongo_helper(void* ptr) {
|
|||||||
pongo_thr_running = 1;
|
pongo_thr_running = 1;
|
||||||
pthread_cleanup_push(thr_cleanup, &pongo_thr_running);
|
pthread_cleanup_push(thr_cleanup, &pongo_thr_running);
|
||||||
wait_for_pongo();
|
wait_for_pongo();
|
||||||
palerain_block();
|
while (get_spin()) {
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
pthread_cleanup_pop(1);
|
pthread_cleanup_pop(1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -139,7 +141,7 @@ done:
|
|||||||
#ifdef USE_LIBUSB
|
#ifdef USE_LIBUSB
|
||||||
libusb_unref_device(arg->dev);
|
libusb_unref_device(arg->dev);
|
||||||
#endif
|
#endif
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +236,7 @@ void io_start(stuff_t *stuff)
|
|||||||
if(r != 0)
|
if(r != 0)
|
||||||
{
|
{
|
||||||
ERR("pthread_create: %s", strerror(r));
|
ERR("pthread_create: %s", strerror(r));
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pthread_join(stuff->th, NULL);
|
pthread_join(stuff->th, NULL);
|
||||||
@@ -246,14 +248,14 @@ void io_stop(stuff_t *stuff)
|
|||||||
if(r != 0)
|
if(r != 0)
|
||||||
{
|
{
|
||||||
ERR("pthread_cancel: %s", strerror(r));
|
ERR("pthread_cancel: %s", strerror(r));
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
r = pthread_join(stuff->th, NULL);
|
r = pthread_join(stuff->th, NULL);
|
||||||
if(r != 0)
|
if(r != 0)
|
||||||
{
|
{
|
||||||
ERR("pthread_join: %s", strerror(r));
|
ERR("pthread_join: %s", strerror(r));
|
||||||
palerain_unblock();
|
set_spin(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef USE_LIBUSB
|
#ifdef USE_LIBUSB
|
||||||
|
|||||||
+3
-1
@@ -245,7 +245,9 @@ int wait_for_pongo(void) {
|
|||||||
}
|
}
|
||||||
LostDevice(&stuff, lost);
|
LostDevice(&stuff, lost);
|
||||||
// CFRunLoopRun();
|
// CFRunLoopRun();
|
||||||
palerain_block();
|
while (get_spin()) {
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
CFRelease(cfdict);
|
CFRelease(cfdict);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user