Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / byterun / misc.h
blob7fe2cbfe35a0f65039576466d1c2d0ed8ea0703c
1 /***********************************************************************/
2 /* */
3 /* Objective Caml */
4 /* */
5 /* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
6 /* */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../LICENSE. */
11 /* */
12 /***********************************************************************/
14 /* $Id$ */
16 /* Miscellaneous macros and variables. */
18 #ifndef CAML_MISC_H
19 #define CAML_MISC_H
21 #ifndef CAML_NAME_SPACE
22 #include "compatibility.h"
23 #endif
24 #include "config.h"
26 /* Standard definitions */
28 #include <stddef.h>
29 #include <stdlib.h>
31 /* Basic types and constants */
33 typedef size_t asize_t;
35 #ifndef NULL
36 #define NULL 0
37 #endif
39 /* <private> */
40 typedef char * addr;
41 /* </private> */
43 #ifdef __GNUC__
44 /* Works only in GCC 2.5 and later */
45 #define Noreturn __attribute__ ((noreturn))
46 #else
47 #define Noreturn
48 #endif
50 /* Export control (to mark primitives and to handle Windows DLL) */
52 #if defined(_WIN32) && defined(CAML_DLL)
53 # define CAMLexport __declspec(dllexport)
54 # define CAMLprim __declspec(dllexport)
55 # if defined(IN_OCAMLRUN)
56 # define CAMLextern __declspec(dllexport) extern
57 # else
58 # define CAMLextern __declspec(dllimport) extern
59 # endif
60 #else
61 # define CAMLexport
62 # define CAMLprim
63 # define CAMLextern extern
64 #endif
66 /* Assertions */
68 /* <private> */
70 #ifdef DEBUG
71 #define CAMLassert(x) ((x) ? 0 : caml_failed_assert ( #x , __FILE__, __LINE__))
72 CAMLextern int caml_failed_assert (char *, char *, int);
73 #else
74 #define CAMLassert(x) ((void) 0)
75 #endif
77 CAMLextern void caml_fatal_error (char *msg) Noreturn;
78 CAMLextern void caml_fatal_error_arg (char *fmt, char *arg) Noreturn;
79 CAMLextern void caml_fatal_error_arg2 (char *fmt1, char *arg1,
80 char *fmt2, char *arg2) Noreturn;
82 /* Data structures */
84 struct ext_table {
85 int size;
86 int capacity;
87 void ** contents;
90 extern void caml_ext_table_init(struct ext_table * tbl, int init_capa);
91 extern int caml_ext_table_add(struct ext_table * tbl, void * data);
92 extern void caml_ext_table_free(struct ext_table * tbl, int free_entries);
94 /* GC flags and messages */
96 extern uintnat caml_verb_gc;
97 void caml_gc_message (int, char *, uintnat);
99 /* Memory routines */
101 char *caml_aligned_malloc (asize_t, int, void **);
103 #ifdef DEBUG
104 #ifdef ARCH_SIXTYFOUR
105 #define Debug_tag(x) (0xD700D7D7D700D6D7ul \
106 | ((uintnat) (x) << 16) \
107 | ((uintnat) (x) << 48))
108 #else
109 #define Debug_tag(x) (0xD700D6D7ul | ((uintnat) (x) << 16))
110 #endif /* ARCH_SIXTYFOUR */
113 00 -> free words in minor heap
114 01 -> fields of free list blocks in major heap
115 03 -> heap chunks deallocated by heap shrinking
116 04 -> fields deallocated by [caml_obj_truncate]
117 10 -> uninitialised fields of minor objects
118 11 -> uninitialised fields of major objects
119 15 -> uninitialised words of [caml_aligned_malloc] blocks
120 85 -> filler bytes of [caml_aligned_malloc]
122 special case (byte by byte):
123 D7 -> uninitialised words of [caml_stat_alloc] blocks
125 #define Debug_free_minor Debug_tag (0x00)
126 #define Debug_free_major Debug_tag (0x01)
127 #define Debug_free_shrink Debug_tag (0x03)
128 #define Debug_free_truncate Debug_tag (0x04)
129 #define Debug_uninit_minor Debug_tag (0x10)
130 #define Debug_uninit_major Debug_tag (0x11)
131 #define Debug_uninit_align Debug_tag (0x15)
132 #define Debug_filler_align Debug_tag (0x85)
134 #define Debug_uninit_stat 0xD7
136 extern void caml_set_fields (char *, unsigned long, unsigned long);
137 #endif /* DEBUG */
140 #ifndef CAML_AVOID_CONFLICTS
141 #define Assert CAMLassert
142 #endif
144 /* </private> */
146 #endif /* CAML_MISC_H */