File: mlk_pvtblk_create.c

package info (click to toggle)
fis-gtm 6.3-007-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,284 kB
  • sloc: ansic: 328,861; asm: 5,182; csh: 5,102; sh: 1,918; awk: 291; makefile: 69; sed: 13
file content (150 lines) | stat: -rwxr-xr-x 4,484 bytes parent folder | download
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/****************************************************************
 *								*
 * Copyright (c) 2001-2018 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include "gtm_string.h"
#include <stdarg.h>

#include "error.h"
#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsfhead.h"
#include "filestruct.h"
#include "mlkdef.h"
#include "mlk_ops.h"
#include "mlk_region_lookup.h"
#include "mlk_pvtblk_insert.h"
#include "mlk_pvtblk_create.h"
#include "mmrhash.h"
#include "dpgbldir.h"
#include "gtm_reservedDB.h"
/* The header files below are for environment translation*/
#include "lv_val.h"	/* needed for "fgncalsp.h" */
#include "fgncalsp.h"
#include "gtm_env_xlate_init.h"

GBLREF gd_addr		*gd_header;

error_def(ERR_LOCKSUB2LONG);
error_def(ERR_PCTYRESERVED);
error_def(ERR_TEXT);

/*
 * ---------------------------------------------------------
 * Create a private block structure for one nref,
 * given by the subptr.
 *
 * Arguments:
 *	subptr	- address of 1st element of nref
 *
 * NOTE:
 *	See the description of nref in Technical Specification
 *	for Mumps Lock by R. Shear
 *	In short, each nref consists of:
 *		1. longword = number of MVALs in this nref.
 *		2. Address of external global.
 *		3-n. Variable length list of pointers to mvals in this nref.
 * ---------------------------------------------------------
 */
void	mlk_pvtblk_create (int subcnt, mval *extgbl1, va_list subptr)
{
	va_list		mp;
	int		i, len;
	unsigned char	*cp, *cp_prev;
	mval		*extgbl2, *mp_temp, val_xlated;
	mlk_pvtblk	*r;
	gd_region	*reg;
	gd_addr		*gld;
	hash128_state_t	accstate, tmpstate;
	gtm_uint16	hashres;

	/* Get count of mvals including extgbl1 */
	assert (subcnt >= 2);
	subcnt--;
	/* compiler gives us extgbl1 always, even if the nref is not an extended ref */
	if (NULL == extgbl1)
	{	/* not an extended reference */
		if (!gd_header)
			gvinit();
		gld = gd_header;
	} else
	{
		MV_FORCE_STR(extgbl1);
		extgbl2 = va_arg(subptr, mval *);
		subcnt--;
		extgbl1 = gtm_env_translate(extgbl1, extgbl2, &val_xlated);
		if (extgbl1->str.len)
			gld = zgbldir(extgbl1);
		else
		{
			if (!gd_header)
				gvinit();
			gld = gd_header;
		}
	}
	VAR_COPY(mp, subptr);
	mp_temp = va_arg(mp, mval *);
	MV_FORCE_STR(mp_temp);
	/* If specified var name is global ^%Y*, the name is illegal to use in a LOCK command.
	 * Ths first byte is '^' so skip it in the comparison.
	 */
	if ((RESERVED_NAMESPACE_LEN <= (mp_temp->str.len - 1)) && (0 == MEMCMP_LIT(mp_temp->str.addr + 1, RESERVED_NAMESPACE)))
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_PCTYRESERVED);
	reg = mlk_region_lookup((mp_temp), gld);
	/* Add up the sizes of all MVAL strings */
	for (len = 0, i = 0;  i < subcnt;  mp_temp=va_arg(mp, mval *), i++)
	{
		MV_FORCE_STR(mp_temp);
		if ((mp_temp)->str.len > 255)
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_LOCKSUB2LONG, 1, (mp_temp)->str.len,
				      ERR_TEXT, 2, (mp_temp)->str.len, (mp_temp)->str.addr);
		assert((mp_temp)->mvtype & MV_STR);
		len += (int)(mp_temp)->str.len;
	}
	va_end(mp);
	/*
	 * Allocate a buffer for all mval strings.
	 * All strings are stored one after another in the buffer.
	 * Each string is preceeded by 1 byte string len.
	 */
	MLK_PVTBLK_ALLOC(len + subcnt, subcnt, 0, r);
	r->translev = 1;
	r->subscript_cnt = subcnt;
	/* Each string is preceeded by string length byte */
	r->nref_length = len + subcnt;
	/* Keep the hash code generation here in sync with MLK_PVTBLK_SUBHASH_GEN() */
	HASH128_STATE_INIT(accstate, 0);
	cp = &r->value[0];
	/* Copy all strings into the buffer one after another */
	for (i = 0, VAR_COPY(mp, subptr);  i < subcnt;  i++)
	{
		cp_prev = cp;
		mp_temp = va_arg(mp, mval *);
		MV_FORCE_STR(mp_temp);
		len = (int)(mp_temp)->str.len;
		*cp++ = len;
		memcpy(cp, (mp_temp)->str.addr, len);
		cp += len;
		gtmmrhash_128_ingest(&accstate, cp_prev, len + 1);
		tmpstate = accstate;
		gtmmrhash_128_result(&tmpstate, (cp - r->value), &hashres);
		MLK_PVTBLK_SUBHASH(r, i) = (uint4)hashres.one;
	}
	va_end(mp);
	MLK_PVTCTL_INIT(r->pvtctl, reg);
	if (!mlk_pvtblk_insert(r))
		free(r);
	return;
}