1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
diff --git a/apps/plugin.h b/apps/plugin.h
index 624b703..596bf12 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -912,14 +912,14 @@ extern unsigned char plugin_end_addr[];
         const struct plugin_header __header \
         __attribute__ ((section (".header")))= { \
         PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
-        plugin_start_addr, plugin_end_addr, plugin_start, &rb };
+        plugin_start_addr, plugin_end_addr, plugin__start, &rb };
 #else /* PLATFORM_HOSTED */
 #define PLUGIN_HEADER \
         const struct plugin_api *rb DATA_ATTR; \
         const struct plugin_header __header \
         __attribute__((visibility("default"))) = { \
         PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
-        NULL, NULL, plugin_start, &rb };
+        NULL, NULL, plugin__start, &rb };
 #endif /* CONFIG_PLATFORM */

 #ifdef PLUGIN_USE_IRAM
@@ -954,7 +954,7 @@ void plugin_tsr(bool (*exit_callback)(bool reenter));

 /* defined by the plugin */
 extern const struct plugin_api *rb;
-enum plugin_status plugin_start(const void* parameter)
+enum plugin_status plugin__start(const void* parameter)
     NO_PROF_ATTR;

 #endif /* __PCTOOL__ */
diff --git a/apps/plugins/alarmclock.c b/apps/plugins/alarmclock.c
index a22a2f2..3ccb0c3 100644
--- a/apps/plugins/alarmclock.c
+++ b/apps/plugins/alarmclock.c
@@ -22,7 +22,7 @@
 #include "plugin.h"
 #include "lib/pluginlib_actions.h"

-PLUGIN_HEADER
+

 const struct button_mapping *plugin_contexts[] = { pla_main_ctx };

diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c
index 9357b2e..f6b2368 100644
--- a/apps/plugins/alpine_cdc.c
+++ b/apps/plugins/alpine_cdc.c
@@ -36,7 +36,7 @@
 /* Only build for (correct) target */
 #if CONFIG_CPU==SH7034 && !(CONFIG_STORAGE & STORAGE_MMC)

-PLUGIN_HEADER
+

 #ifdef HAVE_LCD_CHARCELLS /* player model */
 #define LINES    2
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index e6efd38..bb0e4f5 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -22,7 +22,7 @@

 #include "version.h"
 #include "plugin.h"
-PLUGIN_HEADER
+

 #define BATTERY_LOG "/battery_bench.txt"
 #define BUF_SIZE 16000
diff --git a/apps/plugins/beatbox/beatbox.c b/apps/plugins/beatbox/beatbox.c
index a51f738..9cb7dd4 100644
--- a/apps/plugins/beatbox/beatbox.c
+++ b/apps/plugins/beatbox/beatbox.c
@@ -26,7 +26,7 @@
 #include "midi/sequencer.h"
 #include "midi/midifile.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 /* variable button definitions */
diff --git a/apps/plugins/bench_mem_jpeg.c b/apps/plugins/bench_mem_jpeg.c
index 5169286..4e24f2a 100644
--- a/apps/plugins/bench_mem_jpeg.c
+++ b/apps/plugins/bench_mem_jpeg.c
@@ -23,7 +23,7 @@

 #include "plugin.h"
 #include "lib/jpeg_mem.h"
-PLUGIN_HEADER
+

 /* a null output plugin to save memory and better isolate decode cost */
 static unsigned int get_size_null(struct bitmap *bm)
diff --git a/apps/plugins/bench_scaler.c b/apps/plugins/bench_scaler.c
index 246271d..5db2987 100644
--- a/apps/plugins/bench_scaler.c
+++ b/apps/plugins/bench_scaler.c
@@ -23,7 +23,7 @@

 #include "plugin.h"
 #include "lib/jpeg_mem.h"
-PLUGIN_HEADER
+

 static unsigned char output;
 static int output_y = 0;
diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c
index 7b3dbef..8b28b81 100644
--- a/apps/plugins/blackjack.c
+++ b/apps/plugins/blackjack.c
@@ -26,7 +26,7 @@
 #include "lib/highscore.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* save files */
 #define SCORE_FILE PLUGIN_GAMES_DIR "/blackjack.score"
diff --git a/apps/plugins/bounce.c b/apps/plugins/bounce.c
index f193818..1ee5b1e 100644
--- a/apps/plugins/bounce.c
+++ b/apps/plugins/bounce.c
@@ -22,7 +22,7 @@
 #include "time.h"
 #include "lib/fixedpoint.h"

-PLUGIN_HEADER
+

 #define SS_TITLE       "Bouncer"

diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c
index 98de3d4..50ceaa7 100644
--- a/apps/plugins/brickmania.c
+++ b/apps/plugins/brickmania.c
@@ -41,7 +41,7 @@
 #include "pluginbitmaps/brickmania_break.h"
 #endif

-PLUGIN_HEADER
+


 /*
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c
index f169a2e..320fd3e 100644
--- a/apps/plugins/bubbles.c
+++ b/apps/plugins/bubbles.c
@@ -31,8 +31,6 @@
 #include "lib/playback_control.h"
 #include "lib/highscore.h"

-PLUGIN_HEADER
-
 /* files */
 #define SCORE_FILE PLUGIN_GAMES_DIR "/bubbles.score"
 #define SAVE_FILE  PLUGIN_GAMES_DIR "/bubbles.save"
diff --git a/apps/plugins/calculator.c b/apps/plugins/calculator.c
index 95b35e9..8068b9c 100644
--- a/apps/plugins/calculator.c
+++ b/apps/plugins/calculator.c
@@ -78,7 +78,7 @@ F3: equal to "="
 #ifdef HAVE_LCD_BITMAP
 #include "math.h"

-PLUGIN_HEADER
+


 #define M_TWOPI         (M_PI * 2.0)
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c
index 13abdfc..32d4501 100644
--- a/apps/plugins/calendar.c
+++ b/apps/plugins/calendar.c
@@ -25,7 +25,7 @@
 #include "lib/playback_control.h"
 #include "lib/configfile.h"

-PLUGIN_HEADER
+

 #if CONFIG_KEYPAD == RECORDER_PAD
 #define CALENDAR_QUIT       BUTTON_OFF
diff --git a/apps/plugins/chessbox.c b/apps/plugins/chessbox.c
index a6db7ba..14d2936 100644
--- a/apps/plugins/chessbox.c
+++ b/apps/plugins/chessbox.c
@@ -24,7 +24,7 @@

 #include "lib/overlay.h"

-PLUGIN_HEADER
+

 /* this is the plugin entry point */
 enum plugin_status plugin_start(const void* parameter)
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c
index 45f052d..4e298a8 100644
--- a/apps/plugins/chessbox/chessbox.c
+++ b/apps/plugins/chessbox/chessbox.c
@@ -49,7 +49,7 @@ struct cb_command {
 extern const fb_data chessbox_pieces[];


-PLUGIN_HEADER
+

 /* Tile size defined by the assigned bitmap */
 #include "pluginbitmaps/chessbox_pieces.h"
diff --git a/apps/plugins/chessclock.c b/apps/plugins/chessclock.c
index 3afa705..0ddfcb5 100644
--- a/apps/plugins/chessclock.c
+++ b/apps/plugins/chessclock.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c
index f60bdb3..cca6229 100644
--- a/apps/plugins/chip8.c
+++ b/apps/plugins/chip8.c
@@ -21,7 +21,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 #define EXTERN static
 #define STATIC static
diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c
index 67cb9ee..86f1bfb 100644
--- a/apps/plugins/chopper.c
+++ b/apps/plugins/chopper.c
@@ -26,7 +26,7 @@
 #include "lib/helper.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /*
 Still To do:
diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c
index 0735656..0bdf693 100644
--- a/apps/plugins/clix.c
+++ b/apps/plugins/clix.c
@@ -22,7 +22,7 @@
 #include "lib/playback_control.h"
 #include "lib/display_text.h"

-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == SANSA_E200_PAD)
 #define CLIX_BUTTON_QUIT        BUTTON_POWER
diff --git a/apps/plugins/clock/clock.c b/apps/plugins/clock/clock.c
index f06f3e1..8a1a55e 100644
--- a/apps/plugins/clock/clock.c
+++ b/apps/plugins/clock/clock.c
@@ -22,6 +22,7 @@
 #include "plugin.h"
 #include "time.h"
 #include "lib/pluginlib_actions.h"
+#include "lib/pluginlib_exit.h"
 #include "lib/xlcd.h"

 #include "clock.h"
@@ -30,7 +31,7 @@
 #include "clock_menu.h"
 #include "clock_settings.h"

