public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: How to add 4K of scratch space at the bottom of the stack   using C   instead of C++?
@ 2005-07-12 18:02 Yu-Cheng Chou
  2005-07-12 20:15 ` Max Kaehn
  0 siblings, 1 reply; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-12 18:02 UTC (permalink / raw)
  To: cygwin


> As has been already pointed out, you have to load cygwin1.dll first,
> initialize it, and then load your DLL.  The whole cygload thing is for
> cygwin1.dll only, it will not work for anything else.  After the Cygwin
> DLL has been loaded and initialized you should be able to load your DLL
> that depends on the Cygwin DLL normally, without any special procedure. 
> If you try to load your DLL directly Cygwin will not be initialized
> properly, and if you try to locate the Cygwin initialization routine in
> your DLL it will fail (because it exists only in the Cygwin DLL.)

My program works in this way. However, after the cygwin1.dll was 
initialized, the I/O seemed to be redirected. How can I get my I/O back?
I listed my codes below for reference.


/* main.c */
#include <stdio.h>
#include <windows.h>

extern "C" int mainCRTStartup();

extern "C" int __stdcall 
cygloadCRTStartup() {
    char padding[4096];
    return mainCRTStartup();
}

int main() {   
    char *modname = "module.dll";  
    HMODULE h;
    HMODULE handle;
    void (*init)();
    int (*fp)(int);
    int ret;

printf("1\n");

    h = LoadLibrary("cygwin1.dll");

printf("h  = %p\n", h);

    init = (void (*)())GetProcAddress(h, "cygwin_dll_init");

printf("init = %p\n", init);
 
    init(); // after this, I/O will be redirected

printf("2\n");

    handle = LoadLibrary(modname);

    if(handle == NULL) {
        fprintf(stderr, "Can't load %s in LoadLibrary()\n", modname);
        exit(1);
    }
printf("handle = %p\n", handle);

    fp = (int (*)(int))GetProcAddress(handle, "foo");

    if(fp== NULL) {
        fprintf(stderr, "ERROR: GetProcAddress()\n");
        exit(1);
    }
printf("fp = %p\n", fp);

    ret = fp(100);

printf("ret = %d\n", ret);

    return 0;
}

/* module.c */
#include <stdio.h>

int foo(int arg){
   printf("foo() is called in main.exe\n");
   printf("arg * 2 = %d\n", arg * 2);
   return arg * 2;
}

Here is the output from MS command prompt
C:\users\ycchou\VC1>main.exe
1
h  = 61000000
init = 61005790
foo() is called in main.exe
arg * 2 = 200

Thanks for anyone's help

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack    using C   instead of C++?
  2005-07-12 18:02 How to add 4K of scratch space at the bottom of the stack using C instead of C++? Yu-Cheng Chou
@ 2005-07-12 20:15 ` Max Kaehn
  0 siblings, 0 replies; 16+ messages in thread
From: Max Kaehn @ 2005-07-12 20:15 UTC (permalink / raw)
  To: cygwin

On Tue, 2005-07-12 at 11:02 -0700, Yu-Cheng Chou wrote:
> My program works in this way. However, after the cygwin1.dll was 
> initialized, the I/O seemed to be redirected. How can I get my I/O back?
> I listed my codes below for reference.

Does your CYGWIN environment variable include the string "tty"?



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack    using C   instead of C++?
@ 2005-07-12 22:56 Yu-Cheng Chou
  0 siblings, 0 replies; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-12 22:56 UTC (permalink / raw)
  To: cygwin


> > My program works in this way. However, after the cygwin1.dll was 
> > initialized, the I/O seemed to be redirected. How can I get my I/O
> > back?
> > I listed my codes below for reference.

> Does your CYGWIN environment variable include the string "tty"?

I set tty as CYGWIN's environment variable value, and the program works.
But the last new line character in the last printf() of foo() in 
module.dll doesn't work.
How to fix it?
Thanks

/* module.c */
#include <stdio.h>

int foo(int arg){
   printf("foo() is called in main.exe\n");
   printf("arg * 2 = %d\n", arg * 2);
   return arg * 2;
}


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack   using C   instead of C++?
  2005-07-11 21:46 Yu-Cheng Chou
  2005-07-11 22:08 ` Max Kaehn
@ 2005-07-12  3:44 ` Brian Dessent
  1 sibling, 0 replies; 16+ messages in thread
