release r2, update credits
[fceu.git] / drivers / gp2x / squidgehack.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8
9 extern char **g_argv;
10
11 /* Call this MMU Hack kernel module after doing mmap, and before doing memset*/
12 int mmuhack(void)
13 {
14         char kocmd[1024];
15         int i, mmufd;
16
17         /* some programs like some versions of gpSP use some weird version of mmuhack.o
18          * which doesn't seem to work. What's even worse they leave their mmuhack loaded on exit.
19          * So we must remove whatever may be left and always reload _our_ mmuhack.o */
20         system("/sbin/rmmod mmuhack");
21
22         strcpy(kocmd, "/sbin/insmod ");
23         strncpy(kocmd+13, g_argv[0], 1023-13);
24         kocmd[1023] = 0;
25         for (i = strlen(kocmd); i > 13; i--)
26                 if (kocmd[i] == '/') { i++; break; }
27         strcpy(kocmd+i, "mmuhack.o");
28
29         printf("Installing NK's kernel module for Squidge MMU Hack (%s)...\n", kocmd);
30         system(kocmd);
31         mmufd = open("/dev/mmuhack", O_RDWR);
32         if(mmufd < 0) return 0;
33
34         close(mmufd);
35         return 1;
36 }
37
38
39 /* Unload MMU Hack kernel module after closing all memory devices*/
40 int mmuunhack(void)
41 {
42         int ret;
43         printf("Removing NK's kernel module for Squidge MMU Hack... "); fflush(stdout);
44         ret = system("/sbin/rmmod mmuhack");
45         printf("done (%i)\n", ret);
46
47         return ret;
48 }