-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmemvms.c
More file actions
119 lines (102 loc) · 2.84 KB
/
memvms.c
File metadata and controls
119 lines (102 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
** 2013 March 8
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains the memory allocation drivers for use when running
** under OpenVMS.
*/
#include "sqliteInt.h"
/*
** This version of the memory allocator is the only one supported on
** OpenVMS, although the others do work.
*/
#ifdef VMS
#include <descrip.h>
#include <libvmdef.h>
#include <ssdef.h>
#include <starlet.h>
#include <stdlib.h>
#include <stsdef.h>
#if !defined(VAX)
# include <lib$routines.h>
#endif
static long _sqliteZone_ = 0;
static void *sqlite3MemMalloc(int nByte){
long *pNew, szNew = nByte + sizeof(int);
if( $VMS_STATUS_SUCCESS(lib$get_vm(&szNew, &pNew, &_sqliteZone_)) ){
*pNew = nByte;
return ++pNew;
}
return 0;
}
static void sqlite3MemFree(void *pPrior){
long *pOld = ((long *)pPrior) - 1, szOld = *pOld + sizeof(int);
lib$free_vm(&szOld, &pOld, &_sqliteZone_);
}
static void *sqlite3MemRealloc(void *pPrior, int nByte){
int *pOld = ((int *)pPrior) - 1, szOld = *pOld;
void *pNew;
if( nByte <= szOld ){
return pPrior;
} else {
pNew = sqlite3MemMalloc(nByte);
if (!pNew) return 0;
memcpy(pNew, pPrior, szOld);
sqlite3MemFree(pPrior);
return pNew;
}
}
static int sqlite3MemSize(void *pPrior){
if (!pPrior) return 0;
return *((int *)pPrior - 1);
}
static int sqlite3MemRoundup(int n){
return ROUND8(n);
}
static int sqlite3MemInit(void *NotUsed){
const int alg = LIB$K_VM_QUICK_FIT, arg = 16, extent = 128;
const int blocksize = 512, smallest = 8;
const int flags = LIB$M_VM_BOUNDARY_TAGS | LIB$M_VM_EXTEND_AREA
| LIB$M_VM_TAIL_LARGE;
int rc = SQLITE_OK, status;
$DESCRIPTOR(name, "Sqlite_heap");
if( _sqliteZone_ == 0){
status = lib$create_vm_zone(&_sqliteZone_, &alg, &arg, &flags, &extent,
&extent, &blocksize, 0, 0, &smallest, &name);
if( !$VMS_STATUS_SUCCESS(status) ){
rc = SQLITE_ERROR;
}
}
return rc;
}
static void sqlite3MemShutdown(void *NotUsed){
lib$delete_vm_zone(&_sqliteZone_);
}
/*
** This routine is the only routine in this file with external linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
static const sqlite3_mem_methods defaultMethods = {
sqlite3MemMalloc,
sqlite3MemFree,
sqlite3MemRealloc,
sqlite3MemSize,
sqlite3MemRoundup,
sqlite3MemInit,
sqlite3MemShutdown,
0
};
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
}
#endif /* VMS */