403Webshell
Server IP : 172.67.216.182  /  Your IP : 172.71.124.10
Web Server : Apache
System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /www/server/mysql/src/sql/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/server/mysql/src/sql/malloc_allocator.h
/* Copyright (c) 2014, 2023, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef MALLOC_ALLOCATOR_INCLUDED
#define MALLOC_ALLOCATOR_INCLUDED

#include "my_global.h"
#include "my_sys.h"

#include <new>
#include <limits>


/**
  Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.

  This allows for P_S instrumentation of memory allocation done by
  internally by STL container classes.

  Example usage:
  vector<int, Malloc_allocator<int> >
    v((Malloc_allocator<int>(PSI_NOT_INSTRUMENTED)));

  @note allocate() throws std::bad_alloc() similarly to the default
  STL memory allocator. This is necessary - STL functions which allocates
  memory expects it. Otherwise these functions will try to use the memory,
  leading to seg faults if memory allocation was not successful.

  @note This allocator cannot be used for std::basic_string
  because of this libstd++ bug:
  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56437
  "basic_string assumes that allocators are default-constructible"
*/

template <class T> class Malloc_allocator
{
  // This cannot be const if we want to be able to swap.
  PSI_memory_key m_key;

public:
  typedef T value_type;
  typedef size_t size_type;
  typedef ptrdiff_t difference_type;

  typedef T* pointer;
  typedef const T* const_pointer;

  typedef T& reference;
  typedef const T& const_reference;

  pointer address(reference r) const { return &r; }
  const_pointer address(const_reference r) const { return &r; }

  explicit Malloc_allocator(PSI_memory_key key) : m_key(key)
  {}

  template <class U> Malloc_allocator(const Malloc_allocator<U> &other)
    : m_key(other.psi_key())
  {}

  template <class U> Malloc_allocator & operator=
    (const Malloc_allocator<U> &other)
  {
    assert(m_key == other.psi_key()); // Don't swap key.
  }

  ~Malloc_allocator()
  {}

  pointer allocate(size_type n, const_pointer hint= 0)
  {
    if (n == 0)
      return NULL;
    if (n > max_size())
      throw std::bad_alloc();

    pointer p= static_cast<pointer>(my_malloc(m_key, n * sizeof(T),
                                              MYF(MY_WME | ME_FATALERROR)));
    if (p == NULL)
      throw std::bad_alloc();
    return p;
  }

  void deallocate(pointer p, size_type n) { my_free(p); }

  void construct(pointer p, const T& val)
  {
    assert(p != NULL);
    try {
      new(p) T(val);
    } catch (...) {
      assert(false); // Constructor should not throw an exception.
    }
  }

  void destroy(pointer p)
  {
    assert(p != NULL);
    try {
      p->~T();
    } catch (...) {
      assert(false); // Destructor should not throw an exception
    }
  }

  size_type max_size() const
  {
    return std::numeric_limits<size_t>::max() / sizeof(T);
  }

  template <class U> struct rebind { typedef Malloc_allocator<U> other; };

  PSI_memory_key psi_key() const { return m_key; }
};

template <class T>
bool operator== (const Malloc_allocator<T>& a1, const Malloc_allocator<T>& a2)
{
  return a1.psi_key() == a2.psi_key();
}

template <class T>
bool operator!= (const Malloc_allocator<T>& a1, const Malloc_allocator<T>& a2)
{
  return a1.psi_key() != a2.psi_key();
}

#endif // MALLOC_ALLOCATOR_INCLUDED

Youez - 2016 - github.com/yon3zu
LinuXploit