cc68a136 |
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]; |
55ca4154 |
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 > 0; i--) |
26 | if (kocmd[i] == '/') { kocmd[i] = 0; break; } |
27 | strcat(kocmd, "/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 | |
cc68a136 |
33 | if(mmufd < 0) return 0; |
55ca4154 |
34 | |
cc68a136 |
35 | close(mmufd); |
36 | return 1; |
55ca4154 |
37 | } |
cc68a136 |
38 | |
39 | |
40 | /* Unload MMU Hack kernel module after closing all memory devices*/ |
41 | int mmuunhack(void) |
42 | { |
43 | int ret; |
44 | printf("Removing NK's kernel module for Squidge MMU Hack... "); fflush(stdout); |
45 | ret = system("/sbin/rmmod mmuhack"); |
46 | printf("done (%i)\n", ret); |
47 | |
48 | return ret; |
49 | } |