From: Brian Dessent @ 2005-07-12  3:44 UTC (permalink / raw)
  To: cygwin

Yu-Cheng Chou wrote:

> I have module.dll that was created by using command line "gcc -shared -o
> module.dll module.c" in cygwin.
> When I run "msvc-cygload -v -cygwin module.dll" in cygwin, error messages
> listed below occurred.

As has been already pointed out, you have to load cygwin1.dll first,
initialize it, and then load your DLL.  The whole cygload thing is for
cygwin1.dll only, it will not work for anything else.  After the Cygwin
DLL has been loaded and initialized you should be able to load your DLL
that depends on the Cygwin DLL normally, without any special procedure. 
If you try to load your DLL directly Cygwin will not be initialized
properly, and if you try to locate the Cygwin initialization routine in
your DLL it will fail (because it exists only in the Cygwin DLL.)

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack     using C instead of C++?
  2005-07-11 23:14 Yu-Cheng Chou
@ 2005-07-11 23:22 ` Max Kaehn
  0 siblings, 0 replies; 16+ messages in thread
From: Max Kaehn @ 2005-07-11 23:22 UTC (permalink / raw)
  To: cygwin

On Mon, 2005-07-11 at 16:14 -0700, Yu-Cheng Chou wrote:
> I used "cl -c main.c" and "cl /o main.exe main.obj" to create main.exe.
> I used "gcc -shared -o module.dll module.c" to create module.dll.
> module.dll will be invoked in main.exe. However, when I run main.exe, the 
> program just hung there.

> So, my question is in an executable program that was created by MSVC, how 
> to dynamically load a library (module.dll) that was created by cygwin's 
> gcc?

If you don't need cygwin functionality, you can just use MinGW
http://www.mingw.org/ and "gcc -mno-cygwin".

> Some users suggested that I load cygwin1.dll before module.dll because 
> module.dll might be related to cygwin1.dll.

> module.dll will only be created by cygwin's gcc, but I'm not sure if I did 
> it in the correct way using "gcc -shared -o module.dll module.c".

You may need to arrange that the symbols are exported; do a "dumpbin
/exports module.dll" and make sure that those things are available.

If your module.dll expects cygwin1.dll to already be present and
initialized, you'll need to arrange for 4K at the bottom of your stack,
then load cygwin1.dll and call cygwin_dll_init(), then load module.dll.

To separate out problems with DLL creation from problems with loading
cygwin, create a cygwin loader application for your DLL first, then
once you have the bugs ironed out of that, create the non-cygwin
version of the loader.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack    using C instead of C++?
@ 2005-07-11 23:14 Yu-Cheng Chou
  2005-07-11 23:22 ` Max Kaehn
  0 siblings, 1 reply; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-11 23:14 UTC (permalink / raw)
  To: cygwin


> > I have module.dll that was created by using command line "gcc -shared
> > -o module.dll module.c" in cygwin.
> > When I run "msvc-cygload -v -cygwin module.dll" in cygwin, error
> > messages listed below occurred.
 
> Why are you using cygload to load something that isn't cygwin1.dll?

Hi, Max:

Originally, I got two files, main.c and module.c

// main.c
#include <stdio.h>
#include <windows.h>

int main(){
   void *handle;
   int (*fp)();
   char *modname = "./module.dll";
 
   handle = LoadLibrary(modname);
   if (handle == NULL) {
      fprintf(stderr, "Can't load %s in LoadLibrary()\n", modname);
      exit(1);
   }
   fp = (int (*)())GetProcAddress((HMODULE)handle, "foo");
   if (fp== NULL) {
      fprintf(stderr, "ERROR: GetProcAddress()\n");
      exit(1);
   }
   fp();
   FreeLibrary((HMODULE)handle);
}

// module.c
#include <stdio.h>
#include <windows.h>

int foo(int arg){
   printf("foo() called\n");
   return (arg * 2);
}

I used "cl -c main.c" and "cl /o main.exe main.obj" to create main.exe.
I used "gcc -shared -o module.dll module.c" to create module.dll.
module.dll will be invoked in main.exe. However, when I run main.exe, the 
program just hung there.

So, my question is in an executable program that was created by MSVC, how 
to dynamically load a library (module.dll) that was created by cygwin's 
gcc?

Some users suggested that I load cygwin1.dll before module.dll because 
module.dll might be related to cygwin1.dll.
module.dll will only be created by cygwin's gcc, but I'm not sure if I did 
it in the correct way using "gcc -shared -o module.dll module.c".

