home *** CD-ROM | disk | FTP | other *** search
- /*
- ** ixstacksize.c
- **
- ** Change the stack size for an already compiled ixemul-program
- **
- ** Compile:
- ** vc vlib:minstart.o ixstacksize.c -sc -sd -lamigas -lvcs -nostdlib
- ** -o ixstacksize
- **
- ** Written by Frank Wille 02-Jan-97
- **
- */
-
-
- #include <exec/libraries.h>
- #include <exec/memory.h>
- #include <dos/dos.h>
- #include <dos/rdargs.h>
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
-
-
- static void setstack(ULONG *,UWORD *,ULONG,char *);
-
- struct Library *DOSBase=NULL;
- static char *rev_string = "$VER: ixstacksize 1.0 (02.02.97)\r\n";
-
-
- int main()
- {
- LONG argv[] = { 0,0 };
- struct RDArgs *rda;
- struct FileInfoBlock fib;
- BPTR fh;
- UWORD *buf;
-
- if (!(DOSBase = OpenLibrary("dos.library",37)))
- exit(20);
- if (rda = ReadArgs("NAME/A,STACK/K/N",argv,NULL)) {
- if (fh = Open((STRPTR)argv[0],MODE_OLDFILE)) {
- if (ExamineFH(fh,&fib)) {
- if (buf = (UWORD *)AllocVec((unsigned long)fib.fib_Size,
- MEMF_PUBLIC)) {
- if (Read(fh,buf,fib.fib_Size) >= 0) {
- Close(fh);
- setstack((ULONG *)argv[1],buf,fib.fib_Size,(char *)argv[0]);
- }
- else {
- Close(fh);
- Printf("Read error!\n");
- }
- FreeVec(buf);
- }
- else {
- Close(fh);
- Printf("Out of memory!\n");
- }
- }
- else {
- Close(fh);
- Printf("Can't determine size of %s.\n",(char *)argv[0]);
- }
- }
- else
- Printf("Could not open %s.\n",(char *)argv[0]);
- FreeArgs(rda);
- }
- else
- PrintFault(IoErr(),NULL);
- CloseLibrary(DOSBase);
- }
-
-
- static void setstack(stacksize,buf,bufsize,filename)
- ULONG *stacksize;
- UWORD *buf;
- ULONG bufsize;
- char *filename;
- {
- UWORD *p=buf;
- ULONG i;
- BPTR fh;
-
- for (i=0; i<=(bufsize-12); i+=2,p++)
- if (*(ULONG *)p==0x5374436b && *(ULONG *)(p+4)==0x7354634b) {
- i = 0;
- break;
- }
- if (i==0) {
- p += 2;
- if (stacksize) {
- if ((i = (*stacksize + 3) & ~3) < 4096) {
- Printf("Stack size must be at least 4096 bytes.\n");
- i = 4096;
- }
- if (fh = Open((STRPTR)filename,MODE_NEWFILE)) {
- *(ULONG *)p = i;
- if (Write(fh,buf,bufsize) < 0) {
- Printf("*** Write error!!! ***\n");
- Close(fh);
- return;
- }
- Close(fh);
- }
- else
- Printf("Can't open %s for writing!\n",filename);
- }
- Printf("Stack size of %s: %ld bytes.\n",filename,*(long *)p);
- }
- else
- Printf("%s doesn't allow to change its stack size.\n",filename);
- }
-