1 /******************************************************************************
3 * Module Name: exstorob - AML Interpreter object store support, store to object
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __EXSTOROB_C__
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exstorob")
55 /*******************************************************************************
57 * FUNCTION: AcpiExStoreBufferToBuffer
59 * PARAMETERS: SourceDesc - Source object to copy
60 * TargetDesc - Destination object of the copy
64 * DESCRIPTION: Copy a buffer object to another buffer object.
66 ******************************************************************************/
69 AcpiExStoreBufferToBuffer (
70 ACPI_OPERAND_OBJECT
*SourceDesc
,
71 ACPI_OPERAND_OBJECT
*TargetDesc
)
77 ACPI_FUNCTION_TRACE_PTR (ExStoreBufferToBuffer
, SourceDesc
);
80 /* If Source and Target are the same, just return */
82 if (SourceDesc
== TargetDesc
)
84 return_ACPI_STATUS (AE_OK
);
87 /* We know that SourceDesc is a buffer by now */
89 Buffer
= ACPI_CAST_PTR (UINT8
, SourceDesc
->Buffer
.Pointer
);
90 Length
= SourceDesc
->Buffer
.Length
;
93 * If target is a buffer of length zero or is a static buffer,
94 * allocate a new buffer of the proper length
96 if ((TargetDesc
->Buffer
.Length
== 0) ||
97 (TargetDesc
->Common
.Flags
& AOPOBJ_STATIC_POINTER
))
99 TargetDesc
->Buffer
.Pointer
= ACPI_ALLOCATE (Length
);
100 if (!TargetDesc
->Buffer
.Pointer
)
102 return_ACPI_STATUS (AE_NO_MEMORY
);
105 TargetDesc
->Buffer
.Length
= Length
;
108 /* Copy source buffer to target buffer */
110 if (Length
<= TargetDesc
->Buffer
.Length
)
112 /* Clear existing buffer and copy in the new one */
114 ACPI_MEMSET (TargetDesc
->Buffer
.Pointer
, 0, TargetDesc
->Buffer
.Length
);
115 ACPI_MEMCPY (TargetDesc
->Buffer
.Pointer
, Buffer
, Length
);
117 #ifdef ACPI_OBSOLETE_BEHAVIOR
119 * NOTE: ACPI versions up to 3.0 specified that the buffer must be
120 * truncated if the string is smaller than the buffer. However, "other"
121 * implementations of ACPI never did this and thus became the defacto
122 * standard. ACPI 3.0A changes this behavior such that the buffer
123 * is no longer truncated.
128 * If the original source was a string, we must truncate the buffer,
129 * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
130 * copy must not truncate the original buffer.
132 if (OriginalSrcType
== ACPI_TYPE_STRING
)
134 /* Set the new length of the target */
136 TargetDesc
->Buffer
.Length
= Length
;
142 /* Truncate the source, copy only what will fit */
144 ACPI_MEMCPY (TargetDesc
->Buffer
.Pointer
, Buffer
,
145 TargetDesc
->Buffer
.Length
);
147 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
148 "Truncating source buffer from %X to %X\n",
149 Length
, TargetDesc
->Buffer
.Length
));
154 TargetDesc
->Buffer
.Flags
= SourceDesc
->Buffer
.Flags
;
155 TargetDesc
->Common
.Flags
&= ~AOPOBJ_STATIC_POINTER
;
156 return_ACPI_STATUS (AE_OK
);
160 /*******************************************************************************
162 * FUNCTION: AcpiExStoreStringToString
164 * PARAMETERS: SourceDesc - Source object to copy
165 * TargetDesc - Destination object of the copy
169 * DESCRIPTION: Copy a String object to another String object
171 ******************************************************************************/
174 AcpiExStoreStringToString (
175 ACPI_OPERAND_OBJECT
*SourceDesc
,
176 ACPI_OPERAND_OBJECT
*TargetDesc
)
182 ACPI_FUNCTION_TRACE_PTR (ExStoreStringToString
, SourceDesc
);
185 /* If Source and Target are the same, just return */
187 if (SourceDesc
== TargetDesc
)
189 return_ACPI_STATUS (AE_OK
);
192 /* We know that SourceDesc is a string by now */
194 Buffer
= ACPI_CAST_PTR (UINT8
, SourceDesc
->String
.Pointer
);
195 Length
= SourceDesc
->String
.Length
;
198 * Replace existing string value if it will fit and the string
199 * pointer is not a static pointer (part of an ACPI table)
201 if ((Length
< TargetDesc
->String
.Length
) &&
202 (!(TargetDesc
->Common
.Flags
& AOPOBJ_STATIC_POINTER
)))
205 * String will fit in existing non-static buffer.
206 * Clear old string and copy in the new one
208 ACPI_MEMSET (TargetDesc
->String
.Pointer
, 0,
209 (ACPI_SIZE
) TargetDesc
->String
.Length
+ 1);
210 ACPI_MEMCPY (TargetDesc
->String
.Pointer
, Buffer
, Length
);
215 * Free the current buffer, then allocate a new buffer
216 * large enough to hold the value
218 if (TargetDesc
->String
.Pointer
&&
219 (!(TargetDesc
->Common
.Flags
& AOPOBJ_STATIC_POINTER
)))
221 /* Only free if not a pointer into the DSDT */
223 ACPI_FREE (TargetDesc
->String
.Pointer
);
226 TargetDesc
->String
.Pointer
= ACPI_ALLOCATE_ZEROED (
227 (ACPI_SIZE
) Length
+ 1);
228 if (!TargetDesc
->String
.Pointer
)
230 return_ACPI_STATUS (AE_NO_MEMORY
);
233 TargetDesc
->Common
.Flags
&= ~AOPOBJ_STATIC_POINTER
;
234 ACPI_MEMCPY (TargetDesc
->String
.Pointer
, Buffer
, Length
);
237 /* Set the new target length */
239 TargetDesc
->String
.Length
= Length
;
240 return_ACPI_STATUS (AE_OK
);