-PLUGIN_HEADER
+

 /* Keymaps */
 const struct button_mapping* plugin_contexts[]={
@@ -56,9 +57,8 @@ const struct button_mapping* plugin_contexts[]={
 /**************************
  * Cleanup on plugin return
  *************************/
-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void)parameter;
     clock_draw_restore_colors();
     if(clock_settings.general.save_settings == 1)
         save_settings();
@@ -115,6 +115,7 @@ enum plugin_status plugin_start(const void* parameter){
     struct counter counter;
     bool exit_clock = false;
     (void)parameter;
+    atexit(cleanup);

 #if LCD_DEPTH > 1
     rb->lcd_set_backdrop(NULL);
@@ -174,9 +175,7 @@ enum plugin_status plugin_start(const void* parameter){
                 exit_clock=main_menu();
                 break;
             default:
-                if(rb->default_event_handler_ex(button, cleanup, NULL)
-                   == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(button);
                 if(time.second != last_second){
                     last_second=time.second;
                     redraw=true;
@@ -193,6 +192,5 @@ enum plugin_status plugin_start(const void* parameter){
         }
     }

-    cleanup(NULL);
     return PLUGIN_OK;
 }
diff --git a/apps/plugins/codebuster.c b/apps/plugins/codebuster.c
index 810bd0c..1169f26 100644
--- a/apps/plugins/codebuster.c
+++ b/apps/plugins/codebuster.c
@@ -24,7 +24,7 @@
 #include "lib/playback_control.h"
 #include "lib/pluginlib_actions.h"

-PLUGIN_HEADER
+

 /* Limits */
 #define MAX_PIECES_COUNT 5
diff --git a/apps/plugins/credits.c b/apps/plugins/credits.c
index 0251849..a05b44c 100644
--- a/apps/plugins/credits.c
+++ b/apps/plugins/credits.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+

 static const char* const credits[] = {
 #include "credits.raw" /* generated list of names from docs/CREDITS */
diff --git a/apps/plugins/crypt_firmware.c b/apps/plugins/crypt_firmware.c
index 051a3d1..f9bdd4d 100644
--- a/apps/plugins/crypt_firmware.c
+++ b/apps/plugins/crypt_firmware.c
@@ -37,7 +37,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+

 static void aes_encrypt(void* data, uint32_t size)
 {
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c
index 2b1e00d..7dec822 100644
--- a/apps/plugins/cube.c
+++ b/apps/plugins/cube.c
@@ -22,6 +22,7 @@
 ***************************************************************************/
 #include "plugin.h"
 #include "lib/playergfx.h"
+#include "lib/pluginlib_exit.h"
 #if LCD_DEPTH > 1
 #include "lib/mylcd.h" /* MYLCD_CFG_RB_XLCD or MYLCD_CFG_PGFX */
 #include "lib/grey.h"
@@ -32,8 +33,6 @@
 #include "lib/xlcd.h"
 #include "lib/fixedpoint.h"

-PLUGIN_HEADER
-
 /* Loops that the values are displayed */
 #define DISP_TIME 30

@@ -611,10 +610,8 @@ static void cube_draw(void)
     }
 }

-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void)parameter;
-
 #ifdef USEGSLIB
     grey_release();
 #elif defined HAVE_LCD_CHARCELLS
@@ -638,7 +635,7 @@ enum plugin_status plugin_start(const void* parameter)
     bool highspeed = false;
     bool paused = false;
     bool redraw = true;
-    bool exit = false;
+    bool quit = false;

     (void)(parameter);

@@ -651,6 +648,7 @@ enum plugin_status plugin_start(const void* parameter)
         rb->splash(HZ, "Couldn't init greyscale display");
         return PLUGIN_ERROR;
     }
+
     /* init lcd_ function pointers */
     lcdfuncs.update =        rb->lcd_update;
     lcdfuncs.clear_display = rb->lcd_clear_display;
@@ -673,7 +671,8 @@ enum plugin_status plugin_start(const void* parameter)
     pgfx_display(0, 0);
 #endif

-    while(!exit)
+    atexit(cleanup);
+    while(!quit)
     {
         if (redraw)
         {
@@ -830,24 +829,17 @@ enum plugin_status plugin_start(const void* parameter)
             case CUBE_RC_QUIT:
 #endif
             case CUBE_QUIT:
-                exit = true;
+                exit(EXIT_SUCCESS);
                 break;

             default:
-                if (rb->default_event_handler_ex(button, cleanup, NULL)
-                    == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(button);
                 break;
         }
         if (button != BUTTON_NONE)
             lastbutton = button;
     }

-#ifdef USEGSLIB
-    grey_release();
-#elif defined(HAVE_LCD_CHARCELLS)
-    pgfx_release();
-#endif
     return PLUGIN_OK;
 }

diff --git a/apps/plugins/demystify.c b/apps/plugins/demystify.c
index 468f180..6a8f1eb 100644
--- a/apps/plugins/demystify.c
+++ b/apps/plugins/demystify.c
@@ -22,11 +22,12 @@
 ****************************************************************************/

 #include "plugin.h"
+#include "lib/pluginlib_exit.h"

 #ifdef HAVE_LCD_BITMAP
 #include "lib/pluginlib_actions.h"
 #include "lib/helper.h"
-PLUGIN_HEADER
+

 #define DEFAULT_WAIT_TIME 3
 #define DEFAULT_NB_POLYGONS 7
@@ -259,10 +260,8 @@ void polygons_draw(struct polygon_fifo * polygons, struct screen * display)
     }
 }

-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void)parameter;
-
     backlight_use_settings();
 #ifdef HAVE_REMOTE_LCD
     remote_backlight_use_settings();
@@ -394,7 +393,6 @@ int plugin_main(void)
         switch(action)
         {
             case DEMYSTIFY_QUIT:
-                cleanup(NULL);
                 return PLUGIN_OK;

             case DEMYSTIFY_ADD_POLYGON:
@@ -421,9 +419,7 @@ int plugin_main(void)
                 break;

             default:
-                if (rb->default_event_handler_ex(action, cleanup, NULL)
-                    == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(action);
                 break;
         }
     }
@@ -436,6 +432,8 @@ enum plugin_status plugin_start(const void* parameter)
     int ret;

     (void)parameter;
+    atexit(cleanup);
+
 #if LCD_DEPTH > 1
     rb->lcd_set_backdrop(NULL);
 #endif
diff --git a/apps/plugins/dice.c b/apps/plugins/dice.c
index 7bd5112..7acb2e7 100644
--- a/apps/plugins/dice.c
+++ b/apps/plugins/dice.c
@@ -45,7 +45,7 @@ struct dices
 };

 #define PRINT_BUFFER_LENGTH MAX_DICES*4
-PLUGIN_HEADER
+

 static struct dices dice;
 static int sides_index;
diff --git a/apps/plugins/dict.c b/apps/plugins/dict.c
index 13fe8e3..a9c4817 100644
--- a/apps/plugins/dict.c
+++ b/apps/plugins/dict.c
@@ -22,7 +22,7 @@
 #include "plugin.h"
 #include "lib/simple_viewer.h"

-PLUGIN_HEADER
+

 #define MIN_DESC_BUF_SIZE 0x400 /* arbitrary minimum size for description */

diff --git a/apps/plugins/disktidy.c b/apps/plugins/disktidy.c
index 8d8515e..d83ecf4 100644
--- a/apps/plugins/disktidy.c
+++ b/apps/plugins/disktidy.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "errno.h"

-PLUGIN_HEADER
+

 /* function return values */
 enum tidy_return
diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c
index 0422128..324cb24 100644
--- a/apps/plugins/doom/rockdoom.c
+++ b/apps/plugins/doom/rockdoom.c
@@ -41,7 +41,7 @@
 #include "st_stuff.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 extern boolean timingdemo, singledemo, demoplayback, fastdemo; // killough
diff --git a/apps/plugins/euroconverter.c b/apps/plugins/euroconverter.c
index f85ee79..24cebe6 100644
--- a/apps/plugins/euroconverter.c
+++ b/apps/plugins/euroconverter.c
@@ -45,7 +45,7 @@ To do:
 - The Irish currency needs 6 digits after the . to have sufficient precision on big number
 */

-PLUGIN_HEADER
+

 /* Name and path of the config file*/
 static const char cfg_filename[] =  "euroconverter.cfg";
@@ -387,10 +387,8 @@ static int euro_menu(void)


 /* Call when the program end */
-static void euro_exit(void *parameter)
+static void euro_exit(void)
 {
-    (void)parameter;
-    
     //Restore the old pattern (i don't find another way to do this. An idea?)
     rb->lcd_unlock_pattern(heuro);
     rb->lcd_unlock_pattern(hhome);
@@ -411,6 +409,7 @@ enum plugin_status plugin_start(const void* parameter)
     /* if you don't use the parameter, you can do like
        this to avoid the compiler warning about it */
     (void)parameter;
+    atexit(euro_exit);

     /*Get the pattern handle*/
     heuro=rb->lcd_get_locked_pattern();
@@ -587,9 +586,7 @@ enum plugin_status plugin_start(const void* parameter)
                 break;

             default:
-                if (rb->default_event_handler_ex(button, euro_exit, NULL)
-                     == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(button);
                 break;
         }
         /*Display*/
@@ -599,7 +596,6 @@ enum plugin_status plugin_start(const void* parameter)
             e=mydiv(h,currency[country]);
         display(e,h,pos);
     }
-    euro_exit(NULL);
     return PLUGIN_OK;
 }

diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c
index e352c1c..a972419 100644
--- a/apps/plugins/fft/fft.c
+++ b/apps/plugins/fft/fft.c
@@ -29,7 +29,7 @@
 #endif
 #include "lib/mylcd.h"

-PLUGIN_HEADER
+

 #ifndef HAVE_LCD_COLOR
 GREY_INFO_STRUCT
diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c
index e1362dc..268a934 100644
--- a/apps/plugins/fire.c
+++ b/apps/plugins/fire.c
@@ -41,8 +41,6 @@
 #define FIRE_XPOS 0
 #endif

-PLUGIN_HEADER
-
 #ifndef HAVE_LCD_COLOR
 GREY_INFO_STRUCT
         static unsigned char draw_buffer[FIRE_WIDTH];
diff --git a/apps/plugins/fireworks.c b/apps/plugins/fireworks.c
index 1ad5f9a..1954f19 100644
--- a/apps/plugins/fireworks.c
+++ b/apps/plugins/fireworks.c
@@ -22,7 +22,7 @@
 #include "lib/helper.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /***
  * FIREWORKS.C by ZAKK ROBERTS
diff --git a/apps/plugins/firmware_flash.c b/apps/plugins/firmware_flash.c
index 317bc92..02c4098 100644
--- a/apps/plugins/firmware_flash.c
+++ b/apps/plugins/firmware_flash.c
@@ -77,7 +77,7 @@
 #error this platform is not (yet) flashable
 #endif

