diff options
Diffstat (limited to 'apps/plugin.c')
-rw-r--r-- | apps/plugin.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 0997b0a901..a2cb0dedcb 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -369,15 +369,15 @@ static const struct plugin_api rockbox_api = { | |||
369 | int plugin_load(const char* plugin, void* parameter) | 369 | int plugin_load(const char* plugin, void* parameter) |
370 | { | 370 | { |
371 | enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); | 371 | enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); |
372 | int rc; | 372 | int fd, rc; |
373 | #ifndef SIMULATOR | 373 | #ifndef SIMULATOR |
374 | struct plugin_header header; | 374 | struct plugin_header header; |
375 | ssize_t readsize; | 375 | ssize_t readsize; |
376 | #else | ||
377 | struct plugin_header *hdr; | ||
376 | #endif | 378 | #endif |
377 | int fd; | ||
378 | |||
379 | #ifdef HAVE_LCD_BITMAP | 379 | #ifdef HAVE_LCD_BITMAP |
380 | int xm,ym; | 380 | int xm, ym; |
381 | #endif | 381 | #endif |
382 | 382 | ||
383 | if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */ | 383 | if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */ |
@@ -397,18 +397,34 @@ int plugin_load(const char* plugin, void* parameter) | |||
397 | lcd_clear_display(); | 397 | lcd_clear_display(); |
398 | #endif | 398 | #endif |
399 | #ifdef SIMULATOR | 399 | #ifdef SIMULATOR |
400 | plugin_start = sim_plugin_load((char *)plugin, &fd); | 400 | hdr = sim_plugin_load((char *)plugin, &fd); |
401 | if(!plugin_start) | 401 | if (!fd) { |
402 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); | ||
402 | return -1; | 403 | return -1; |
404 | } | ||
405 | if (hdr == NULL | ||
406 | || hdr->magic != PLUGIN_MAGIC | ||
407 | || hdr->target_id != TARGET_ID | ||
408 | || hdr->entry_point == NULL) { | ||
409 | sim_plugin_close(fd); | ||
410 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL)); | ||
411 | return -1; | ||
412 | } | ||
413 | if (hdr->api_version > PLUGIN_API_VERSION | ||
414 | || hdr->api_version < PLUGIN_MIN_API_VERSION) { | ||
415 | sim_plugin_close(fd); | ||
416 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); | ||
417 | return -1; | ||
418 | } | ||
419 | plugin_start = hdr->entry_point; | ||
403 | #else | 420 | #else |
404 | fd = open(plugin, O_RDONLY); | 421 | fd = open(plugin, O_RDONLY); |
405 | if (fd < 0) { | 422 | if (fd < 0) { |
406 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); | 423 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); |
407 | return fd; | 424 | return fd; |
408 | } | 425 | } |
409 | |||
410 | readsize = read(fd, &header, sizeof(header)); | 426 | readsize = read(fd, &header, sizeof(header)); |
411 | close(fd); | 427 | close(fd); |
412 | /* Close for now. Less code than doing it in all error checks. | 428 | /* Close for now. Less code than doing it in all error checks. |
413 | * Would need to seek back anyway. */ | 429 | * Would need to seek back anyway. */ |
414 | 430 | ||
@@ -428,7 +444,6 @@ int plugin_load(const char* plugin, void* parameter) | |||
428 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); | 444 | gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); |
429 | return -1; | 445 | return -1; |
430 | } | 446 | } |
431 | |||
432 | /* zero out plugin buffer to ensure a properly zeroed bss area */ | 447 | /* zero out plugin buffer to ensure a properly zeroed bss area */ |
433 | memset(pluginbuf, 0, header.end_addr - pluginbuf); | 448 | memset(pluginbuf, 0, header.end_addr - pluginbuf); |
434 | 449 | ||
@@ -445,8 +460,8 @@ int plugin_load(const char* plugin, void* parameter) | |||
445 | gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); | 460 | gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); |
446 | return -1; | 461 | return -1; |
447 | } | 462 | } |
448 | plugin_start = header.entry_point; | ||
449 | plugin_size = header.end_addr - header.load_addr; | 463 | plugin_size = header.end_addr - header.load_addr; |
464 | plugin_start = header.entry_point; | ||
450 | #endif | 465 | #endif |
451 | 466 | ||
452 | plugin_loaded = true; | 467 | plugin_loaded = true; |
@@ -463,11 +478,15 @@ int plugin_load(const char* plugin, void* parameter) | |||
463 | #else /* LCD_DEPTH == 1 */ | 478 | #else /* LCD_DEPTH == 1 */ |
464 | lcd_set_drawmode(DRMODE_SOLID); | 479 | lcd_set_drawmode(DRMODE_SOLID); |
465 | #endif /* LCD_DEPTH */ | 480 | #endif /* LCD_DEPTH */ |
481 | /* restore margins */ | ||
482 | lcd_setmargins(xm,ym); | ||
466 | #endif /* HAVE_LCD_BITMAP */ | 483 | #endif /* HAVE_LCD_BITMAP */ |
467 | 484 | ||
468 | if (pfn_tsr_exit == NULL) | 485 | if (pfn_tsr_exit == NULL) |
469 | plugin_loaded = false; | 486 | plugin_loaded = false; |
470 | 487 | ||
488 | sim_plugin_close(fd); | ||
489 | |||
471 | switch (rc) { | 490 | switch (rc) { |
472 | case PLUGIN_OK: | 491 | case PLUGIN_OK: |
473 | break; | 492 | break; |
@@ -480,13 +499,6 @@ int plugin_load(const char* plugin, void* parameter) | |||
480 | break; | 499 | break; |
481 | } | 500 | } |
482 | 501 | ||
483 | sim_plugin_close(fd); | ||
484 | |||
485 | #ifdef HAVE_LCD_BITMAP | ||
486 | /* restore margins */ | ||
487 | lcd_setmargins(xm,ym); | ||
488 | #endif | ||
489 | |||
490 | return PLUGIN_OK; | 502 | return PLUGIN_OK; |
491 | } | 503 | } |
492 | 504 | ||