~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/check_stack_overrun.cc

  • Committer: Brian Aker
  • Date: 2010-02-10 18:04:24 UTC
  • mfrom: (1286.1.5 build)
  • Revision ID: brian@gaz-20100210180424-03ypoyifmlc2lgcp
Merge of Brian/Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include "drizzled/internal/my_sys.h"
 
22
#include <drizzled/definitions.h>
 
23
#include <drizzled/session.h>
 
24
#include <drizzled/error.h>
 
25
#include <drizzled/check_stack_overrun.h>
 
26
 
 
27
namespace drizzled
 
28
{
 
29
 
 
30
/****************************************************************************
 
31
        Check stack size; Send error if there isn't enough stack to continue
 
32
****************************************************************************/
 
33
#if STACK_DIRECTION < 0
 
34
#define used_stack(A,B) (long) (A - B)
 
35
#else
 
36
#define used_stack(A,B) (long) (B - A)
 
37
#endif
 
38
 
 
39
extern size_t my_thread_stack_size;
 
40
 
 
41
bool check_stack_overrun(Session *session, long margin, void *)
 
42
{
 
43
  long stack_used;
 
44
  assert(session == current_session);
 
45
  if ((stack_used=used_stack(session->thread_stack,(char*) &stack_used)) >=
 
46
      (long) (my_thread_stack_size - margin))
 
47
  {
 
48
    my_printf_error(ER_STACK_OVERRUN_NEED_MORE, ER(ER_STACK_OVERRUN_NEED_MORE),
 
49
                    MYF(ME_FATALERROR),
 
50
                    stack_used,my_thread_stack_size,margin);
 
51
    return true;
 
52
  }
 
53
  return false;
 
54
}
 
55
 
 
56
} /* namespace drizzled */