-PLUGIN_HEADER
+

 #if CONFIG_KEYPAD == ONDIO_PAD /* limited keypad */
 #define KEY1 BUTTON_LEFT
diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c
index d4c5702..44ad011 100644
--- a/apps/plugins/flipit.c
+++ b/apps/plugins/flipit.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/fractals/fractal.c b/apps/plugins/fractals/fractal.c
index 971ae50..179bc3e 100644
--- a/apps/plugins/fractals/fractal.c
+++ b/apps/plugins/fractals/fractal.c
@@ -29,6 +29,7 @@
 #include "fractal_rect.h"
 #include "fractal_sets.h"
 #include "mandelbrot_set.h"
+#include "lib/pluginlib_exit.h"

 #ifdef USEGSLIB
 GREY_INFO_STRUCT
@@ -41,7 +42,7 @@ static size_t gbuf_size = 0;
 #define REDRAW_FULL         2
 #define REDRAW_FULL_OVERLAY 3

-PLUGIN_HEADER
+

 /* returns 1 if a button has been pressed, 0 otherwise */
 static int button_yield(void *ctx)
@@ -85,9 +86,8 @@ static int button_yield(void *ctx)
     }
 }

-static void cleanup(void *parameter)
+static void cleanup(void)
 {
-    (void)parameter;
 #ifdef USEGSLIB
     grey_release();
 #endif
@@ -109,11 +109,13 @@ enum plugin_status plugin_start(const void* parameter)
     if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL))
     {
         rb->splash(HZ, "Couldn't init greyscale display");
-        return 0;
+        return PLUGIN_ERROR;
     }
     grey_show(true); /* switch on greyscale overlay */
 #endif

+    /* release greylib on exit */
+    atexit(cleanup);
 #if LCD_DEPTH > 1
     rb->lcd_set_backdrop(NULL);
 #endif
@@ -161,9 +163,6 @@ enum plugin_status plugin_start(const void* parameter)
         case FRACTAL_RC_QUIT:
 #endif
         case FRACTAL_QUIT:
-#ifdef USEGSLIB
-            grey_release();
-#endif
             return PLUGIN_OK;

         case FRACTAL_ZOOM_OUT:
@@ -246,18 +245,13 @@ enum plugin_status plugin_start(const void* parameter)
             break;

         default:
-            if (rb->default_event_handler_ex(button, cleanup, NULL)
-                == SYS_USB_CONNECTED)
-                return PLUGIN_USB_CONNECTED;
+            exit_on_usb(button);
             break;
         }

         if (button != BUTTON_NONE)
             lastbutton = button;
     }
-#ifdef USEGSLIB
-    grey_release();
-#endif
     return PLUGIN_OK;
 }

diff --git a/apps/plugins/frotz/frotz.c b/apps/plugins/frotz/frotz.c
index aff9100..23da650 100644
--- a/apps/plugins/frotz/frotz.c
+++ b/apps/plugins/frotz/frotz.c
@@ -23,7 +23,7 @@
 #include "lib/pluginlib_exit.h"
 #include "lib/pluginlib_actions.h"

-PLUGIN_HEADER
+

 extern int frotz_main(void);
 extern bool hot_key_quit(void);
@@ -41,7 +41,7 @@ enum plugin_status plugin_start(const void* parameter)
     int i;
     char* ext;

-    PLUGINLIB_EXIT_INIT_ATEXIT(atexit_cleanup);
+    atexit(atexit_cleanup);

     if (!parameter)
         return PLUGIN_ERROR;
diff --git a/apps/plugins/goban.c b/apps/plugins/goban.c
index 7bb6744..1a12120 100644
--- a/apps/plugins/goban.c
+++ b/apps/plugins/goban.c
@@ -24,7 +24,7 @@

 #include "lib/overlay.h"

-PLUGIN_HEADER
+

 enum plugin_status plugin_start(const void* parameter)
 {
diff --git a/apps/plugins/goban/goban.c b/apps/plugins/goban/goban.c
index 4e20e71..b2306c0 100644
--- a/apps/plugins/goban/goban.c
+++ b/apps/plugins/goban/goban.c
@@ -23,7 +23,7 @@
 #include "lib/playback_control.h"
 #include "lib/configfile.h"

-PLUGIN_HEADER
+

 #include "goban.h"
 #include "game.h"
diff --git a/apps/plugins/greyscale.c b/apps/plugins/greyscale.c
index 73dd98b..3325443 100644
--- a/apps/plugins/greyscale.c
+++ b/apps/plugins/greyscale.c
@@ -27,7 +27,7 @@
 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
 #include "lib/grey.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
@@ -316,9 +316,7 @@ int main(void)

         button = rb->button_get(true);

-        if (rb->default_event_handler_ex(button, cleanup, NULL) 
-            == SYS_USB_CONNECTED)
-            return PLUGIN_USB_CONNECTED;
+        exit_on_usb(button);

         if (button & GREYSCALE_SHIFT)
         {
@@ -369,8 +367,6 @@ int main(void)
             case GREYSCALE_RC_OFF:
 #endif
             case GREYSCALE_OFF:
-
-                cleanup(NULL);
                 return PLUGIN_OK;
         }
     }
@@ -382,6 +378,7 @@ enum plugin_status plugin_start(const void* parameter)
 {
     (void)parameter;

+    atexit(cleanup);
     return main();
 }

diff --git a/apps/plugins/helloworld.c b/apps/plugins/helloworld.c
index e582eb7..f1093f0 100644
--- a/apps/plugins/helloworld.c
+++ b/apps/plugins/helloworld.c
@@ -24,7 +24,7 @@

 /* This macros must always be included. Should be placed at the top by
    convention, although the actual position doesn't matter */
-PLUGIN_HEADER
+

 /* this is the plugin entry point */
 enum plugin_status plugin_start(const void* parameter)
diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c
index 0fd25e7..e581407 100644
--- a/apps/plugins/imageviewer/imageviewer.c
+++ b/apps/plugins/imageviewer/imageviewer.c
@@ -25,7 +25,7 @@
 #include <lib/configfile.h>
 #include "imageviewer.h"

-PLUGIN_HEADER
+

 #ifdef USEGSLIB
 GREY_INFO_STRUCT
diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c
index 851487c..ea4a0a2 100644
--- a/apps/plugins/invadrox.c
+++ b/apps/plugins/invadrox.c
@@ -61,7 +61,7 @@
 #define FIRE_WIDTH            BMPWIDTH_invadrox_fire
 #define FIRE_HEIGHT           BMPHEIGHT_invadrox_fire

-PLUGIN_HEADER
+

 /* Original graphics is only 1bpp so it should be portable
  * to most targets. But for now, only support the simple ones.
diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c
index 24542a9..a1ce22c 100644
--- a/apps/plugins/iriver_flash.c
+++ b/apps/plugins/iriver_flash.c
@@ -35,7 +35,7 @@ ssize_t audiobuf_size;

 #ifdef PLATFORM_ID

-PLUGIN_HEADER
+

 #if CONFIG_KEYPAD == IRIVER_H100_PAD
 #define KEY1 BUTTON_OFF
diff --git a/apps/plugins/iriverify.c b/apps/plugins/iriverify.c
index 4e8ca5b..1109cde 100644
--- a/apps/plugins/iriverify.c
+++ b/apps/plugins/iriverify.c
@@ -25,7 +25,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 ssize_t buf_size;
 static char *filename;
diff --git a/apps/plugins/jackpot.c b/apps/plugins/jackpot.c
index 56c2910..abf1cf8 100644
--- a/apps/plugins/jackpot.c
+++ b/apps/plugins/jackpot.c
@@ -22,8 +22,9 @@
 #include "plugin.h"
 #include "lib/pluginlib_actions.h"
 #include "lib/picture.h"
+#include "lib/pluginlib_exit.h"
+

-PLUGIN_HEADER

 const struct button_mapping* plugin_contexts[]={pla_main_ctx};
 #define NB_PICTURES 9
@@ -109,9 +110,8 @@ void patterns_deinit(struct screen* display)
 #endif /* HAVE_LCD_CHARCELLS */

 /*Call when the program exit*/
-void jackpot_exit(void *parameter)
+void jackpot_exit(void)
 {
-    (void)parameter;
 #ifdef HAVE_LCD_CHARCELLS
     patterns_deinit(rb->screens[SCREEN_MAIN]);
 #endif /* HAVE_LCD_CHARCELLS */
@@ -298,6 +298,7 @@ enum plugin_status plugin_start(const void* parameter)
     int action, i;
     struct jackpot game;
     (void)parameter;
+    atexit(jackpot_exit);
     rb->srand(*rb->current_tick);
 #ifdef HAVE_LCD_CHARCELLS
     patterns_init(rb->screens[SCREEN_MAIN]);
@@ -323,12 +324,9 @@ enum plugin_status plugin_start(const void* parameter)
                 break;

             default:
-                if (rb->default_event_handler_ex(action, jackpot_exit, NULL)
-                    == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(action);
                 break;
         }
     }
-    jackpot_exit(NULL);
     return PLUGIN_OK;
 }
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c
index c2340aa..fdf4ff7 100644
--- a/apps/plugins/jewels.c
+++ b/apps/plugins/jewels.c
@@ -29,7 +29,7 @@

 #ifdef HAVE_LCD_BITMAP

-PLUGIN_HEADER
+

 /* button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/keybox.c b/apps/plugins/keybox.c
index a241e40..8ac4064 100644
--- a/apps/plugins/keybox.c
+++ b/apps/plugins/keybox.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/playback_control.h"
 #include "lib/md5.h"
-PLUGIN_HEADER
+

 #define KEYBOX_FILE PLUGIN_APPS_DIR "/keybox.dat"
 #define BLOCK_SIZE 8
diff --git a/apps/plugins/lamp.c b/apps/plugins/lamp.c
index 8c2dff5..0074933 100644
--- a/apps/plugins/lamp.c
+++ b/apps/plugins/lamp.c
@@ -25,7 +25,7 @@
 #include "plugin.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+

 /* variable button definitions - only targets with a colour display */
 #if defined(HAVE_LCD_COLOR)
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index fa12f94..9b8b214 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -2,7 +2,6 @@ gcc-support.c
 pluginlib_actions.c
 helper.c
 md5.c
