| 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 = open("/dev/mmuhack", O_RDWR); |
| 16 | |
| 17 | if(mmufd < 0) { |
| 18 | strcpy(kocmd, "/sbin/insmod "); |
| 19 | strncpy(kocmd+13, g_argv[0], 1023-13); |
| 20 | kocmd[1023] = 0; |
| 21 | for (i = strlen(kocmd); i > 0; i--) |
| 22 | if (kocmd[i] == '/') { kocmd[i] = 0; break; } |
| 23 | strcat(kocmd, "/mmuhack.o"); |
| 24 | |
| 25 | printf("Installing NK's kernel module for Squidge MMU Hack (%s)...\n", kocmd); |
| 26 | system(kocmd); |
| 27 | mmufd = open("/dev/mmuhack", O_RDWR); |
| 28 | } |
| 29 | if(mmufd < 0) return 0; |
| 30 | |
| 31 | close(mmufd); |
| 32 | return 1; |
| 33 | } |
| 34 | |
| 35 | |
| 36 | /* Unload MMU Hack kernel module after closing all memory devices*/ |
| 37 | int mmuunhack(void) |
| 38 | { |
| 39 | int ret; |
| 40 | printf("Removing NK's kernel module for Squidge MMU Hack... "); fflush(stdout); |
| 41 | ret = system("/sbin/rmmod mmuhack"); |
| 42 | printf("done (%i)\n", ret); |
| 43 | |
| 44 | return ret; |
| 45 | } |