__stdcall alternative

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bartc

    __stdcall alternative

    I'm mixing C and ASM, and for calling ASM from C, I just happened to use the
    __stdcall convention (using C convention is not practical for other
    reasons).

    But, __stdcall seems to assume that machine registers are saved by the
    called routine (as far as I can gather after a few hours messing with some
    strange behaviours especially with optimised C code).

    Is there any other call convention I can use likely to be commonly
    available?

    Or is there a way of specifying that an external function does not save
    registers or is badly behaved?


    --
    Thanks,

    Bartc


  • Ian Collins

    #2
    Re: __stdcall alternative

    Bartc wrote:
    I'm mixing C and ASM, and for calling ASM from C, I just happened to use the
    __stdcall convention (using C convention is not practical for other
    reasons).
    >
    What is __stdcall? It's not C, so it must be platform specific, try a
    group for your platform, you'll get more help there.

    --
    Ian Collins.

    Comment

    • jacob navia

      #3
      Re: __stdcall alternative

      Bartc wrote:
      I'm mixing C and ASM, and for calling ASM from C, I just happened to use the
      __stdcall convention (using C convention is not practical for other
      reasons).
      >
      But, __stdcall seems to assume that machine registers are saved by the
      called routine (as far as I can gather after a few hours messing with some
      strange behaviours especially with optimised C code).
      >
      OBVIOUSLY you should save the registers ytour compiler thinks are permanent

      Under windows (where stdcall is commonly used) you should save
      (I am assuming 64 bit CPU)

      rsi
      rdi
      rbx
      r12-r15
      rbp

      And at the end you should issue a
      ret $8

      when you receive 8 bytes of arguments for instance.
      Is there any other call convention I can use likely to be commonly
      available?
      >
      you could just as well use the C calling convention. The registers to save
      are THE SAME but you should just issue

      ret
      and the called procedure adjusts the stack.

      Or is there a way of specifying that an external function does not save
      registers or is badly behaved?
      >
      There is NO way to do that. YOU HAVE TO SAVE THOSE if not
      you will just have a crash.

      >

      --
      jacob navia
      jacob at jacob point remcomp point fr
      logiciels/informatique

      Comment

      • jacob navia

        #4
        Re: __stdcall alternative

        Ian Collins wrote:
        Bartc wrote:
        >I'm mixing C and ASM, and for calling ASM from C, I just happened to use the
        >__stdcall convention (using C convention is not practical for other
        >reasons).
        >>
        What is __stdcall?
        What's the point of showing your ignorance as it was a quality?

        You do not know the subject matter?

        Just stay silent! Is that too complicated?

        It's not C,
        Of course it is. It is a common extension.
        so it must be platform specific,
        no, it isn't



        --
        jacob navia
        jacob at jacob point remcomp point fr
        logiciels/informatique

        Comment

        • Antoninus Twink

          #5
          Re: __stdcall alternative

          On 24 Apr 2008 at 20:56, jacob navia wrote:
          Bartc wrote:
          >Or is there a way of specifying that an external function does not save
          >registers or is badly behaved?
          >>
          >
          There is NO way to do that. YOU HAVE TO SAVE THOSE if not
          you will just have a crash.
          It sounded to me like the external function isn't one he's written, and
          he can't control its behavior. If that's the case, there's nothing for
          it except to work out what calling convention the function expects, and
          use that.

          Comment

          • Eric Sosman

            #6
            Re: __stdcall alternative

            jacob navia wrote:
            Ian Collins wrote:
            >Bartc wrote:
            >>I'm mixing C and ASM, and for calling ASM from C, I just happened to
            >>use the __stdcall convention (using C convention is not practical for
            >>other reasons).
            >>>
            >What is __stdcall?
            >
            What's the point of showing your ignorance as it was a quality?
            >
            You do not know the subject matter?
            >
            Just stay silent! Is that too complicated?
            >
            >
            >It's not C,
            >
            Of course it is. It is a common extension.
            >
            >so it must be platform specific,
            >
            no, it isn't
            Oh, good! Then I'll start using it right away!

            % cat foo.c
            extern void __stdcall foo(void);
            % cc foo.c
            "foo.c", line 1: syntax error before or at: foo
            "foo.c", line 1: warning: old-style declaration or incorrect type for: foo
            cc: acomp failed for foo.c
            %

            Hmmm -- Something seems to be amiss. I'll try a
            different machine and a different compiler:
            >gcc foo.c
            foo.c:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before
            'foo'

            What am I doing wrong? You've said __stdcall isn't
            platform-specific, but I've tried two platforms and it doesn't
            work on either of them!

            --
            Eric.Sosman@sun .com

            Comment

            • Keith Thompson

              #7
              Re: __stdcall alternative

              jacob navia <jacob@nospam.c omwrites:
              Ian Collins wrote:
              >Bartc wrote:
              >>I'm mixing C and ASM, and for calling ASM from C, I just happened
              >>to use the __stdcall convention (using C convention is not
              >>practical for other reasons).
              >>>
              >What is __stdcall?
              >
              What's the point of showing your ignorance as it was a quality?
              >
              You do not know the subject matter?
              >
              Just stay silent! Is that too complicated?
              >
              >
              >It's not C,
              >
              Of course it is. It is a common extension.
              >
              >so it must be platform specific,
              >
              no, it isn't
              "_stdcall" isn't platform-specific? Seriously?

              --
              Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
              Nokia
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              • jacob navia

                #8
                Re: __stdcall alternative

                Eric Sosman wrote:
                jacob navia wrote:
                >Ian Collins wrote:
                >>Bartc wrote:
                >>>I'm mixing C and ASM, and for calling ASM from C, I just happened to
                >>>use the __stdcall convention (using C convention is not practical
                >>>for other reasons).
                >>>>
                >>What is __stdcall?
                >>
                >What's the point of showing your ignorance as it was a quality?
                >>
                >You do not know the subject matter?
                >>
                >Just stay silent! Is that too complicated?
                >>
                >>
                >>It's not C,
                >>
                >Of course it is. It is a common extension.
                >>
                >>so it must be platform specific,
                >>
                >no, it isn't
                >
                Oh, good! Then I'll start using it right away!
                >
                % cat foo.c
                extern void __stdcall foo(void);
                % cc foo.c
                "foo.c", line 1: syntax error before or at: foo
                "foo.c", line 1: warning: old-style declaration or incorrect type for: foo
                cc: acomp failed for foo.c
                %
                >
                Hmmm -- Something seems to be amiss. I'll try a
                different machine and a different compiler:
                >
                >gcc foo.c
                foo.c:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before
                'foo'
                >
                What am I doing wrong? You've said __stdcall isn't
                platform-specific, but I've tried two platforms and it doesn't
                work on either of them!
                >
                If you use gcc you should
                #ifndef STDCALL
                #define STDCALL __attribute__(( stdcall))
                #endif
                >What's the point of showing your ignorance as it was a quality?
                >>
                >You do not know the subject matter?
                >>
                >Just stay silent! Is that too complicated?

                --
                jacob navia
                jacob at jacob point remcomp point fr
                logiciels/informatique

                Comment

                • jacob navia

                  #9
                  Re: __stdcall alternative

                  Keith Thompson wrote:
                  jacob navia <jacob@nospam.c omwrites:
                  >Ian Collins wrote:
                  >>Bartc wrote:
                  >>>I'm mixing C and ASM, and for calling ASM from C, I just happened
                  >>>to use the __stdcall convention (using C convention is not
                  >>>practical for other reasons).
                  >>>>
                  >>What is __stdcall?
                  >What's the point of showing your ignorance as it was a quality?
                  >>
                  >You do not know the subject matter?
                  >>
                  >Just stay silent! Is that too complicated?
                  >>
                  >>
                  >>It's not C,
                  >Of course it is. It is a common extension.
                  >>
                  >>so it must be platform specific,
                  >no, it isn't
                  >
                  "_stdcall" isn't platform-specific? Seriously?
                  >
                  #ifndef STDCALL
                  #define STDCALL __attribute__(( stdcall))
                  #endif


                  --
                  jacob navia
                  jacob at jacob point remcomp point fr
                  logiciels/informatique

                  Comment

                  • Eric Sosman

                    #10
                    Re: __stdcall alternative

                    jacob navia wrote:
                    Eric Sosman wrote:
                    >jacob navia wrote:
                    >>Ian Collins wrote:
                    >>>Bartc wrote:
                    >>>>I'm mixing C and ASM, and for calling ASM from C, I just happened
                    >>>>to use the __stdcall convention (using C convention is not
                    >>>>practical for other reasons).
                    >>>>>
                    >>>What is __stdcall?
                    >>>
                    >>What's the point of showing your ignorance as it was a quality?
                    >>>
                    >>You do not know the subject matter?
                    >>>
                    >>Just stay silent! Is that too complicated?
                    >>>
                    >>>
                    >>>It's not C,
                    >>>
                    >>Of course it is. It is a common extension.
                    >>>
                    >>>so it must be platform specific,
                    >>>
                    >>no, it isn't
                    >>
                    > Oh, good! Then I'll start using it right away!
                    >>
                    >% cat foo.c
                    >extern void __stdcall foo(void);
                    >% cc foo.c
                    >"foo.c", line 1: syntax error before or at: foo
                    >"foo.c", line 1: warning: old-style declaration or incorrect type for:
                    >foo
                    >cc: acomp failed for foo.c
                    >%
                    >>
                    > Hmmm -- Something seems to be amiss. I'll try a
                    >different machine and a different compiler:
                    >>
                    > >gcc foo.c
                    >foo.c:1: error: expected '=', ',', ';', 'asm' or '__attribute__'
                    >before 'foo'
                    >>
                    > What am I doing wrong? You've said __stdcall isn't
                    >platform-specific, but I've tried two platforms and it doesn't
                    >work on either of them!
                    >>
                    >
                    If you use gcc you should
                    #ifndef STDCALL
                    #define STDCALL __attribute__(( stdcall))
                    #endif
                    ... but you said __stdcall wasn't platform-specific, so
                    why do I have to write __attribute__(( stdcall)) instead? And
                    what about the other platform I tried?

                    --
                    Eric.Sosman@sun .com

                    Comment

                    • Keith Thompson

                      #11
                      Re: __stdcall alternative

                      jacob navia <jacob@nospam.c omwrites:
                      Keith Thompson wrote:
                      >jacob navia <jacob@nospam.c omwrites:
                      >>Ian Collins wrote:
                      >>>Bartc wrote:
                      >>>>I'm mixing C and ASM, and for calling ASM from C, I just happened
                      >>>>to use the __stdcall convention (using C convention is not
                      >>>>practical for other reasons).
                      >>>>>
                      >>>What is __stdcall?
                      >>What's the point of showing your ignorance as it was a quality?
                      >>>
                      >>You do not know the subject matter?
                      >>>
                      >>Just stay silent! Is that too complicated?
                      >>>
                      >>>It's not C,
                      >>Of course it is. It is a common extension.
                      >>>
                      >>>so it must be platform specific,
                      >>no, it isn't
                      >>
                      >"_stdcall" isn't platform-specific? Seriously?
                      >>
                      #ifndef STDCALL
                      #define STDCALL __attribute__(( stdcall))
                      #endif
                      What does defining "STDCALL" have to do with "__stdcall" ? They're two
                      different identifiers, you know.

                      I suppose your point is that gcc supports a feature that's similar to
                      "__stdcall" , but uses the syntax "__attribute__( (stdcall))". So two
                      different platforms support a similar feature using radically
                      different syntax. If I were sufficiently motivated, I'm sure I could
                      find another platform that either supports it with yet another
                      different syntax, or doesn't support it at all.

                      "__stdcall" is platform-specific.

                      --
                      Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
                      Nokia
                      "We must do something. This is something. Therefore, we must do this."
                      -- Antony Jay and Jonathan Lynn, "Yes Minister"

                      Comment

                      • Ian Collins

                        #12
                        Re: __stdcall alternative

                        jacob navia wrote:
                        Ian Collins wrote:
                        >Bartc wrote:
                        >>I'm mixing C and ASM, and for calling ASM from C, I just happened to
                        >>use the __stdcall convention (using C convention is not practical for
                        >>other reasons).
                        >>>
                        >What is __stdcall?
                        >
                        >
                        Just stay silent! Is that too complicated?
                        >
                        Fool, if you read the bit of my post you snipped - "try a group for your
                        platform, you'll get more help there." - you would see I was attempting
                        to help the OP.
                        >
                        >It's not C,
                        >
                        Of course it is. It is a common extension.
                        >
                        Not on any platform I use, and that's quite a few.
                        >so it must be platform specific,
                        >
                        no, it isn't
                        >
                        Eric's already shown you that is is.

                        --
                        Ian Collins.

                        Comment

                        • jacob navia

                          #13
                          Re: __stdcall alternative

                          Eric Sosman wrote:
                          ... but you said __stdcall wasn't platform-specific, so
                          why do I have to write __attribute__(( stdcall)) instead? And
                          what about the other platform I tried?
                          >
                          Go to the kindergarten then. There you will find all answers



                          --
                          jacob navia
                          jacob at jacob point remcomp point fr
                          logiciels/informatique

                          Comment

                          • jacob navia

                            #14
                            Re: __stdcall alternative

                            Keith Thompson wrote:
                            jacob navia <jacob@nospam.c omwrites:
                            >Keith Thompson wrote:
                            >>jacob navia <jacob@nospam.c omwrites:
                            >>>Ian Collins wrote:
                            >>>>Bartc wrote:
                            >>>>>I'm mixing C and ASM, and for calling ASM from C, I just happened
                            >>>>>to use the __stdcall convention (using C convention is not
                            >>>>>practica l for other reasons).
                            >>>>>>
                            >>>>What is __stdcall?
                            >>>What's the point of showing your ignorance as it was a quality?
                            >>>>
                            >>>You do not know the subject matter?
                            >>>>
                            >>>Just stay silent! Is that too complicated?
                            >>>>
                            >>>>It's not C,
                            >>>Of course it is. It is a common extension.
                            >>>>
                            >>>>so it must be platform specific,
                            >>>no, it isn't
                            >>"_stdcall" isn't platform-specific? Seriously?
                            >>>
                            >#ifndef STDCALL
                            >#define STDCALL __attribute__(( stdcall))
                            >#endif
                            >
                            What does defining "STDCALL" have to do with "__stdcall" ? They're two
                            different identifiers, you know.
                            >
                            I suppose your point is that gcc supports a feature that's similar to
                            "__stdcall" , but uses the syntax "__attribute__( (stdcall))". So two
                            different platforms support a similar feature using radically
                            different syntax. If I were sufficiently motivated, I'm sure I could
                            find another platform that either supports it with yet another
                            different syntax, or doesn't support it at all.
                            >
                            "__stdcall" is platform-specific.
                            >
                            What piss me off of this regulars is that when they are proved
                            wrong they insist



                            --
                            jacob navia
                            jacob at jacob point remcomp point fr
                            logiciels/informatique

                            Comment

                            • jacob navia

                              #15
                              Re: __stdcall alternative

                              Ian Collins wrote:
                              jacob navia wrote:
                              >Ian Collins wrote:
                              >>Bartc wrote:
                              >>>I'm mixing C and ASM, and for calling ASM from C, I just happened to
                              >>>use the __stdcall convention (using C convention is not practical for
                              >>>other reasons).
                              >>>>
                              >>What is __stdcall?
                              >>
                              >Just stay silent! Is that too complicated?
                              >>
                              Fool, if you read the bit of my post you snipped - "try a group for your
                              platform, you'll get more help there." - you would see I was attempting
                              to help the OP.
                              >
                              >>It's not C,
                              >Of course it is. It is a common extension.
                              >>
                              Not on any platform I use, and that's quite a few.
                              >
                              >>so it must be platform specific,
                              >no, it isn't
                              >>
                              Eric's already shown you that is is.
                              >
                              And I showed Eric and you and Thompson that is supported
                              on gcc/MSVC/Lcc-win/Watcom/Borland and what have you

                              what piss me off of this regulars is that when proved wrong
                              they insist


                              --
                              jacob navia
                              jacob at jacob point remcomp point fr
                              logiciels/informatique

                              Comment

                              Working...