-pluginlib_exit.c
 jhash.c
 configfile.c
 fixedpoint.c
diff --git a/apps/plugins/lib/pluginlib_exit.h b/apps/plugins/lib/pluginlib_exit.h
index 00cbc8d..4cbafc9 100644
--- a/apps/plugins/lib/pluginlib_exit.h
+++ b/apps/plugins/lib/pluginlib_exit.h
@@ -22,35 +22,22 @@
 #ifndef __PLUGINLIB_EXIT_H__
 #define __PLUGINLIB_EXIT_H__

-#include "config.h"
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
-#include "../../codecs/lib/setjmp.h"
-#else
-#include <setjmp.h>
-#endif
+/* these are actually implemented in plugin_crt0.c which all plugins link */

-#define _PLUGINLIB_EXIT_INIT(atexit) switch(setjmp(__exit_env))   \
-                                     {                            \
-                                         case 1:                  \
-                                             atexit               \
-                                             return PLUGIN_OK;    \
-                                         case 2:                  \
-                                             atexit               \
-                                             return PLUGIN_ERROR; \
-                                         case 0:                  \
-                                         default:                 \
-                                             break;               \
-                                     }
+extern int atexit(void (*func)(void));
+extern void exit(int status);
+/* these don't call the exit handlers */
+extern void _exit(int status);
+#define _Exit _exit

-/* Either PLUGINLIB_EXIT_INIT or PLUGINLIB_EXIT_INIT_ATEXIT needs to be placed
- * as the first line in plugin_start. The _ATEXIT version will call the named
- * no-argument function when exit() is called before exiting the plugin, to
- * allow for cleanup.
- */
-#define PLUGINLIB_EXIT_INIT _PLUGINLIB_EXIT_INIT()
-#define PLUGINLIB_EXIT_INIT_ATEXIT(atexit) _PLUGINLIB_EXIT_INIT(atexit();)

-extern jmp_buf __exit_env;
-#define exit(status) longjmp(__exit_env, status != 0 ? 2 : 1)
+/**
+ * helper function to handle USB connected events coming from
+ * button_get()
+ *
+ * it will exit the plugin if usb is detected, but it will call the atexit func
+ * before actually showing the usb screen
+ */
+extern void exit_on_usb(int button);

 #endif /*  __PLUGINLIB_EXIT_H__ */
diff --git a/apps/plugins/logo.c b/apps/plugins/logo.c
index db69284..43a7c3f 100644
--- a/apps/plugins/logo.c
+++ b/apps/plugins/logo.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/playergfx.h"

-PLUGIN_HEADER
+

 #ifdef HAVE_LCD_BITMAP
 #define DISPLAY_WIDTH LCD_WIDTH
diff --git a/apps/plugins/lrcplayer.c b/apps/plugins/lrcplayer.c
index 43f3b8e..9f43849 100644
--- a/apps/plugins/lrcplayer.c
+++ b/apps/plugins/lrcplayer.c
@@ -24,7 +24,7 @@
 #include "lib/helper.h"
 #include <ctype.h>

-PLUGIN_HEADER
+

 #define MAX_LINE_LEN    256
 #define LRC_BUFFER_SIZE 0x3000 /* 12 kiB */
diff --git a/apps/plugins/lua/rocklua.c b/apps/plugins/lua/rocklua.c
index b92c274..00bfd8e 100644
--- a/apps/plugins/lua/rocklua.c
+++ b/apps/plugins/lua/rocklua.c
@@ -20,7 +20,6 @@
  ****************************************************************************/

 #include "plugin.h"
-#include "lib/pluginlib_exit.h"
 #include "lua.h"
 #include "lauxlib.h"
 #include "lualib.h"
@@ -28,7 +27,7 @@
 #include "rockmalloc.h"
 #include "luadir.h"

-PLUGIN_HEADER
+

 static const luaL_Reg lualibs[] = {
   {"",              luaopen_base},
@@ -148,8 +147,6 @@ enum plugin_status plugin_start(const void* parameter)
     const char* filename;
     int status;

-    PLUGINLIB_EXIT_INIT
-
     if (parameter == NULL)
     {
         rb->splash(HZ, "Play a .lua file!");
diff --git a/apps/plugins/matrix.c b/apps/plugins/matrix.c
index 5a13b3a..d342969 100644
--- a/apps/plugins/matrix.c
+++ b/apps/plugins/matrix.c
@@ -34,7 +34,7 @@


 #include "plugin.h"
-PLUGIN_HEADER
+

 /* Images */
 #include "pluginbitmaps/matrix_bold.h"
diff --git a/apps/plugins/maze.c b/apps/plugins/maze.c
index 465dfa9..231b602 100644
--- a/apps/plugins/maze.c
+++ b/apps/plugins/maze.c
@@ -33,7 +33,7 @@
 #include "plugin.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+

 /* key assignments */

diff --git a/apps/plugins/mazezam.c b/apps/plugins/mazezam.c
index f4b76df..bb93825 100644
--- a/apps/plugins/mazezam.c
+++ b/apps/plugins/mazezam.c
@@ -25,7 +25,7 @@
 #include "lib/playback_control.h"

 /* Include standard plugin macro */
-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == IPOD_3G_PAD)
 #   define MAZEZAM_MENU    BUTTON_MENU
diff --git a/apps/plugins/md5sum.c b/apps/plugins/md5sum.c
index 9dd8f5a..fe1c65e 100644
--- a/apps/plugins/md5sum.c
+++ b/apps/plugins/md5sum.c
@@ -22,7 +22,7 @@
 #include "plugin.h"
 #include "lib/md5.h"

-PLUGIN_HEADER
+

 #define BUFFERSIZE 16384

diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c
index 37a7329..52d1a2b 100644
--- a/apps/plugins/metronome.c
+++ b/apps/plugins/metronome.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/pluginlib_actions.h"

-PLUGIN_HEADER
+

 #if CONFIG_CODEC != SWCODEC
 /* tick sound from a metronome */
@@ -846,13 +846,14 @@ void timer_callback(void)
     }
 }

-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void)parameter;
-
     rb->timer_unregister();
     MET_PLAY_STOP; /* stop audio ISR */
     rb->led(0);
+#if CONFIG_CODEC == SWCODEC
+    rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
+#endif
 }

 void tap(void)
@@ -885,9 +886,9 @@ enum plugin_status plugin_start(const void* parameter)
 {
     int button;
     static int last_button = BUTTON_NONE;
-    enum plugin_status status;

     (void)parameter;
+    atexit(cleanup);

     if (MET_IS_PLAYING)
         MET_PLAY_STOP; /* stop audio IS */
@@ -927,9 +928,7 @@ enum plugin_status plugin_start(const void* parameter)

             case METRONOME_QUIT:
                 /* get out of here */
-                cleanup(NULL);
-                status = PLUGIN_OK;
-                goto metronome_exit;
+                return PLUGIN_OK;

             case METRONOME_PAUSE:
                 if(!sound_paused)
@@ -981,12 +980,7 @@ enum plugin_status plugin_start(const void* parameter)
 #endif

             default:
-                if (rb->default_event_handler_ex(button, cleanup, NULL)
-                    == SYS_USB_CONNECTED)
-                {
-                    status = PLUGIN_USB_CONNECTED;
-                    goto metronome_exit;
-                }
+                exit_on_usb(button);
                 reset_tap = false;
                 break;

@@ -998,11 +992,5 @@ enum plugin_status plugin_start(const void* parameter)
         }
         rb->yield();
     }
-
-metronome_exit:
-#if CONFIG_CODEC == SWCODEC
-    rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
-#endif
-    return status;
 }

diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c
index d9e2151..442a747 100644
--- a/apps/plugins/midi/midiplay.c
+++ b/apps/plugins/midi/midiplay.c
@@ -25,7 +25,7 @@
 #include "sequencer.h"
 #include "midifile.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 /* variable button definitions */
@@ -450,7 +450,6 @@ static int midimain(const void * filename)
 enum plugin_status plugin_start(const void* parameter)
 {
     int retval;
-    PLUGINLIB_EXIT_INIT;

     PLUGIN_IRAM_INIT(rb)

diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index 58e56de..5793dde 100644
--- a/apps/plugins/minesweeper.c
+++ b/apps/plugins/minesweeper.c
@@ -25,7 +25,7 @@

 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* what the minesweeper() function can return */
 enum minesweeper_status {
diff --git a/apps/plugins/mosaique.c b/apps/plugins/mosaique.c
index 43efc27..42c9254 100644
--- a/apps/plugins/mosaique.c
+++ b/apps/plugins/mosaique.c
@@ -22,7 +22,7 @@
 #include "lib/playergfx.h"
 #include "lib/mylcd.h"

-PLUGIN_HEADER
+

 #ifdef HAVE_LCD_BITMAP
 #define GFX_X (LCD_WIDTH/2-1)
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c
index da749b8..06d28a3 100644
--- a/apps/plugins/mp3_encoder.c
+++ b/apps/plugins/mp3_encoder.c
@@ -14,7 +14,7 @@
 #include <inttypes.h>
 #include "plugin.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 #define SAMP_PER_FRAME       1152
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index 961214f..8142c6f 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -108,7 +108,7 @@
 #include "stream_thread.h"
 #include "stream_mgr.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 /* button definitions */
diff --git a/apps/plugins/nim.c b/apps/plugins/nim.c
index 460e275..3301277 100644
--- a/apps/plugins/nim.c
+++ b/apps/plugins/nim.c
@@ -48,7 +48,7 @@ V1.2 : 2003-07-30
      take a match. Later you are obliged to take at least one.)
 */

-PLUGIN_HEADER
+

 /*Pattern for the game*/
 static unsigned char smile[]={0x00, 0x11, 0x04, 0x04, 0x00, 0x11, 0x0E};    /* :-) */
@@ -144,6 +144,7 @@ enum plugin_status plugin_start(const void* parameter)
     int x,v,min;
     bool ok;
     bool go;
+    atexit(nim_exit);

     /* if you don't use the parameter, you can do like
        this to avoid the compiler warning about it */
@@ -193,7 +194,6 @@ enum plugin_status plugin_start(const void* parameter)
                     {
                         case BUTTON_STOP|BUTTON_REL:
                             go = true;
-                            nim_exit(NULL);
                             return PLUGIN_OK;
                             break;

@@ -214,9 +214,7 @@ enum plugin_status plugin_start(const void* parameter)
                             break;

                         default:
-                            if (rb->default_event_handler_ex(button, nim_exit,
-                                                    NULL) == SYS_USB_CONNECTED)
-                                return PLUGIN_USB_CONNECTED;
+                            exit_on_usb(button);
                             break;
                     }
                     display_first_line(x);
@@ -291,7 +289,6 @@ enum plugin_status plugin_start(const void* parameter)
             min=1;
         }
     }
