Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: localhost.localdomain: ronald owned process doing -bs Date: Wed, 12 Mar 2003 18:26:07 +0100 (CET) From: Ronald Landheer-Cieslak X-X-Sender: ronald AT localhost DOT localdomain To: Nicholas Burton cc: cygwin AT cygwin DOT com Subject: Re: JNI multiple String problem In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII I've built a debug version of Cygwin and straced it to some weirdness.. (You're lucky I'm working on JNI at the moment too ;) First off: when running in rxvt, Cygwin segfaults just after fstat()ing stdout. Here's the strace output: --- BEGIN strace output --- 44494 [main] ? 195 normalize_posix_path: src /dev/pipew 44641 [main] ? 195 normalize_posix_path: /dev/pipew = normalize_posix_path (/dev/pipew) 44724 [main] ? 195 mount_info::conv_to_win32_path: conv_to_win32_path (/dev/pipew) 44808 [main] ? 195 mount_info::conv_to_win32_path: src_path /dev/pipew, dst \dev\pipew, flags 0x2, rc 0 44888 [main] ? 195 fhandler_base::fstat: here 44969 [main] ? 195 fstat64: 0 = fstat (1, 0x6E46C) 78745 [sig] p3 195 wait_sig: sigcatch_nonmain 0x450, sigcatch_main 0x460 78899 [sig] p3 195 wait_sig: Ready. dwProcessid 195 ---- END strace output ---- This doesn't happen when running in a "normal" command window - i.e. from cmd.exe. I don't know why (yet). A well-placed addr2line command gives me this ~/src/winsup/cygwin/pinfo.h:171 as the source of the error. (the ~ being the relative path to the sources from CVS) I didn't dive any deeper than that. Under cmd.exe, the DLL is loaded & run just fine (for the single-string native function), with one exception: you *must not* free the UTF strings, even if they were copied. You'll find this doesn't work under MSVC either (if you compile in Debug mode). This is because you'll try to free memory that is not actually yours (I don't know *why* it's not yours - and it's a WAG that is isn't, but hey...) For the function with two parameters, it gets weird: the DLL crashes and Java tells me the address it was executing is exactly one byte off utf_string2 - I've edited the code a bit like so: utf_string2 = (*env)->GetStringUTFChars(env, str2, &isCopy2); printf("0x%.8X\n", (int)utf_string2); printf("%s\n", utf_string2); This displays: | 0x0006FA5C | (garbage) | An unexpected exception has been detected in native code outside the VM. | Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6FA5D | Function=[Unknown.] | Library=(N/A) It *does* reach the following line, though (some well-placed printf("ping!\n"); statements show that much) and as I commented out the rest, that is effectively the last command in the function. This brings me to the calling convention used: Java expects stdcall, but with names with leading underscores. gcc doesn't produce it like that, but using the -mrtd option to gcc fixes the problem. That makes the gcc command-line as follows: $ gcc -mrtd -g -c nativ.c $ gcc -shared -g -o cygnativ.dll nativ.o which fixes the last problems. Note that it still won't work from a Cygwin terminal (and I still don't know why not) but it will work from cmd. HTH rlc On Wed, 12 Mar 2003, Ronald Landheer-Cieslak wrote: > On Wed, 12 Mar 2003, Nicholas Burton wrote: > [snip minimal description of problem] > > > I am using: > > gcc version 3.2 20020927 (prerelease) that came with cygwin. > > (I installed cygwin from the cygwin.exe file in January 2003) > ^^^^^^^^^^ > Don't you mean "with the setup.exe program"? > If not, install Cygwin with the "Install Cygwin now" link on > http://www.cygwin.com/ > > [snipped rest] > > I'll have a look at the sources you send - I'll get back to you if I see > anything. Next time, please attach them so they won't confuse the search > engine of the mailing list archives. > > rlc > > > > -- > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > Bug reporting: http://cygwin.com/bugs.html > Documentation: http://cygwin.com/docs.html > FAQ: http://cygwin.com/faq/ > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/