1. Wrapping FastCGI - Function howto?
- Posted by Jeremy Cowgar <jeremy at cowga?.c?m> Apr 23, 2008
- 683 views
Hey guys, I am trying to wrap fast cgi and here's the C signature: DLLAPI int FCGX_Accept( FCGX_Stream **in, FCGX_Stream **out, FCGX_Stream **err, FCGX_ParamArray *envp); DLLAPI is nothing on Unix (where I am testing right now). I wrapped it as:
constant hAccept = define_c_func(hFcgi, "FCGX_Accept", {P, P, P, P}, I), global function FCGX_Accept() integer result atom pIn, pOut, pErr, pEnv pIn = allocate(4) pOut = allocate(4) pErr = allocate(4) pEnv = allocate(4) if c_func(hAccept, {pIn, pOut, pErr, pEnv}) >= 0 then return {pIn, pOut, pErr, pEnv} end if return 0 end function
Does that seem right? When I call this function on 3.2, I immediately get a machine level error when calling hAccept. On released 3.1, I get a glibc memory error: *** glibc detected *** exu: malloc(): memory corruption: 0x080e9990 *** ======= Backtrace: ========= /lib/libc.so.6[0xb7eaac64] /lib/libc.so.6[0xb7ead22a] /lib/libc.so.6(__libc_malloc+0x9c)[0xb7eae9ec] /lib/libc.so.6[0xb7e9b7af] /lib/libc.so.6(fopen+0x2c)[0xb7e9b87c] exu[0x8086650] /usr/lib/libfcgi.so(FCGX_PutS+0x35)[0xb7e39345] exu[0x8079feb] exu[0x807c93b] ======= Memory map: ======== 08048000-08090000 r-xp 00000000 08:01 22003817 /opt/euphoria-3.1/bin/exu 08090000-08091000 rwxp 00048000 08:01 22003817 /opt/euphoria-3.1/bin/exu 08091000-08102000 rwxp 08091000 00:00 0 [heap] b7d00000-b7d21000 rwxp b7d00000 00:00 0 b7d21000-b7e00000 ---p b7d21000 00:00 0 b7e12000-b7e1e000 r-xp 00000000 08:01 639287 /usr/lib/libgcc_s.so.1 b7e1e000-b7e1f000 rwxp 0000b000 08:01 639287 /usr/lib/libgcc_s.so.1 b7e1f000-b7e32000 r-xp 00000000 08:01 10207268 /lib/libnsl-2.7.so b7e32000-b7e34000 rwxp 00012000 08:01 10207268 /lib/libnsl-2.7.so b7e34000-b7e36000 rwxp b7e34000 00:00 0 b7e36000-b7e3e000 r-xp 00000000 08:01 6963639 /usr/lib/libfcgi.so.0.0.0 b7e3e000-b7e3f000 rwxp 00008000 08:01 6963639 /usr/lib/libfcgi.so.0.0.0 b7e3f000-b7e40000 rwxp b7e3f000 00:00 0 b7e40000-b7f7a000 r-xp 00000000 08:01 10207256 /lib/libc-2.7.so b7f7a000-b7f7b000 r-xp 0013a000 08:01 10207256 /lib/libc-2.7.so b7f7b000-b7f7d000 rwxp 0013b000 08:01 10207256 /lib/libc-2.7.so b7f7d000-b7f80000 rwxp b7f7d000 00:00 0 b7f80000-b7f82000 r-xp 00000000 08:01 10207260 /lib/libdl-2.7.so b7f82000-b7f84000 rwxp 00001000 08:01 10207260 /lib/libdl-2.7.so b7f84000-b7fa8000 r-xp 00000000 08:01 10207266 /lib/libm-2.7.so b7fa8000-b7faa000 rwxp 00023000 08:01 10207266 /lib/libm-2.7.so b7faa000-b7fab000 rwxp b7faa000 00:00 0 b7fbf000-b7fc0000 r-xp b7fbf000 00:00 0 [vdso] b7fc0000-b7fdb000 r-xp 00000000 08:01 10208712 /lib/ld-2.7.so b7fdb000-b7fdd000 rwxp 0001a000 08:01 10208712 /lib/ld-2.7.so bfb3d000-bfb52000 rw-p bffeb000 00:00 0 [stack] Any thoughts? -- Jeremy Cowgar http://jeremy.cowgar.com
2. Re: Wrapping FastCGI - Function howto?
- Posted by Bernie Ryan <xotron at bluefrog.c?m> Apr 23, 2008
- 679 views
Jeremy Cowgar wrote: > > Hey guys, > > I am trying to wrap fast cgi and here's the C signature: > > DLLAPI int FCGX_Accept( > FCGX_Stream **in, > FCGX_Stream **out, > FCGX_Stream **err, > FCGX_ParamArray *envp); > > DLLAPI is nothing on Unix (where I am testing right now). > > I wrapped it as: > > }}} <eucode> > constant hAccept = define_c_func(hFcgi, "FCGX_Accept", {P, P, P, P}, I), > > global function FCGX_Accept() > integer result > atom pIn, pOut, pErr, pEnv > > pIn = allocate(4) > pOut = allocate(4) > pErr = allocate(4) > pEnv = allocate(4) > > if c_func(hAccept, {pIn, pOut, pErr, pEnv}) >= 0 then > return {pIn, pOut, pErr, pEnv} > end if > > return 0 > end function > </eucode> {{{ > > Does that seem right? When I call this function on 3.2, I immediately get a > machine level error when calling hAccept. On released 3.1, I get a glibc > memory > error: > > *** glibc detected *** exu: malloc(): memory corruption: 0x080e9990 *** > ======= Backtrace: ========= > /lib/libc.so.6[0xb7eaac64] > /lib/libc.so.6[0xb7ead22a] > /lib/libc.so.6(__libc_malloc+0x9c)[0xb7eae9ec] > /lib/libc.so.6[0xb7e9b7af] > /lib/libc.so.6(fopen+0x2c)[0xb7e9b87c] > exu[0x8086650] > /usr/lib/libfcgi.so(FCGX_PutS+0x35)[0xb7e39345] > exu[0x8079feb] > exu[0x807c93b] > ======= Memory map: ======== > 08048000-08090000 r-xp 00000000 08:01 22003817 /opt/euphoria-3.1/bin/exu > 08090000-08091000 rwxp 00048000 08:01 22003817 /opt/euphoria-3.1/bin/exu > 08091000-08102000 rwxp 08091000 00:00 0 [heap] > b7d00000-b7d21000 rwxp b7d00000 00:00 0 > b7d21000-b7e00000 ---p b7d21000 00:00 0 > b7e12000-b7e1e000 r-xp 00000000 08:01 639287 /usr/lib/libgcc_s.so.1 > b7e1e000-b7e1f000 rwxp 0000b000 08:01 639287 /usr/lib/libgcc_s.so.1 > b7e1f000-b7e32000 r-xp 00000000 08:01 10207268 /lib/libnsl-2.7.so > b7e32000-b7e34000 rwxp 00012000 08:01 10207268 /lib/libnsl-2.7.so > b7e34000-b7e36000 rwxp b7e34000 00:00 0 > b7e36000-b7e3e000 r-xp 00000000 08:01 6963639 /usr/lib/libfcgi.so.0.0.0 > b7e3e000-b7e3f000 rwxp 00008000 08:01 6963639 /usr/lib/libfcgi.so.0.0.0 > b7e3f000-b7e40000 rwxp b7e3f000 00:00 0 > b7e40000-b7f7a000 r-xp 00000000 08:01 10207256 /lib/libc-2.7.so > b7f7a000-b7f7b000 r-xp 0013a000 08:01 10207256 /lib/libc-2.7.so > b7f7b000-b7f7d000 rwxp 0013b000 08:01 10207256 /lib/libc-2.7.so > b7f7d000-b7f80000 rwxp b7f7d000 00:00 0 > b7f80000-b7f82000 r-xp 00000000 08:01 10207260 /lib/libdl-2.7.so > b7f82000-b7f84000 rwxp 00001000 08:01 10207260 /lib/libdl-2.7.so > b7f84000-b7fa8000 r-xp 00000000 08:01 10207266 /lib/libm-2.7.so > b7fa8000-b7faa000 rwxp 00023000 08:01 10207266 /lib/libm-2.7.so > b7faa000-b7fab000 rwxp b7faa000 00:00 0 > b7fbf000-b7fc0000 r-xp b7fbf000 00:00 0 [vdso] > b7fc0000-b7fdb000 r-xp 00000000 08:01 10208712 /lib/ld-2.7.so > b7fdb000-b7fdd000 rwxp 0001a000 08:01 10208712 /lib/ld-2.7.so > bfb3d000-bfb52000 rw-p bffeb000 00:00 0 [stack] > > Any thoughts? > > -- Jeremy: pEnv should be just a pointer not a allocated location pEnv = allocate(4) Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
3. Re: Wrapping FastCGI - Function howto?
- Posted by Jeremy Cowgar <jeremy at cowga?.?om> Apr 23, 2008
- 652 views
Bernie Ryan wrote: > > Jeremy: > > pEnv should be just a pointer not a allocated location > > pEnv = allocate(4) Bernie, I have the simple wrappings down with Euphoria, but how do I give it just a pointer? -- Jeremy Cowgar http://jeremy.cowgar.com
4. Re: Wrapping FastCGI - Function howto?
- Posted by Bernie Ryan <xotron at blue?rog.c?m> Apr 23, 2008
- 653 views
Jeremy Cowgar wrote: > > Bernie Ryan wrote: > > > > Jeremy: > > > > pEnv should be just a pointer not a allocated location > > > > pEnv = allocate(4) > > Bernie, > > I have the simple wrappings down with Euphoria, but how do I give it just a > pointer? > > -- Jeremy: When you see a ** this means a POINTER to a 4-byte location in memory that contains the POINTER that the function will use. When you see a SINGLE * this means a POINTER that the function will use directly. Because I am not familiar with code you are wrapping I don't know where you obtain the Env pointer to pass to your function. But the reason a machine exception error is generaly occuring is because you are not passing the correct parameter and you are pointing to a illegeal memory location when you call the function. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
5. Re: Wrapping FastCGI - Function howto?
- Posted by Jeremy Cowgar <jeremy at cow??r.com> Apr 23, 2008
- 647 views
Bernie Ryan wrote: > > When you see a ** this means a POINTER to a 4-byte location in memory that > contains > the POINTER that the function will use. > > When you see a SINGLE * this means a POINTER that the function will use > directly. > Yes. I have been programming in C for many years. However, this is not a value passed to the FCGX_Accept function, it's a value that is populated by the FCGX_Accept function. So, I pass no data (at least no useful data) to it. It should populate it with information about the request. It will then be passed to functions yet to be wrapped such as FCGX_GetParam("QUERY_STRING", pEnv). -- Jeremy Cowgar http://jeremy.cowgar.com
6. Re: Wrapping FastCGI - Function howto?
- Posted by Bernie Ryan <xotron at blu?frog.c?m> Apr 23, 2008
- 660 views
Jeremy Cowgar wrote: > > Bernie Ryan wrote: > > > > When you see a ** this means a POINTER to a 4-byte location in memory that > > contains > > the POINTER that the function will use. > > > > When you see a SINGLE * this means a POINTER that the function will use > > directly. > > > > Yes. I have been programming in C for many years. However, this is not a value > passed to the FCGX_Accept function, it's a value that is populated by the > FCGX_Accept > function. So, I pass no data (at least no useful data) to it. > > It should populate it with information about the request. It will then be > passed > to functions yet to be wrapped such as FCGX_GetParam("QUERY_STRING", pEnv). > > -- Jeremy: Sounds to me like it's looking for a pointer to a null terminated string. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
7. Re: Wrapping FastCGI - Function howto?
- Posted by Jeremy Cowgar <jeremy at cow?ar.?om> Apr 23, 2008
- 659 views
Ok, here is an example C usage: FCGX_ParamArray envp; while (FCGX_Accept(&in, &out, &err, &envp) >= 0) { ... } FCGX_ParamArray = typedef char **FCGX_ParamArray; I'm just drawing at straws, allocating, allocating strings, string arrays, poking, poking4, etc... nothing work so far and I realize my method is terrible, but I'm not sure what to give it, thus I was hoping with wild guesses I'd get lucky, but not yet. -- Jeremy Cowgar http://jeremy.cowgar.com
8. Re: Wrapping FastCGI - Function howto?
- Posted by irv mullins <irvm at ?llijay.c?m> Apr 23, 2008
- 671 views
Looks like it is a pointer to either a string (null-terminated) or to an array. I suspect an array, which will be one or more pointers, followed by a null pointer at the end. Figuring out what type of variable each pointer leads to should be an interesting exercise.
9. Re: Wrapping FastCGI - Function howto?
- Posted by Matt Lewis <matthewwalkerlewis at gm?il?com> Apr 23, 2008
- 687 views
Jeremy Cowgar wrote: > > Ok, here is an example C usage: > > FCGX_ParamArray envp; > while (FCGX_Accept(&in, &out, &err, &envp) >= 0) { ... } > > > FCGX_ParamArray = typedef char **FCGX_ParamArray; > > I'm just drawing at straws, allocating, allocating strings, string arrays, > poking, poking4, etc... nothing work so far and I realize my method is > terrible, but I'm not sure what to give it, thus I was hoping with wild > guesses I'd get lucky, but not yet. I don't see anything obviously wrong with your wrapper. From glancing at manpages and such, it looks like all of those will be populated by FastCGI. I have two thoughts. Make sure that the memory is all zeroed out:
in = allocate(4) poke4( in, 0 ) -- .... -- or.. ptrs = allocate( 16 ) poke4( ptrs, repeat( 0, 4 ) )
If this doesn't help, then you could try running under valgrind. Print out the pointers that you're using, so you can compare to whatever error you get. You'll typically get better results, of course, if you use a debug build of euphoria. Matt
10. Re: Wrapping FastCGI - Function howto?
- Posted by gshingles <gshingles at gmail.??m> Apr 23, 2008
- 709 views
- Last edited Apr 24, 2008
Jeremy Cowgar wrote: > > Ok, here is an example C usage: > > FCGX_ParamArray envp; > while (FCGX_Accept(&in, &out, &err, &envp) >= 0) { ... } > > > FCGX_ParamArray = typedef char **FCGX_ParamArray; > > I'm just drawing at straws, allocating, allocating strings, string arrays, > poking, > poking4, etc... nothing work so far and I realize my method is terrible, but > I'm not sure what to give it, thus I was hoping with wild guesses I'd get > lucky, > but not yet. Where I come from envp is the pointer to the environment variables. It if is that then it's a pointer to a null terminated array of null terminated strings ie char **envp; This would make sense for a CGI library, maybe it wants a pointer to the environment block, or maybe it wants to give you one from where the query is coming from? Gary
11. Re: Wrapping FastCGI - Function howto?
- Posted by Jeremy Cowgar <jeremy at cowgar.?om> Apr 23, 2008
- 661 views
- Last edited Apr 24, 2008
gshingles wrote: > > > Where I come from envp is the pointer to the environment variables. > It if is that then it's a pointer to a null terminated array of null > terminated > strings > ie char **envp; > > This would make sense for a CGI library, maybe it wants a pointer to the > environment block, or maybe it wants to give you one from where the > query is coming from? > Gary, Yes, it's the environment. It want's to populate that array with the environment as the FastCGI application may be running locally, under it's own session, or it could be running on a totally different server in another country. So, it passes the web servers environment to your application via the FCGX_Accept function. I have yet to make this work, btw... I get various memory errors. I have not been working on it solid, only touching it here and there between my real job. FastCGI or SCGI would be very nice to have for Euphoria. I am really surprised it has not been done already. -- Jeremy Cowgar http://jeremy.cowgar.com
12. Re: Wrapping FastCGI - Function howto?
- Posted by Jason Gade <jaygade at ?ah?o.com> Apr 24, 2008
- 671 views
Jeremy Cowgar wrote: > > gshingles wrote: > > > > > > Where I come from envp is the pointer to the environment variables. > > It if is that then it's a pointer to a null terminated array of null > > terminated > > strings > > ie char **envp; > > > > This would make sense for a CGI library, maybe it wants a pointer to the > > environment block, or maybe it wants to give you one from where the > > query is coming from? > > > > Gary, > > Yes, it's the environment. It want's to populate that array with the > environment > as the FastCGI application may be running locally, under it's own session, or > it could be running on a totally different server in another country. So, it > passes the web servers environment to your application via the FCGX_Accept > function. > > I have yet to make this work, btw... I get various memory errors. I have > not been working on it solid, only touching it here and there between my real > job. FastCGI or SCGI would be very nice to have for Euphoria. I am really > surprised > it has not been done already. > > -- > Jeremy Cowgar > <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a> Maybe you need to allocate a large enough area for the environment and then allocate a pointer for the environment? Then again, isn't a pointer to the environment passed to the C main() statement? No, I see that that's a windows extension for winmain(). That's all I got. -- A complex system that works is invariably found to have evolved from a simple system that works. --John Gall's 15th law of Systemantics. "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.