-    nim_exit(NULL);
     return PLUGIN_OK;
 }
 #endif
diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c
index 4195d96..e9c21ff 100644
--- a/apps/plugins/oscilloscope.c
+++ b/apps/plugins/oscilloscope.c
@@ -23,12 +23,13 @@

 #include "plugin.h"
 #include "lib/helper.h"
+#include "lib/pluginlib_exit.h"

 #ifdef HAVE_LCD_BITMAP
 #include "lib/xlcd.h"
 #include "lib/configfile.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
@@ -751,9 +752,8 @@ void anim_vertical(int cur_left, int cur_right)
     last_pos = cur_y;
 }

-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void)parameter;
 #if LCD_DEPTH > 1
     rb->lcd_set_foreground(LCD_DEFAULT_FG);
     rb->lcd_set_background(LCD_DEFAULT_BG);
@@ -772,6 +772,7 @@ enum plugin_status plugin_start(const void* parameter)

     (void)parameter;

+    atexit(cleanup);
     configfile_load(cfg_filename, disk_config,
                     sizeof(disk_config) / sizeof(disk_config[0]),
                     CFGFILE_MINVERSION);
@@ -892,9 +893,7 @@ enum plugin_status plugin_start(const void* parameter)
                 break;

             default:
-                if (rb->default_event_handler_ex(button, cleanup, NULL)
-                    == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(button);
                 break;
         }
         if (button != BUTTON_NONE)
@@ -908,7 +907,6 @@ enum plugin_status plugin_start(const void* parameter)
             displaymsg = true;
         }
     }
-    cleanup(NULL);
     if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */
     {
         rb->memcpy(&osc_disk, &osc, sizeof(osc));
diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c
index 7f40822..db25b1c 100644
--- a/apps/plugins/pacbox/pacbox.c
+++ b/apps/plugins/pacbox/pacbox.c
@@ -32,7 +32,7 @@
 #include "lib/configfile.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 struct pacman_settings {
diff --git a/apps/plugins/pdbox/pdbox.c b/apps/plugins/pdbox/pdbox.c
index 4fa6978..7f4a7ac 100644
--- a/apps/plugins/pdbox/pdbox.c
+++ b/apps/plugins/pdbox/pdbox.c
@@ -28,7 +28,7 @@
 #include "PDa/src/s_stuff.h"

 /* Welcome to the PDBox plugin */
-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 /* Name of the file to open. */
diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c
index a429b00..a953c68 100644
--- a/apps/plugins/pegbox.c
+++ b/apps/plugins/pegbox.c
@@ -26,7 +26,7 @@
 #include "pluginbitmaps/pegbox_header.h"
 #include "pluginbitmaps/pegbox_pieces.h"

-PLUGIN_HEADER
+

 #define CONFIG_FILE_NAME "pegbox.cfg"

diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c
index 75dc405..738ca2f 100644
--- a/apps/plugins/pictureflow.c
+++ b/apps/plugins/pictureflow.c
@@ -24,7 +24,7 @@

 #include "lib/overlay.h"

-PLUGIN_HEADER
+

 /* this is the plugin entry point */
 enum plugin_status plugin_start(const void* parameter)
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index 546afad..8ad62b0 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -27,6 +27,7 @@
 #include <albumart.h>
 #include "lib/read_image.h"
 #include "lib/pluginlib_actions.h"
+#include "lib/pluginlib_exit.h"
 #include "lib/helper.h"
 #include "lib/configfile.h"
 #include "lib/grey.h"
@@ -34,7 +35,7 @@
 #include "lib/feature_wrappers.h"
 #include "lib/buflib.h"

-PLUGIN_HEADER
+

 /******************************* Globals ***********************************/

@@ -2068,9 +2069,8 @@ void update_scroll_animation(void)
 /**
   Cleanup the plugin
 */
-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void) parameter;
     int i;
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
     rb->cpu_boost(false);
@@ -2610,19 +2610,6 @@ int main(void)
     cache_version = CACHE_VERSION;
     configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, CONFIG_VERSION);

-
-#ifdef USEGSLIB
-    long grey_buf_used;
-    if (!grey_init(buf, buf_size, GREY_BUFFERED|GREY_ON_COP,
-                   LCD_WIDTH, LCD_HEIGHT, &grey_buf_used))
-    {
-        error_wait("Greylib init failed!");
-        return PLUGIN_ERROR;
-    }
-    grey_setfont(FONT_UI);
-    buf_size -= grey_buf_used;
-    buf = (void*)(grey_buf_used + (char*)buf);
-#endif
     buflib_init(&buf_ctx, (void *)buf, buf_size);

     if (!(empty_slide_hid = read_pfraw(EMPTY_SLIDE, 0)))
@@ -2841,9 +2828,7 @@ int main(void)
             }
             break;
         default:
-            if (rb->default_event_handler_ex(button, cleanup, NULL)
-                == SYS_USB_CONNECTED)
-                return PLUGIN_USB_CONNECTED;
+            exit_on_usb(button);
             break;
         }
     }
@@ -2855,6 +2840,7 @@ enum plugin_status plugin_start(const void *parameter)
 {
     int ret, i;
     (void) parameter;
+    atexit(cleanup);

     FOR_NB_SCREENS(i)
         rb->viewportmanager_theme_enable(i, false, NULL);
@@ -2873,6 +2859,21 @@ enum plugin_status plugin_start(const void *parameter)
     }
 #endif
 #endif
+
+#ifdef USEGSLIB
+    long grey_buf_used;
+    if (!grey_init(buf, buf_size, GREY_BUFFERED|GREY_ON_COP,
+                   LCD_WIDTH, LCD_HEIGHT, &grey_buf_used))
+    {
+        error_wait("Greylib init failed!");
+        return PLUGIN_ERROR;
+    }
+    grey_setfont(FONT_UI);
+    buf_size -= grey_buf_used;
+    buf = (void*)(grey_buf_used + (char*)buf);
+#endif
+
+    atexit(cleanup);
     ret = main();
     if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) {
         if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS,
@@ -2882,7 +2883,5 @@ enum plugin_status plugin_start(const void *parameter)
             ret = PLUGIN_ERROR;
         }
     }
-
-    cleanup(NULL);
     return ret;
 }
diff --git a/apps/plugins/pitch_detector.c b/apps/plugins/pitch_detector.c
index 36248a5..b3003cd 100644
--- a/apps/plugins/pitch_detector.c
+++ b/apps/plugins/pitch_detector.c
@@ -68,7 +68,7 @@
 #include "lib/helper.h"
 #include "pluginbitmaps/pitch_notes.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 /* Some fixed point calculation stuff */
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c
index 637d948..35bc03b 100644
--- a/apps/plugins/plasma.c
+++ b/apps/plugins/plasma.c
@@ -27,6 +27,7 @@
 #include "plugin.h"
 #include "lib/helper.h"
 #include "lib/pluginlib_actions.h"
+#include "lib/pluginlib_exit.h"

 #ifdef HAVE_LCD_BITMAP

@@ -35,7 +36,6 @@
 #endif
 #include "lib/fixedpoint.h"

-PLUGIN_HEADER

 /******************************* Globals ***********************************/

@@ -131,10 +131,8 @@ static void shades_generate(void)
 }
 #endif

-void cleanup(void *parameter)
+void cleanup(void)
 {
-    (void)parameter;
-
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
     if (boosted)
         rb->cpu_boost(false);
@@ -144,6 +142,9 @@ void cleanup(void *parameter)
 #endif
     /* Turn on backlight timeout (revert to settings) */
     backlight_use_settings(); /* backlight control in lib/helper.c */
+#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
+    rb->lcd_set_mode(LCD_MODE_RGB565);
+#endif
 }

 /*
@@ -180,10 +181,15 @@ int main(void)
     /* get the remainder of the plugin buffer */
     gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

-    grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
+    if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL))
+    {
+        rb->splash(HZ, "Couldn't init greyscale display");
+        return PLUGIN_ERROR;
+    }
     /* switch on greyscale overlay */
     grey_show(true);
 #endif
+    atexit(cleanup);
     sp1 = 4;
     sp2 = 2;
     sp3 = 4;
@@ -261,7 +267,6 @@ int main(void)
         {
             case PLA_EXIT:
             case PLA_CANCEL:
-                cleanup(NULL);
                 return PLUGIN_OK;
                 break;

@@ -299,9 +304,7 @@ int main(void)
 #endif

             default:
-                if (rb->default_event_handler_ex(action, cleanup, NULL)
-                    == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(action);
                 break;
         }
     }
