public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mike Giancola <mikegiancola@gmail.com>
To: cygwin@cygwin.com
Subject: another LoadLibrary question / crash (sorry)
Date: Fri, 04 Dec 2015 19:25:00 -0000	[thread overview]
Message-ID: <CAPHm_==DDJg9CKkq2OVHT=on+dmH_-A8eWZFkUsHkETG-L2gqw@mail.gmail.com> (raw)

Hi,

I apologize for asking the same question that has been asked so many
times - but I'm stuck.

I have a DLL built in Cygwin that I'm trying to call from a program
compiled in Visual Studio 2012. When I call LoadLibrary it's
successful, however calls to the APIs crash the program.

From what I've read, I understand I need to allocate "4k of scratch
space at the bottom of the stack" and call the  cygwin_dll_init first.
(From https://cygwin.com/faq/ section 6.19).

I haven't been able to find the how-cygtls-works.txt nor
winsup/testsuite/cygload - most of the links in old mail archives are
dead (some messages go back to 2007). That said, I've found cygload.cc
here: https://raw.githubusercontent.com/openunix/cygwin/master/winsup/testsuite/winsup.api/cygload.cc

Here, the code attempts to use some assembly to set the stack size:

#ifdef __GNUC__
  __asm__ (
    "movl %%fs:4, %0"
    :"=r"(stackbase)
    );
#else
  __asm
      {
        mov eax, fs:[4];
        mov stackbase, eax;
      }
#endif

However these lines crash the program. I've downloaded these exact
files (the .cc & .h) and compiled them using VS2012. When debugged /
run i get an access violation and crash. Note - i'm trying to run this
program as is, unmodified.

Is there a specific compiler flag i need to set in order to allow
these operations? I've turned off DEP, i've tried both set the entry
point to be cygloadCRTStartup then going back - reseting the entry
point and uncommenting the construction of the padding object line.
Both fail.

Does anyone happen to have a simple example - simply calling a
"fooapi" within a dll available? Is there any updated documentation
anywhere?

Thanks for the help!

mike

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

                 reply	other threads:[~2015-12-04 19:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPHm_==DDJg9CKkq2OVHT=on+dmH_-A8eWZFkUsHkETG-L2gqw@mail.gmail.com' \
    --to=mikegiancola@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).