I have been working on this for a while, but still can't figure out how to 
make it work.

Could you help me with this?

Thanks   

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack    using C instead of C++?
  2005-07-11 21:46 Yu-Cheng Chou
@ 2005-07-11 22:08 ` Max Kaehn
  2005-07-12  3:44 ` Brian Dessent
  1 sibling, 0 replies; 16+ messages in thread
From: Max Kaehn @ 2005-07-11 22:08 UTC (permalink / raw)
  To: cygwin

On Mon, 2005-07-11 at 14:46 -0700, Yu-Cheng Chou wrote:
> I have module.dll that was created by using command line "gcc -shared -o 
> module.dll module.c" in cygwin.
> When I run "msvc-cygload -v -cygwin module.dll" in cygwin, error messages 
> listed below occurred.

Why are you using cygload to load something that isn't cygwin1.dll?



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack   using C instead of C++?
@ 2005-07-11 21:46 Yu-Cheng Chou
  2005-07-11 22:08 ` Max Kaehn
  2005-07-12  3:44 ` Brian Dessent
  0 siblings, 2 replies; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-11 21:46 UTC (permalink / raw)
  To: cygwin


> > > I downloaded the cygload package, set up the MSVCDir for my system,
> > > and
> > > used c:\cygwin\bin\make to run the Makefile. The msvc-cygload.exe was
> > > successfully created. However, when I run msvc-cygload.exe, error
> > > messages listed below occurred.
  
> > 1.  You're running cygwin 1.5.18?
> > 2.  What version of Visual Studio are you using?
> > 3.  Did you try "cygload -v" to see how far it got before it crashed?
 
> I was running 1.5.17 originally. The msvc-cygload.exe works for cygwin 
> 1.5.18.
> I used Microsoft Visual Studio .NET 2003.
> I think the error caused by the older version of cygwin.
> 
> Thanks

I have module.dll that was created by using command line "gcc -shared -o 
module.dll module.c" in cygwin.
When I run "msvc-cygload -v -cygwin module.dll" in cygwin, error messages 
listed below occurred.

Connecting to cygwin...
Warning! Stack base is 00130000. padding ends at 0012FFC0. Delta is 64.  
Stack variables could be overwritten!
Loading module.dll...
Initializing cygwin...
GetProcAddress(cygwin_dll_init):  The specified procedure could not be 
found. (127)

Is it because I created module.dll in the wrong way?
How to fix it?
Thanks

Here is the module.c

//module.c
#include <stdio.h>
#include <windows.h>

/*
__declspec(dllexport)
*/

int foo(int arg){
   printf("foo() called\n");
   return (arg * 2);
}

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack   using C instead of C++?
@ 2005-07-11 20:05 Yu-Cheng Chou
  0 siblings, 0 replies; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-11 20:05 UTC (permalink / raw)
  To: cygwin


> > I downloaded the cygload package, set up the MSVCDir for my system, and
> > used c:\cygwin\bin\make to run the Makefile. The msvc-cygload.exe was 
> > successfully created. However, when I run msvc-cygload.exe, error
> > messages listed below occurred.
 
> 1.  You're running cygwin 1.5.18?
> 2.  What version of Visual Studio are you using?
> 3.  Did you try "cygload -v" to see how far it got before it crashed?

I was running 1.5.17 originally. The msvc-cygload.exe works for cygwin 
1.5.18.
I used Microsoft Visual Studio .NET 2003.
I think the error caused by the older version of cygwin.

Thanks

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack   using C instead of C++?
  2005-07-11 18:55 Yu-Cheng Chou
@ 2005-07-11 19:37 ` Max Kaehn
  0 siblings, 0 replies; 16+ messages in thread
From: Max Kaehn @ 2005-07-11 19:37 UTC (permalink / raw)
  To: cygwin

On Mon, 2005-07-11 at 11:55 -0700, Yu-Cheng Chou wrote:
> I downloaded the cygload package, set up the MSVCDir for my system, and 
> used c:\cygwin\bin\make to run the Makefile. The msvc-cygload.exe was 
> successfully created. However, when I run msvc-cygload.exe, error messages 
> listed below occurred.

1.  You're running cygwin 1.5.18?
2.  What version of Visual Studio are you using?
3.  Did you try "cygload -v" to see how far it got before it crashed?



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack  using C instead of C++?
@ 2005-07-11 18:55 Yu-Cheng Chou
  2005-07-11 19:37 ` Max Kaehn
  0 siblings, 1 reply; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-11 18:55 UTC (permalink / raw)
  To: cygwin