@@ -311,8 +314,6 @@ int main(void)

 enum plugin_status plugin_start(const void* parameter)
 {
-    int ret;
-
     (void)parameter;
 #if LCD_DEPTH > 1
     rb->lcd_set_backdrop(NULL);
@@ -323,14 +324,7 @@ enum plugin_status plugin_start(const void* parameter)
 #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
     rb->lcd_set_mode(LCD_MODE_PAL256);
 #endif
-
-    ret = main();
-
-#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
-    rb->lcd_set_mode(LCD_MODE_RGB565);
-#endif
-
-    return ret;
+    return main();
 }

 #endif /* HAVE_LCD_BITMAP */
diff --git a/apps/plugins/plugins.make b/apps/plugins/plugins.make
index d3c66c3..aa4b2ea 100644
--- a/apps/plugins/plugins.make
+++ b/apps/plugins/plugins.make
@@ -33,7 +33,7 @@ PLUGIN_LDS := $(APPSDIR)/plugins/plugin.lds
 PLUGINLINK_LDS := $(BUILDDIR)/apps/plugins/plugin.link
 OVERLAYREF_LDS := $(BUILDDIR)/apps/plugins/overlay_ref.link
 endif
-
+PLUGIN_CRT0 := $(BUILDDIR)/apps/plugins/plugin_crt0.o
 # multifile plugins (subdirs):
 PLUGINSUBDIRS := $(call preprocess, $(APPSDIR)/plugins/SUBDIRS)

@@ -49,7 +49,7 @@ PLUGINFLAGS = -I$(APPSDIR)/plugins -DPLUGIN $(CFLAGS)
 $(ROCKS1): $(BUILDDIR)/%.rock: $(BUILDDIR)/%.o

 # dependency for all plugins
-$(ROCKS): $(APPSDIR)/plugin.h $(PLUGINLINK_LDS) $(PLUGINLIB) $(PLUGINBITMAPLIB)
+$(ROCKS): $(APPSDIR)/plugin.h $(PLUGINLINK_LDS) $(PLUGINLIB) $(PLUGINBITMAPLIB) $(PLUGIN_CRT0)

 $(PLUGINLIB): $(PLUGINLIB_OBJ)
 	$(SILENT)$(shell rm -f $@)
diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c
index 08899d7..8a41d9e 100644
--- a/apps/plugins/pong.c
+++ b/apps/plugins/pong.c
@@ -22,7 +22,7 @@

 #ifdef HAVE_LCD_BITMAP

-PLUGIN_HEADER
+

 #define PAD_HEIGHT LCD_HEIGHT / 6    /* Recorder: 10   iRiver: 21 */
 #define PAD_WIDTH LCD_WIDTH / 50     /* Recorder: 2    iRiver: 2  */
diff --git a/apps/plugins/ppmviewer.c b/apps/plugins/ppmviewer.c
index c947af1..035fffe 100644
--- a/apps/plugins/ppmviewer.c
+++ b/apps/plugins/ppmviewer.c
@@ -24,7 +24,7 @@

 #if defined(HAVE_LCD_COLOR)

-PLUGIN_HEADER
+

 /* Magic constants. */
 #define PPM_MAGIC1 'P'
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c
index 9d9020f..2e34a4e 100644
--- a/apps/plugins/properties.c
+++ b/apps/plugins/properties.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 bool its_a_dir = false;

diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c
index 9a589df..55d9bf9 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "file.h"

-PLUGIN_HEADER
+

 static bool cancel;
 static int fd;
diff --git a/apps/plugins/remote_control.c b/apps/plugins/remote_control.c
index e00d5de..a5ad442 100644
--- a/apps/plugins/remote_control.c
+++ b/apps/plugins/remote_control.c
@@ -23,7 +23,7 @@

 #include "lib/pluginlib_actions.h"

-PLUGIN_HEADER
+

 #define PLUGIN_CONTINUE 10

diff --git a/apps/plugins/reversi/reversi-gui.c b/apps/plugins/reversi/reversi-gui.c
index 67ccf19..dcdfe5f 100644
--- a/apps/plugins/reversi/reversi-gui.c
+++ b/apps/plugins/reversi/reversi-gui.c
@@ -47,7 +47,7 @@ further options:

 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* This is initialized at the start of the plugin and used to determine the
  * Appropriate game board size/legend spacing if the font is larger than a cell
diff --git a/apps/plugins/robotfindskitten.c b/apps/plugins/robotfindskitten.c
index 0e5c94e..003087b 100644
--- a/apps/plugins/robotfindskitten.c
+++ b/apps/plugins/robotfindskitten.c
@@ -34,7 +34,7 @@

 /* This macros must always be included. Should be placed at the top by
    convention, although the actual position doesn't matter */
-PLUGIN_HEADER
+

 /*Be sure to change MESSAGES when you change the array, or bad things
   will happen.*/
diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c
index 084eaa5..90df401 100644
--- a/apps/plugins/rockblox.c
+++ b/apps/plugins/rockblox.c
@@ -28,7 +28,7 @@
 #include "lib/playergfx.h"
 #include "lib/mylcd.h"

-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
     (CONFIG_KEYPAD == IPOD_3G_PAD) || \
diff --git a/apps/plugins/rockblox1d.c b/apps/plugins/rockblox1d.c
index 5006d88..1306cc9 100644
--- a/apps/plugins/rockblox1d.c
+++ b/apps/plugins/rockblox1d.c
@@ -22,7 +22,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+


 #ifdef HAVE_LCD_BITMAP
diff --git a/apps/plugins/rockbox_flash.c b/apps/plugins/rockbox_flash.c
index 17c5e51..f1c4f53 100644
--- a/apps/plugins/rockbox_flash.c
+++ b/apps/plugins/rockbox_flash.c
@@ -25,7 +25,7 @@

 #if (CONFIG_CPU == SH7034) /* Only for SH targets */

-PLUGIN_HEADER
+

 /* define DUMMY if you only want to "play" with the UI, does no harm */
 /* #define DUMMY */
diff --git a/apps/plugins/rockboy.c b/apps/plugins/rockboy.c
index bd72dea..b452073 100644
--- a/apps/plugins/rockboy.c
+++ b/apps/plugins/rockboy.c
@@ -24,7 +24,7 @@

 #include "lib/overlay.h"

-PLUGIN_HEADER
+

 /* this is the plugin entry point */
 enum plugin_status plugin_start(const void* parameter)
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c
index 797971c..7fc9199 100644
--- a/apps/plugins/rockboy/rockboy.c
+++ b/apps/plugins/rockboy/rockboy.c
@@ -26,7 +26,7 @@
 #include "hw.h"
 #include "pcm.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 int shut,cleanshut;
diff --git a/apps/plugins/rocklife.c b/apps/plugins/rocklife.c
index 210cffa..afe442f 100644
--- a/apps/plugins/rocklife.c
+++ b/apps/plugins/rocklife.c
@@ -64,7 +64,7 @@
 #include "lib/pluginlib_actions.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+

 #define ROCKLIFE_PLAY_PAUSE PLA_SELECT
 #define ROCKLIFE_INIT       PLA_DOWN
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index 264e4f6..7032a8e 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -33,7 +33,7 @@
 #include "lib/rgb_hsv.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /***********************************************************************
  * Buttons
diff --git a/apps/plugins/search.c b/apps/plugins/search.c
index 7edb7e2..76d8711 100644
--- a/apps/plugins/search.c
+++ b/apps/plugins/search.c
@@ -22,7 +22,7 @@
 #include "plugin.h"
 #include <ctype.h>

-PLUGIN_HEADER
+

 #define BUFFER_SIZE 16384

diff --git a/apps/plugins/searchengine/searchengine.c b/apps/plugins/searchengine/searchengine.c
index f737a27..4e8bc45 100644
--- a/apps/plugins/searchengine/searchengine.c
+++ b/apps/plugins/searchengine/searchengine.c
@@ -23,7 +23,7 @@
 #include "token.h"
 #include "dbinterface.h"

-PLUGIN_HEADER
+

 void *audio_bufferbase;
 void *audio_bufferpointer;
diff --git a/apps/plugins/settings_dumper.c b/apps/plugins/settings_dumper.c
index 93c4f67..381cdee 100644
--- a/apps/plugins/settings_dumper.c
+++ b/apps/plugins/settings_dumper.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 #define FILENAME "/settings_dumper.txt"
 static int setting_count = 0;
diff --git a/apps/plugins/shopper.c b/apps/plugins/shopper.c
index b05395b..61cf295 100644
--- a/apps/plugins/shopper.c
+++ b/apps/plugins/shopper.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 #define MAX_LIST_SIZE 400
 #define DESC_SIZE 40
diff --git a/apps/plugins/shortcuts/shortcuts_append.c b/apps/plugins/shortcuts/shortcuts_append.c
index 69b2a44..3eea87e 100644
--- a/apps/plugins/shortcuts/shortcuts_append.c
+++ b/apps/plugins/shortcuts/shortcuts_append.c
@@ -22,7 +22,7 @@

 #include "shortcuts.h"

-PLUGIN_HEADER
+


 bool append_entry_to_file(sc_file_t *file, char *path, bool is_dir)
diff --git a/apps/plugins/shortcuts/shortcuts_view.c b/apps/plugins/shortcuts/shortcuts_view.c
index a63e26d..469241f 100644
--- a/apps/plugins/shortcuts/shortcuts_view.c
+++ b/apps/plugins/shortcuts/shortcuts_view.c
@@ -22,7 +22,7 @@

 #include "shortcuts.h"

