summaryrefslogtreecommitdiff
path: root/src/squidgehack.c
diff options
context:
space:
mode:
authorToad King2012-06-14 03:21:06 -0400
committerToad King2012-06-14 03:21:06 -0400
commit6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119 (patch)
tree885cf7f507139b795ba7b2a6fb829dc044da39dd /src/squidgehack.c
downloadsnes9x2002-6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119.tar.gz
snes9x2002-6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119.tar.bz2
snes9x2002-6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119.zip
initial pocketsnes commit
Diffstat (limited to 'src/squidgehack.c')
-rw-r--r--src/squidgehack.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/squidgehack.c b/src/squidgehack.c
new file mode 100644
index 0000000..f831bd4
--- /dev/null
+++ b/src/squidgehack.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+extern char **g_argv;
+
+/* Call this MMU Hack kernel module after doing mmap, and before doing memset*/
+int mmuhack(void)
+{
+ char kocmd[1024];
+ int i, mmufd = open("/dev/mmuhack", O_RDWR);
+
+ if(mmufd < 0) {
+ strcpy(kocmd, "/sbin/insmod ");
+ strncpy(kocmd+13, g_argv[0], 1023-13);
+ kocmd[1023] = 0;
+ for (i = strlen(kocmd); i > 0; i--)
+ if (kocmd[i] == '/') { kocmd[i] = 0; break; }
+ strcat(kocmd, "/mmuhack.o");
+
+ printf("Installing NK's kernel module for Squidge MMU Hack (%s)...\n", kocmd);
+ system(kocmd);
+ mmufd = open("/dev/mmuhack", O_RDWR);
+ }
+ if(mmufd < 0) return 0;
+
+ close(mmufd);
+ return 1;
+}
+
+
+/* Unload MMU Hack kernel module after closing all memory devices*/
+int mmuunhack(void)
+{
+ int ret;
+ printf("Removing NK's kernel module for Squidge MMU Hack... "); fflush(stdout);
+ ret = system("/sbin/rmmod mmuhack");
+ printf("done (%i)\n", ret);
+
+ return ret;
+}