> > > By the way, the Makefile shows that the MSVC compiler is in
> > > C:/cygwin/usr/local/tools/i686_win32/vc7/Vc7.
> > > Is it a package that is provided by cygwin? Or is it the MSVC
> > > software
> > > that is installed in that directory?

> > Umm, no, Cygwin doesn't install MSVC (hopefully).  I believe this is an
> > artifact of the system configuration of whoever submitted the Makefile.
 
> Yes.  That's the effective MSVCDir I use; if you've got your environment
> filled out from vcvars32.bat, it should provide the right MSVCDir for
> your own system and the Makefile should pick it up.

I downloaded the cygload package, set up the MSVCDir for my system, and 
used c:\cygwin\bin\make to run the Makefile. The msvc-cygload.exe was 
successfully created. However, when I run msvc-cygload.exe, error messages 
listed below occurred.

       3 [main] ? 1768 handle_exceptions: Exception: 
STATUS_ACCESS_VIOLATION
Exception: STATUS_ACCESS_VIOLATION at eip=610B93F3
eax=0012F084 ebx=0000032C ecx=0000032C edx=00130000 esi=000000A8 
edi=00000000
ebp=0012E948 esp=0012E948 program=, pid 0, thread main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame     Function  Args
0012E948  610B93F3  (0000032C, 0012E8DC, 0012E978, 610BB331)
0012E978  610B92E0  (61128014, 6110F1B4, 00000000, 00000000)
0012E9B8  61006775  (00000000, FFFFFFFE, 0000074C, 6110F1B4)
0012E9E8  61006FBD  (0012EBFC, 00000000, 00000000, 7FFD9000)
0012EA58  00401CB2  (0040F390, 00000000, 00000000, 7FFD9000)
0012EF44  00402BEE  (00000001, 00325188, 00322D80, 00000000)
0012EF9C  0040B2EC  (00470046, 00490048, 00325118, 00325158)
0012FFC0  004029CD  (00000000, 00000000, 7FFD9000, 805502FA)
0012FFF0  7C816D4F  (004013ED, 00000000, 78746341, 00000020)
End of stack trace

how to fix it? Thanks

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack  using C instead of C++?
  2005-07-11 16:12 ` Igor Pechtchanski
@ 2005-07-11 18:37   ` Max Kaehn
  0 siblings, 0 replies; 16+ messages in thread
From: Max Kaehn @ 2005-07-11 18:37 UTC (permalink / raw)
  To: cygwin

On Mon, 2005-07-11 at 12:12 -0400, Igor Pechtchanski wrote:
> > By the way, the Makefile shows that the MSVC compiler is in
> > C:/cygwin/usr/local/tools/i686_win32/vc7/Vc7.
> > Is it a package that is provided by cygwin? Or is it the MSVC software
> > that is installed in that directory?
> 
> Umm, no, Cygwin doesn't install MSVC (hopefully).  I believe this is an
> artifact of the system configuration of whoever submitted the Makefile.

Yes.  That's the effective MSVCDir I use; if you've got your environment
filled out from vcvars32.bat, it should provide the right MSVCDir for
your own system and the Makefile should pick it up.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack using   C instead of C++?
  2005-07-11 15:42 Yu-Cheng Chou
@ 2005-07-11 16:12 ` Igor Pechtchanski
  2005-07-11 18:37   ` Max Kaehn
  0 siblings, 1 reply; 16+ messages in thread
From: Igor Pechtchanski @ 2005-07-11 16:12 UTC (permalink / raw)
  To: Yu-Cheng Chou; +Cc: cygwin

On Mon, 11 Jul 2005, Yu-Cheng Chou wrote:

> By the way, the Makefile shows that the MSVC compiler is in
> C:/cygwin/usr/local/tools/i686_win32/vc7/Vc7.
> Is it a package that is provided by cygwin? Or is it the MSVC software
> that is installed in that directory?