-PLUGIN_HEADER
+

 enum sc_list_action_type
 {
diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c
index 7bf49c1..4d7d2c0 100644
--- a/apps/plugins/sliding_puzzle.c
+++ b/apps/plugins/sliding_puzzle.c
@@ -21,7 +21,7 @@
 #include "plugin.h"

 #ifdef HAVE_LCD_BITMAP
-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c
index c3fe84e..00a43e5 100644
--- a/apps/plugins/snake.c
+++ b/apps/plugins/snake.c
@@ -38,7 +38,7 @@ dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
 #include "lib/highscore.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c
index 414d924..3fbf40b 100644
--- a/apps/plugins/snake2.c
+++ b/apps/plugins/snake2.c
@@ -34,7 +34,7 @@ Head and Tail are stored
 #include "lib/highscore.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 #define WIDTH  28
 #define HEIGHT 16
diff --git a/apps/plugins/snow.c b/apps/plugins/snow.c
index c3c9b74..c9abae4 100644
--- a/apps/plugins/snow.c
+++ b/apps/plugins/snow.c
@@ -22,7 +22,7 @@
 #include "lib/playergfx.h"
 #include "lib/mylcd.h"

-PLUGIN_HEADER
+

 #ifdef HAVE_LCD_BITMAP
 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c
index b2721c8..6e94519 100644
--- a/apps/plugins/sokoban.c
+++ b/apps/plugins/sokoban.c
@@ -24,7 +24,7 @@
 #include "plugin.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 #define SOKOBAN_TITLE        "Sokoban"

diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index 1c7aefb..1d2535f 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -28,7 +28,7 @@

 #ifdef HAVE_LCD_BITMAP

-PLUGIN_HEADER
+

 #define min(a,b) (a<b?a:b)

diff --git a/apps/plugins/sort.c b/apps/plugins/sort.c
index 1e787b3..f8c3f5c 100644
--- a/apps/plugins/sort.c
+++ b/apps/plugins/sort.c
@@ -57,7 +57,7 @@
  * TODO: Implement a merge sort for files larger than the buffer
  ****************************************************************************/

-PLUGIN_HEADER
+

 size_t buf_size;
 static char *filename;
diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c
index 0ade406..2e7ccc0 100644
--- a/apps/plugins/spacerocks.c
+++ b/apps/plugins/spacerocks.c
@@ -25,7 +25,7 @@
 #include "lib/highscore.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/splitedit.c b/apps/plugins/splitedit.c
index 3e5161b..c19d4b5 100644
--- a/apps/plugins/splitedit.c
+++ b/apps/plugins/splitedit.c
@@ -21,7 +21,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/star.c b/apps/plugins/star.c
index d11e318..c0f0997 100644
--- a/apps/plugins/star.c
+++ b/apps/plugins/star.c
@@ -23,7 +23,7 @@
 #include "lib/display_text.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* size of a level in file */
 #define STAR_LEVEL_SIZE    ((STAR_WIDTH + 1) * STAR_HEIGHT + 1)
diff --git a/apps/plugins/starfield.c b/apps/plugins/starfield.c
index 1ae0f28..09f58da 100644
--- a/apps/plugins/starfield.c
+++ b/apps/plugins/starfield.c
@@ -19,10 +19,11 @@

 #include "plugin.h"
 #include "lib/helper.h"
+#include "lib/pluginlib_exit.h"

 #ifdef HAVE_LCD_BITMAP /* and also not for the Player */

-PLUGIN_HEADER
+

 /******************************* Globals ***********************************/

@@ -497,9 +498,11 @@ int plugin_main(void)
             case STARFIELD_RC_QUIT:
 #endif
             case(STARFIELD_QUIT):
-            case(SYS_USB_CONNECTED):
                 return PLUGIN_OK;
                 break;
+            default:
+                exit_on_usb(button);
+                break;
         }
     }
 }
diff --git a/apps/plugins/stats.c b/apps/plugins/stats.c
index 3420579..ecf335d 100644
--- a/apps/plugins/stats.c
+++ b/apps/plugins/stats.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 static int files, dirs, musicfiles, largestdir;
 static int lasttick;
diff --git a/apps/plugins/stopwatch.c b/apps/plugins/stopwatch.c
index b09dcdb..6bac97e 100644
--- a/apps/plugins/stopwatch.c
+++ b/apps/plugins/stopwatch.c
@@ -21,7 +21,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+

 #ifdef HAVE_LCD_BITMAP
 #define TIMER_Y 1
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c
index f3d9b1e..4f87c5f 100644
--- a/apps/plugins/sudoku/sudoku.c
+++ b/apps/plugins/sudoku/sudoku.c
@@ -81,7 +81,7 @@ Example ".ss" file, and one with a saved state:
 #define BITMAP_WIDTH  BMPWIDTH_sudoku_normal
 #endif

-PLUGIN_HEADER
+

 /* Default game - used to initialise sudoku.ss if it doesn't exist. */
 static const char default_game[9][9] =
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c
index c2a7d8f..5ded7f9 100644
--- a/apps/plugins/superdom.c
+++ b/apps/plugins/superdom.c
@@ -22,7 +22,7 @@
 #include "lib/playback_control.h"
 #include "lib/display_text.h"
 #include "pluginbitmaps/superdom_boarditems.h"
-PLUGIN_HEADER
+

 extern const fb_data superdom_boarditems[];
 char buf[255];
diff --git a/apps/plugins/test_boost.c b/apps/plugins/test_boost.c
index 2406990..ec91206 100644
--- a/apps/plugins/test_boost.c
+++ b/apps/plugins/test_boost.c
@@ -21,7 +21,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+

 enum plugin_status plugin_start(const void* parameter)
 {
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index b8aa93d..94c510a 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 /* All swcodec targets have BUTTON_SELECT apart from the H10 and M3 */

diff --git a/apps/plugins/test_core_jpeg.c b/apps/plugins/test_core_jpeg.c
index 9e7ecfd..76dbac8 100644
--- a/apps/plugins/test_core_jpeg.c
+++ b/apps/plugins/test_core_jpeg.c
@@ -22,7 +22,7 @@
 #include "plugin.h"
 #include "lib/grey.h"
 #include "lib/mylcd.h"
-PLUGIN_HEADER
+

 /* different graphics libraries */
 #if LCD_DEPTH < 8
diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c
index 08e1a39..2650f4b 100644
--- a/apps/plugins/test_disk.c
+++ b/apps/plugins/test_disk.c
@@ -22,7 +22,7 @@
 #include "plugin.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+

 #define TESTBASEDIR "/__TEST__"
 #define TEST_FILE   TESTBASEDIR "/test_disk.tmp"
diff --git a/apps/plugins/test_fps.c b/apps/plugins/test_fps.c
index 62e7f48..80a8d88 100644
--- a/apps/plugins/test_fps.c
+++ b/apps/plugins/test_fps.c
@@ -45,7 +45,7 @@ PLUGIN_IRAM_DECLARE

 #define DURATION (2*HZ) /* longer duration gives more precise results */

-PLUGIN_HEADER
+

 /* Screen logging */
 static int line;
diff --git a/apps/plugins/test_gfx.c b/apps/plugins/test_gfx.c
index 2c46d16..aa89854 100644
--- a/apps/plugins/test_gfx.c
+++ b/apps/plugins/test_gfx.c
@@ -35,7 +35,7 @@ static size_t gbuf_size = 0;
 #define DURATION (HZ) /* longer duration gives more precise results */
 #define RND_SEED 0x43A678C3     /* arbirary */

-PLUGIN_HEADER
+

 static uint16_t rand_table[0x400];
 static int log_fd;
diff --git a/apps/plugins/test_grey.c b/apps/plugins/test_grey.c
index 31f6310..5931d96 100644
--- a/apps/plugins/test_grey.c
+++ b/apps/plugins/test_grey.c
@@ -22,7 +22,7 @@
 #include "lib/grey.h"
 #include "lib/helper.h"

-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
  || (CONFIG_KEYPAD == IPOD_1G2G_PAD)
diff --git a/apps/plugins/test_greylib_bitmap_scale.c b/apps/plugins/test_greylib_bitmap_scale.c
index 892f3dc..d096d02 100644
--- a/apps/plugins/test_greylib_bitmap_scale.c
+++ b/apps/plugins/test_greylib_bitmap_scale.c
@@ -44,7 +44,7 @@
 #define BMP_LOAD rb->read_bmp_file
 #endif

-PLUGIN_HEADER
+
 GREY_INFO_STRUCT
 static unsigned char grey_bm_buf[LCD_WIDTH * LCD_HEIGHT + 
                    BM_SCALED_SIZE(LCD_WIDTH,0,FORMAT_NATIVE,0)];
diff --git a/apps/plugins/test_mem.c b/apps/plugins/test_mem.c
index f648c00..7758e35 100644
--- a/apps/plugins/test_mem.c
+++ b/apps/plugins/test_mem.c
@@ -21,7 +21,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+

 #if PLUGIN_BUFFER_SIZE <= 0x8000
 #define BUF_SIZE (1<<12) /* 16 KB = (1<<12)*sizeof(int) */
diff --git a/apps/plugins/test_mem_jpeg.c b/apps/plugins/test_mem_jpeg.c
index 6e7d381..72f6131 100644
--- a/apps/plugins/test_mem_jpeg.c
+++ b/apps/plugins/test_mem_jpeg.c
@@ -25,7 +25,7 @@
 #include "lib/grey.h"
 #include "lib/jpeg_mem.h"
 #include "lib/mylcd.h"
-PLUGIN_HEADER
+

 /* different graphics libraries */
 #if LCD_DEPTH < 8
diff --git a/apps/plugins/test_resize.c b/apps/plugins/test_resize.c
index 8ee4989..2ab10eb 100644
--- a/apps/plugins/test_resize.c
+++ b/apps/plugins/test_resize.c
@@ -28,7 +28,7 @@
 #include "lib/pluginlib_actions.h"
 #include "lib/pluginlib_bmp.h"

-PLUGIN_HEADER
+

 const struct button_mapping *plugin_contexts[]
 = {pla_main_ctx};
diff --git a/apps/plugins/test_sampr.c b/apps/plugins/test_sampr.c
index 1f6ee35..85525c5 100644
--- a/apps/plugins/test_sampr.c
+++ b/apps/plugins/test_sampr.c
@@ -28,7 +28,7 @@
  * with sample rate.
  */

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE;

 static int hw_freq IDATA_ATTR = HW_FREQ_DEFAULT;
diff --git a/apps/plugins/test_scanrate.c b/apps/plugins/test_scanrate.c
index 1aa9feb..81d8248 100644
--- a/apps/plugins/test_scanrate.c
+++ b/apps/plugins/test_scanrate.c
@@ -23,7 +23,7 @@

 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR)

