How can you determine the stack usage of a function call from an API that has been provided to you? You do not know what the function looks like and you have access only to the API. For example,
int main() {
// call some API function
some_func_called();
// rest of your main
}
The only thing that I can think of is by populating the stack memory with a known pattern before calling the function and later checking the stack to see how many bytes of the the known pattern was changed after the function returns. Any other ideas? (This was an interview question)
Something like this, not fully tested, may have limit problems. Only works if stack pointer decreases by PUSHING, so this is not portable across all hardware…