src/audio/SDL_sysaudio.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 16 May 2013 00:43:22 -0700
changeset 7180 3733e68edbc3
parent 6885 700f1b25f77f
child 7191 75360622e65f
permissions -rw-r--r--
Fixed bug 1846 - _allmul implementation in SDL_stdlib.c doesn't clean up the stack

Colin Barrett

I see this manifest itself (VS2012 x86) as:

"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

in the first call to SDL_GetTicks in my application. The disassembly at the problem line is:

hires_now.QuadPart *= 1000;
00AD0792 push 0
00AD0794 push 3E8h
00AD0799 mov eax,dword ptr [ebp-10h]
00AD079C push eax
00AD079D mov ecx,dword ptr [hires_now]
00AD07A0 push ecx
00AD07A1 call _allmul (0AE7D40h)
00AD07A6 mov dword ptr [hires_now],eax
00AD07A9 mov dword ptr [ebp-10h],edx

Apparently _allmul should be popping the stack but isn't (other similar functions in SDL_stdlib.c - _alldiv and whatnot - DO pop the stack).

A 'ret 10h' at the end of _allmul appears to do the trick
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #ifndef _SDL_sysaudio_h
    24 #define _SDL_sysaudio_h
    25 
    26 #include "SDL_mutex.h"
    27 #include "SDL_thread.h"
    28 
    29 /* The SDL audio driver */
    30 typedef struct SDL_AudioDevice SDL_AudioDevice;
    31 #define _THIS	SDL_AudioDevice *_this
    32 
    33 /* Used by audio targets during DetectDevices() */
    34 typedef void (*SDL_AddAudioDevice)(const char *name);
    35 
    36 typedef struct SDL_AudioDriverImpl
    37 {
    38     void (*DetectDevices) (int iscapture, SDL_AddAudioDevice addfn);
    39     int (*OpenDevice) (_THIS, const char *devname, int iscapture);
    40     void (*ThreadInit) (_THIS); /* Called by audio thread at start */
    41     void (*WaitDevice) (_THIS);
    42     void (*PlayDevice) (_THIS);
    43     Uint8 *(*GetDeviceBuf) (_THIS);
    44     void (*WaitDone) (_THIS);
    45     void (*CloseDevice) (_THIS);
    46     void (*LockDevice) (_THIS);
    47     void (*UnlockDevice) (_THIS);
    48     void (*Deinitialize) (void);
    49 
    50     /* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */
    51 
    52     /* Some flags to push duplicate code into the core and reduce #ifdefs. */
    53     int ProvidesOwnCallbackThread;
    54     int SkipMixerLock;  /* !!! FIXME: do we need this anymore? */
    55     int HasCaptureSupport;
    56     int OnlyHasDefaultOutputDevice;
    57     int OnlyHasDefaultInputDevice;
    58 } SDL_AudioDriverImpl;
    59 
    60 
    61 typedef struct SDL_AudioDriver
    62 {
    63     /* * * */
    64     /* The name of this audio driver */
    65     const char *name;
    66 
    67     /* * * */
    68     /* The description of this audio driver */
    69     const char *desc;
    70 
    71     SDL_AudioDriverImpl impl;
    72 
    73     char **outputDevices;
    74     int outputDeviceCount;
    75 
    76     char **inputDevices;
    77     int inputDeviceCount;
    78 } SDL_AudioDriver;
    79 
    80 
    81 /* Streamer */
    82 typedef struct
    83 {
    84     Uint8 *buffer;
    85     int max_len;                /* the maximum length in bytes */
    86     int read_pos, write_pos;    /* the position of the write and read heads in bytes */
    87 } SDL_AudioStreamer;
    88 
    89 
    90 /* Define the SDL audio driver structure */
    91 struct SDL_AudioDevice
    92 {
    93     /* * * */
    94     /* Data common to all devices */
    95 
    96     /* The current audio specification (shared with audio thread) */
    97     SDL_AudioSpec spec;
    98 
    99     /* An audio conversion block for audio format emulation */
   100     SDL_AudioCVT convert;
   101 
   102     /* The streamer, if sample rate conversion necessitates it */
   103     int use_streamer;
   104     SDL_AudioStreamer streamer;
   105 
   106     /* Current state flags */
   107     int iscapture;
   108     int enabled;
   109     int paused;
   110     int opened;
   111 
   112     /* Fake audio buffer for when the audio hardware is busy */
   113     Uint8 *fake_stream;
   114 
   115     /* A semaphore for locking the mixing buffers */
   116     SDL_mutex *mixer_lock;
   117 
   118     /* A thread to feed the audio device */
   119     SDL_Thread *thread;
   120     SDL_threadID threadid;
   121 
   122     /* * * */
   123     /* Data private to this driver */
   124     struct SDL_PrivateAudioData *hidden;
   125 };
   126 #undef _THIS
   127 
   128 typedef struct AudioBootStrap
   129 {
   130     const char *name;
   131     const char *desc;
   132     int (*init) (SDL_AudioDriverImpl * impl);
   133     int demand_only;  /* 1==request explicitly, or it won't be available. */
   134 } AudioBootStrap;
   135 
   136 #endif /* _SDL_sysaudio_h */
   137 
   138 /* vi: set ts=4 sw=4 expandtab: */