github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/include/jit/jit-memory.h (about)

     1  /*
     2   * jit-memory.h - Memory management.
     3   *
     4   * Copyright (C) 2012  Aleksey Demakov
     5   *
     6   * The libjit library is free software: you can redistribute it and/or
     7   * modify it under the terms of the GNU Lesser General Public License
     8   * as published by the Free Software Foundation, either version 2.1 of
     9   * the License, or (at your option) any later version.
    10   *
    11   * The libjit library is distributed in the hope that it will be useful,
    12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14   * Lesser General Public License for more details.
    15   *
    16   * You should have received a copy of the GNU Lesser General Public
    17   * License along with the libjit library.  If not, see
    18   * <http://www.gnu.org/licenses/>.
    19   */
    20  
    21  #ifndef _JIT_MEMORY_H
    22  #define	_JIT_MEMORY_H
    23  
    24  #include <jit/jit-defs.h>
    25  
    26  #ifdef	__cplusplus
    27  extern "C" {
    28  #endif
    29  
    30  /*
    31   * Result values for "_jit_cache_start_function" and "_jit_cache_end_function".
    32   */
    33  #define	JIT_MEMORY_OK		0	/* Function is OK */
    34  #define	JIT_MEMORY_RESTART	1	/* Restart is required */
    35  #define	JIT_MEMORY_TOO_BIG	2	/* Function is too big for the cache */
    36  #define JIT_MEMORY_ERROR	3	/* Other error */
    37  
    38  typedef void *jit_memory_context_t;
    39  typedef void *jit_function_info_t;
    40  
    41  typedef struct jit_memory_manager const* jit_memory_manager_t;
    42  
    43  struct jit_memory_manager
    44  {
    45  	jit_memory_context_t (*create)(jit_context_t context);
    46  	void (*destroy)(jit_memory_context_t memctx);
    47  
    48  	jit_function_info_t (*find_function_info)(jit_memory_context_t memctx, void *pc);
    49  	jit_function_t (*get_function)(jit_memory_context_t memctx, jit_function_info_t info);
    50  	void * (*get_function_start)(jit_memory_context_t memctx, jit_function_info_t info);
    51  	void * (*get_function_end)(jit_memory_context_t memctx, jit_function_info_t info);
    52  
    53  	jit_function_t (*alloc_function)(jit_memory_context_t memctx);
    54  	void (*free_function)(jit_memory_context_t memctx, jit_function_t func);
    55  
    56  	int (*start_function)(jit_memory_context_t memctx, jit_function_t func);
    57  	int (*end_function)(jit_memory_context_t memctx, int result);
    58  	int (*extend_limit)(jit_memory_context_t memctx, int count);
    59  
    60  	void * (*get_limit)(jit_memory_context_t memctx);
    61  	void * (*get_break)(jit_memory_context_t memctx);
    62  	void (*set_break)(jit_memory_context_t memctx, void *brk);
    63  
    64  	void * (*alloc_trampoline)(jit_memory_context_t memctx);
    65  	void (*free_trampoline)(jit_memory_context_t memctx, void *ptr);
    66  
    67  	void * (*alloc_closure)(jit_memory_context_t memctx);
    68  	void (*free_closure)(jit_memory_context_t memctx, void *ptr);
    69  
    70  	void * (*alloc_data)(jit_memory_context_t memctx, jit_size_t size, jit_size_t align);
    71  };
    72  
    73  jit_memory_manager_t jit_default_memory_manager(void) JIT_NOTHROW;
    74  
    75  #ifdef	__cplusplus
    76  }
    77  #endif
    78  
    79  #endif	/* _JIT_MEMORY_H */