Drizzled Public API Documentation

check_stack_overrun.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 #include <drizzled/internal/my_sys.h>
00022 #include <drizzled/definitions.h>
00023 #include <drizzled/session.h>
00024 #include <drizzled/error.h>
00025 #include <drizzled/check_stack_overrun.h>
00026 
00027 namespace drizzled
00028 {
00029 
00030 /****************************************************************************
00031   Check stack size; Send error if there isn't enough stack to continue
00032 ****************************************************************************/
00033 #if defined(STACK_DIRECTION) && (STACK_DIRECTION < 0)
00034 static const bool stack_direction_negative = true;
00035 #else
00036 static const bool stack_direction_negative = false;
00037 #endif
00038 
00039 template <typename A_T, typename B_T>
00040 inline static long used_stack(A_T A, B_T B)
00041 {
00042   if (stack_direction_negative)
00043     return (long) (A - B);
00044   else
00045     return (long) (B - A);
00046 }
00047 
00048 extern size_t my_thread_stack_size;
00049 
00050 bool check_stack_overrun(Session *session, long margin, void *)
00051 {
00052   long stack_used;
00053   if ((stack_used=used_stack(session->thread_stack,(char*) &stack_used)) >=
00054       (long) (my_thread_stack_size - margin))
00055   {
00056     my_printf_error(ER_STACK_OVERRUN_NEED_MORE, ER(ER_STACK_OVERRUN_NEED_MORE),
00057                     MYF(ME_FATALERROR),
00058                     stack_used,my_thread_stack_size,margin);
00059     return true;
00060   }
00061   return false;
00062 }
00063 
00064 } /* namespace drizzled */