exstorob.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /******************************************************************************
  2. *
  3. * Module Name: exstorob - AML Interpreter object store support, store to object
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acinterp.h"
  45. #define _COMPONENT ACPI_EXECUTER
  46. ACPI_MODULE_NAME("exstorob")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ex_store_buffer_to_buffer
  50. *
  51. * PARAMETERS: source_desc - Source object to copy
  52. * target_desc - Destination object of the copy
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Copy a buffer object to another buffer object.
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_ex_store_buffer_to_buffer(union acpi_operand_object *source_desc,
  61. union acpi_operand_object *target_desc)
  62. {
  63. u32 length;
  64. u8 *buffer;
  65. ACPI_FUNCTION_TRACE_PTR(ex_store_buffer_to_buffer, source_desc);
  66. /* If Source and Target are the same, just return */
  67. if (source_desc == target_desc) {
  68. return_ACPI_STATUS(AE_OK);
  69. }
  70. /* We know that source_desc is a buffer by now */
  71. buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer);
  72. length = source_desc->buffer.length;
  73. /*
  74. * If target is a buffer of length zero or is a static buffer,
  75. * allocate a new buffer of the proper length
  76. */
  77. if ((target_desc->buffer.length == 0) ||
  78. (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
  79. target_desc->buffer.pointer = ACPI_ALLOCATE(length);
  80. if (!target_desc->buffer.pointer) {
  81. return_ACPI_STATUS(AE_NO_MEMORY);
  82. }
  83. target_desc->buffer.length = length;
  84. }
  85. /* Copy source buffer to target buffer */
  86. if (length <= target_desc->buffer.length) {
  87. /* Clear existing buffer and copy in the new one */
  88. ACPI_MEMSET(target_desc->buffer.pointer, 0,
  89. target_desc->buffer.length);
  90. ACPI_MEMCPY(target_desc->buffer.pointer, buffer, length);
  91. #ifdef ACPI_OBSOLETE_BEHAVIOR
  92. /*
  93. * NOTE: ACPI versions up to 3.0 specified that the buffer must be
  94. * truncated if the string is smaller than the buffer. However, "other"
  95. * implementations of ACPI never did this and thus became the defacto
  96. * standard. ACPI 3.0_a changes this behavior such that the buffer
  97. * is no longer truncated.
  98. */
  99. /*
  100. * OBSOLETE BEHAVIOR:
  101. * If the original source was a string, we must truncate the buffer,
  102. * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
  103. * copy must not truncate the original buffer.
  104. */
  105. if (original_src_type == ACPI_TYPE_STRING) {
  106. /* Set the new length of the target */
  107. target_desc->buffer.length = length;
  108. }
  109. #endif
  110. } else {
  111. /* Truncate the source, copy only what will fit */
  112. ACPI_MEMCPY(target_desc->buffer.pointer, buffer,
  113. target_desc->buffer.length);
  114. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  115. "Truncating source buffer from %X to %X\n",
  116. length, target_desc->buffer.length));
  117. }
  118. /* Copy flags */
  119. target_desc->buffer.flags = source_desc->buffer.flags;
  120. target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
  121. return_ACPI_STATUS(AE_OK);
  122. }
  123. /*******************************************************************************
  124. *
  125. * FUNCTION: acpi_ex_store_string_to_string
  126. *
  127. * PARAMETERS: source_desc - Source object to copy
  128. * target_desc - Destination object of the copy
  129. *
  130. * RETURN: Status
  131. *
  132. * DESCRIPTION: Copy a String object to another String object
  133. *
  134. ******************************************************************************/
  135. acpi_status
  136. acpi_ex_store_string_to_string(union acpi_operand_object *source_desc,
  137. union acpi_operand_object *target_desc)
  138. {
  139. u32 length;
  140. u8 *buffer;
  141. ACPI_FUNCTION_TRACE_PTR(ex_store_string_to_string, source_desc);
  142. /* If Source and Target are the same, just return */
  143. if (source_desc == target_desc) {
  144. return_ACPI_STATUS(AE_OK);
  145. }
  146. /* We know that source_desc is a string by now */
  147. buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer);
  148. length = source_desc->string.length;
  149. /*
  150. * Replace existing string value if it will fit and the string
  151. * pointer is not a static pointer (part of an ACPI table)
  152. */
  153. if ((length < target_desc->string.length) &&
  154. (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  155. /*
  156. * String will fit in existing non-static buffer.
  157. * Clear old string and copy in the new one
  158. */
  159. ACPI_MEMSET(target_desc->string.pointer, 0,
  160. (acpi_size) target_desc->string.length + 1);
  161. ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
  162. } else {
  163. /*
  164. * Free the current buffer, then allocate a new buffer
  165. * large enough to hold the value
  166. */
  167. if (target_desc->string.pointer &&
  168. (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  169. /* Only free if not a pointer into the DSDT */
  170. ACPI_FREE(target_desc->string.pointer);
  171. }
  172. target_desc->string.pointer = ACPI_ALLOCATE_ZEROED((acpi_size)
  173. length + 1);
  174. if (!target_desc->string.pointer) {
  175. return_ACPI_STATUS(AE_NO_MEMORY);
  176. }
  177. target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
  178. ACPI_MEMCPY(target_desc->string.pointer, buffer, length);
  179. }
  180. /* Set the new target length */
  181. target_desc->string.length = length;
  182. return_ACPI_STATUS(AE_OK);
  183. }