-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) \
  || (CONFIG_KEYPAD == IRIVER_H100_PAD)
diff --git a/apps/plugins/test_touchscreen.c b/apps/plugins/test_touchscreen.c
index 902a2bd..0c9cdc7 100644
--- a/apps/plugins/test_touchscreen.c
+++ b/apps/plugins/test_touchscreen.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == COWON_D2_PAD)
 #define TOUCHSCREEN_QUIT   BUTTON_POWER
diff --git a/apps/plugins/test_viewports.c b/apps/plugins/test_viewports.c
index 08c23a9..be61c77 100644
--- a/apps/plugins/test_viewports.c
+++ b/apps/plugins/test_viewports.c
@@ -21,7 +21,7 @@

 #include "plugin.h"

-PLUGIN_HEADER
+

 #ifdef HAVE_LCD_BITMAP

diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c
index acd82b8..ceb71e4 100644
--- a/apps/plugins/text_editor.c
+++ b/apps/plugins/text_editor.c
@@ -22,7 +22,7 @@
 #include "lib/playback_control.h"

 #define MAX_LINE_LEN 2048
-PLUGIN_HEADER
+

 static unsigned char *buffer;
 static size_t buffer_size;
diff --git a/apps/plugins/text_viewer/text_viewer.c b/apps/plugins/text_viewer/text_viewer.c
index eae8521..5d06d4b 100644
--- a/apps/plugins/text_viewer/text_viewer.c
+++ b/apps/plugins/text_viewer/text_viewer.c
@@ -21,11 +21,12 @@
  *
  ****************************************************************************/
 #include "plugin.h"
+#include "lib/pluginlib_exit.h"
 #include "tv_action.h"
 #include "tv_button.h"
 #include "tv_preferences.h"

-PLUGIN_HEADER
+

 enum plugin_status plugin_start(const void* file)
 {
@@ -56,6 +57,7 @@ enum plugin_status plugin_start(const void* file)
         return PLUGIN_ERROR;
     }

+    atexit(tv_exit);
     while (!done) {
 #ifdef HAVE_LCD_BITMAP
         if (rb->global_settings->statusbar != STATUSBAR_OFF && preferences->statusbar)
@@ -79,12 +81,12 @@ enum plugin_status plugin_start(const void* file)

                     if (res != TV_MENU_RESULT_EXIT_MENU)
                     {
-                        tv_exit(NULL);
-                        done = true;
                         if (res == TV_MENU_RESULT_ATTACHED_USB)
                             return PLUGIN_USB_CONNECTED;
                         else if (res == TV_MENU_RESULT_ERROR)
                             return PLUGIN_ERROR;
+                        else
+                            done = true;
                     }
                 }
                 break;
@@ -195,7 +197,6 @@ enum plugin_status plugin_start(const void* file)
 #ifdef TV_QUIT2
             case TV_QUIT2:
 #endif
-                tv_exit(NULL);
                 done = true;
                 break;

@@ -204,9 +205,7 @@ enum plugin_status plugin_start(const void* file)
                 break;

             default:
-                if (rb->default_event_handler_ex(button, tv_exit, NULL)
-                    == SYS_USB_CONNECTED)
-                    return PLUGIN_USB_CONNECTED;
+                exit_on_usb(button);
                 display_update = false;
                 break;
         }
diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c
index c95ece0..1e5473b 100644
--- a/apps/plugins/text_viewer/tv_action.c
+++ b/apps/plugins/text_viewer/tv_action.c
@@ -47,10 +47,8 @@ static void tv_finalize_action(void)
     tv_finalize_window();
 }

-void tv_exit(void *parameter)
+void tv_exit(void)
 {
-    (void)parameter;
-
     /* save preference and bookmarks */
     if (!tv_save_settings())
         rb->splash(HZ, "Can't save preferences and bookmarks");
diff --git a/apps/plugins/text_viewer/tv_action.h b/apps/plugins/text_viewer/tv_action.h
index fba008d..5b3571d 100644
--- a/apps/plugins/text_viewer/tv_action.h
+++ b/apps/plugins/text_viewer/tv_action.h
@@ -58,11 +58,8 @@ bool tv_init_action(unsigned char **buf, size_t *bufsize);

 /*
  * finalize modules
- *
- * [In] parameter
- *          this argument does not use
  */
-void tv_exit(void *parameter);
+void tv_exit(void);

 /*
  * load the file
diff --git a/apps/plugins/theme_remove.c b/apps/plugins/theme_remove.c
index f818ac4..d679338 100644
--- a/apps/plugins/theme_remove.c
+++ b/apps/plugins/theme_remove.c
@@ -20,7 +20,7 @@
 #include "plugin.h"
 #include "lib/configfile.h"

-PLUGIN_HEADER
+

 /* taken from apps/gui/wps_parser.c */
 #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
diff --git a/apps/plugins/vbrfix.c b/apps/plugins/vbrfix.c
index ba13dc5..71c502b 100644
--- a/apps/plugins/vbrfix.c
+++ b/apps/plugins/vbrfix.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 static char   *audiobuf;
 static size_t audiobuflen;
diff --git a/apps/plugins/video.c b/apps/plugins/video.c
index 6b0a47c..869a053 100644
--- a/apps/plugins/video.c
+++ b/apps/plugins/video.c
@@ -33,7 +33,7 @@

 #ifdef HAVE_LCD_BITMAP /* and definitely not for the Player, haha */

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/vu_meter.c b/apps/plugins/vu_meter.c
index fc04bc7..6dc69d1 100644
--- a/apps/plugins/vu_meter.c
+++ b/apps/plugins/vu_meter.c
@@ -21,7 +21,7 @@
 #include "lib/fixedpoint.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* variable button definitions */
 #if CONFIG_KEYPAD == RECORDER_PAD
diff --git a/apps/plugins/wav2wv.c b/apps/plugins/wav2wv.c
index 3211203..98b4c0f 100644
--- a/apps/plugins/wav2wv.c
+++ b/apps/plugins/wav2wv.c
@@ -25,7 +25,7 @@

 #include <codecs/libwavpack/wavpack.h>

-PLUGIN_HEADER
+

 #define SAMPLES_PER_BLOCK 22050

diff --git a/apps/plugins/wavplay.c b/apps/plugins/wavplay.c
index 94fef9f..cbd4dfb 100644
--- a/apps/plugins/wavplay.c
+++ b/apps/plugins/wavplay.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 /************ Start of MAS pcm codec, raw i2c blocks ************/

diff --git a/apps/plugins/wavrecord.c b/apps/plugins/wavrecord.c
index 83b63e9..375642e 100644
--- a/apps/plugins/wavrecord.c
+++ b/apps/plugins/wavrecord.c
@@ -21,7 +21,7 @@
 #include "plugin.h"
 #include "lib/configfile.h"

-PLUGIN_HEADER
+

 /************ Start of MAS pcm codec, raw i2c blocks ************/

diff --git a/apps/plugins/wavview.c b/apps/plugins/wavview.c
index 2b19d3d..ddf72e1 100644
--- a/apps/plugins/wavview.c
+++ b/apps/plugins/wavview.c
@@ -20,7 +20,7 @@
  ****************************************************************************/
 #include "plugin.h"

-PLUGIN_HEADER
+

 /* temp byte buffer */
 uint8_t samples[10 * 1024]; /* read 10KB at the time */
diff --git a/apps/plugins/wormlet.c b/apps/plugins/wormlet.c
index 037f400..191c995 100644
--- a/apps/plugins/wormlet.c
+++ b/apps/plugins/wormlet.c
@@ -23,7 +23,7 @@
 #include "lib/helper.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 /* size of the field the worm lives in */
 #define FIELD_RECT_X 1
diff --git a/apps/plugins/xobox.c b/apps/plugins/xobox.c
index 4dd673c..871cb2b 100644
--- a/apps/plugins/xobox.c
+++ b/apps/plugins/xobox.c
@@ -24,7 +24,7 @@
 #include "lib/helper.h"
 #include "lib/playback_control.h"

-PLUGIN_HEADER
+

 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)

diff --git a/apps/plugins/zxbox.c b/apps/plugins/zxbox.c
index 94f7807..08e07d5 100644
--- a/apps/plugins/zxbox.c
+++ b/apps/plugins/zxbox.c
@@ -21,7 +21,7 @@

 #include "lib/overlay.h"

-PLUGIN_HEADER
+

 /* this is the plugin entry point */
 enum plugin_status plugin_start(const void* parameter)
diff --git a/apps/plugins/zxbox/zxbox.c b/apps/plugins/zxbox/zxbox.c
index f33b51b..459e062 100644
--- a/apps/plugins/zxbox/zxbox.c
+++ b/apps/plugins/zxbox/zxbox.c
@@ -21,7 +21,7 @@

 #include "zxconfig.h"

-PLUGIN_HEADER
+
 PLUGIN_IRAM_DECLARE

 #include "spkey_p.h"