Umm, no, Cygwin doesn't install MSVC (hopefully).  I believe this is an
artifact of the system configuration of whoever submitted the Makefile.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack using  C instead of C++?
@ 2005-07-11 15:42 Yu-Cheng Chou
  2005-07-11 16:12 ` Igor Pechtchanski
  0 siblings, 1 reply; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-11 15:42 UTC (permalink / raw)
  To: cygwin


> > Hi,
> > In order to dynamically load cygwin1.dll with VC, I need to add 4K of
> > scratch space at the bottom of my stack.
> >
> > The winsup/testsuite/cygload/cygload.cpp shows how to do it using C++.
> 
> I believe it's cygload.cc...
> 
> > How can I add the scratch space using C rather than C++ in a simplest
> > way?
> 
> I'm afraid it won't be very simple, but how about something like
> 
> int main(int ac, char *av[]) {
>     char padding[4096];
>     backup_lower_stack();
> 
>     ...
> 
>     restore_lower_stack();
>     return ...
> }
> 
> with backup_lower_stack() and restore_lower_stack() adapted from the
> cygwin::padding constructor and destructor, respectively (the vector can
> be replaced by a malloc'ed piece of memory).
> 
> However, you'll also need to write a C interface to cygwin::connector.
> Once you have this working, I would strongly urge you to submit the code
> to Cygwin.

By the way, the Makefile shows that the MSVC compiler is in 
C:/cygwin/usr/local/tools/i686_win32/vc7/Vc7. 
Is it a package that is provided by cygwin? Or is it the MSVC software 
that is installed in that directory?

Thanks 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How to add 4K of scratch space at the bottom of the stack using  C instead of C++?
  2005-07-11  3:27 Yu-Cheng Chou
@ 2005-07-11  3:58 ` Igor Pechtchanski
  0 siblings, 0 replies; 16+ messages in thread
From: Igor Pechtchanski @ 2005-07-11  3:58 UTC (permalink / raw)
  To: Yu-Cheng Chou; +Cc: cygwin

On Sun, 10 Jul 2005, Yu-Cheng Chou wrote:

> Hi,
> In order to dynamically load cygwin1.dll with VC, I need to add 4K of
> scratch space at the bottom of my stack.
>
> The winsup/testsuite/cygload/cygload.cpp shows how to do it using C++.

I believe it's cygload.cc...

> How can I add the scratch space using C rather than C++ in a simplest
> way?

I'm afraid it won't be very simple, but how about something like

int main(int ac, char *av[]) {
    char padding[4096];
    backup_lower_stack();

    ...

    restore_lower_stack();
    return ...
}

with backup_lower_stack() and restore_lower_stack() adapted from the
cygwin::padding constructor and destructor, respectively (the vector can
be replaced by a malloc'ed piece of memory).

However, you'll also need to write a C interface to cygwin::connector.
Once you have this working, I would strongly urge you to submit the code
to Cygwin.
HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* How to add 4K of scratch space at the bottom of the stack using C instead of C++?
@ 2005-07-11  3:27 Yu-Cheng Chou
  2005-07-11  3:58 ` Igor Pechtchanski
  0 siblings, 1 reply; 16+ messages in thread
From: Yu-Cheng Chou @ 2005-07-11  3:27 UTC (permalink / raw)
  To: cygwin


Hi,
In order to dynamically load cygwin1.dll with VC, I need to add 4K of 
scratch space at the bottom of my stack.

The winsup/testsuite/cygload/cygload.cpp shows how to do it using C++.
How can I add the scratch space using C rather than C++ in a simplest way?

Thanks


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2005-07-12 22:56 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-12 18:02 How to add 4K of scratch space at the bottom of the stack using C instead of C++? Yu-Cheng Chou
2005-07-12 20:15 ` Max Kaehn
  -- strict thread matches above, loose matches on Subject: below --
2005-07-12 22:56 Yu-Cheng Chou
2005-07-11 23:14 Yu-Cheng Chou
2005-07-11 23:22 ` Max Kaehn
2005-07-11 21:46 Yu-Cheng Chou
2005-07-11 22:08 ` Max Kaehn
2005-07-12  3:44 ` Brian Dessent
2005-07-11 20:05 Yu-Cheng Chou
2005-07-11 18:55 Yu-Cheng Chou
2005-07-11 19:37 ` Max Kaehn
2005-07-11 15:42 Yu-Cheng Chou
2005-07-11 16:12 ` Igor Pechtchanski
2005-07-11 18:37   ` Max Kaehn
2005-07-11  3:27 Yu-Cheng Chou
2005-07-11  3:58 ` Igor Pechtchanski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).