exstorob.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /******************************************************************************
  2. *
  3. * Module Name: exstorob - AML Interpreter object store support, store to object
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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 <acpi/acinterp.h>
  44. #define _COMPONENT ACPI_EXECUTER
  45. ACPI_MODULE_NAME ("exstorob")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_ex_store_buffer_to_buffer
  49. *
  50. * PARAMETERS: source_desc - Source object to copy
  51. * target_desc - Destination object of the copy
  52. *
  53. * RETURN: Status
  54. *
  55. * DESCRIPTION: Copy a buffer object to another buffer object.
  56. *
  57. ******************************************************************************/
  58. acpi_status
  59. acpi_ex_store_buffer_to_buffer (
  60. 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. /* We know that source_desc is a buffer by now */
  67. buffer = (u8 *) source_desc->buffer.pointer;
  68. length = source_desc->buffer.length;
  69. /*
  70. * If target is a buffer of length zero or is a static buffer,
  71. * allocate a new buffer of the proper length
  72. */
  73. if ((target_desc->buffer.length == 0) ||
  74. (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
  75. target_desc->buffer.pointer = ACPI_MEM_ALLOCATE (length);
  76. if (!target_desc->buffer.pointer) {
  77. return_ACPI_STATUS (AE_NO_MEMORY);
  78. }
  79. target_desc->buffer.length = length;
  80. }
  81. /* Copy source buffer to target buffer */
  82. if (length <= target_desc->buffer.length) {
  83. /* Clear existing buffer and copy in the new one */
  84. ACPI_MEMSET (target_desc->buffer.pointer, 0, target_desc->buffer.length);
  85. ACPI_MEMCPY (target_desc->buffer.pointer, buffer, length);
  86. #ifdef ACPI_OBSOLETE_BEHAVIOR
  87. /*
  88. * NOTE: ACPI versions up to 3.0 specified that the buffer must be
  89. * truncated if the string is smaller than the buffer. However, "other"
  90. * implementations of ACPI never did this and thus became the defacto
  91. * standard. ACPi 3.0_a changes this behavior such that the buffer
  92. * is no longer truncated.
  93. */
  94. /*
  95. * OBSOLETE BEHAVIOR:
  96. * If the original source was a string, we must truncate the buffer,
  97. * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
  98. * copy must not truncate the original buffer.
  99. */
  100. if (original_src_type == ACPI_TYPE_STRING) {
  101. /* Set the new length of the target */
  102. target_desc->buffer.length = length;
  103. }
  104. #endif
  105. }
  106. else {
  107. /* Truncate the source, copy only what will fit */
  108. ACPI_MEMCPY (target_desc->buffer.pointer, buffer,
  109. target_desc->buffer.length);
  110. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  111. "Truncating source buffer from %X to %X\n",
  112. length, target_desc->buffer.length));
  113. }
  114. /* Copy flags */
  115. target_desc->buffer.flags = source_desc->buffer.flags;
  116. target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
  117. return_ACPI_STATUS (AE_OK);
  118. }
  119. /*******************************************************************************
  120. *
  121. * FUNCTION: acpi_ex_store_string_to_string
  122. *
  123. * PARAMETERS: source_desc - Source object to copy
  124. * target_desc - Destination object of the copy
  125. *
  126. * RETURN: Status
  127. *
  128. * DESCRIPTION: Copy a String object to another String object
  129. *
  130. ******************************************************************************/
  131. acpi_status
  132. acpi_ex_store_string_to_string (
  133. union acpi_operand_object *source_desc,
  134. union acpi_operand_object *target_desc)
  135. {
  136. u32 length;
  137. u8 *buffer;
  138. ACPI_FUNCTION_TRACE_PTR ("ex_store_string_to_string", source_desc);
  139. /* We know that source_desc is a string by now */
  140. buffer = (u8 *) source_desc->string.pointer;
  141. length = source_desc->string.length;
  142. /*
  143. * Replace existing string value if it will fit and the string
  144. * pointer is not a static pointer (part of an ACPI table)
  145. */
  146. if ((length < target_desc->string.length) &&
  147. (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  148. /*
  149. * String will fit in existing non-static buffer.
  150. * Clear old string and copy in the new one
  151. */
  152. ACPI_MEMSET (target_desc->string.pointer, 0,
  153. (acpi_size) target_desc->string.length + 1);
  154. ACPI_MEMCPY (target_desc->string.pointer, buffer, length);
  155. }
  156. else {
  157. /*
  158. * Free the current buffer, then allocate a new buffer
  159. * large enough to hold the value
  160. */
  161. if (target_desc->string.pointer &&
  162. (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
  163. /* Only free if not a pointer into the DSDT */
  164. ACPI_MEM_FREE (target_desc->string.pointer);
  165. }
  166. target_desc->string.pointer = ACPI_MEM_CALLOCATE (
  167. (acpi_size) length + 1);
  168. if (!target_desc->string.pointer) {
  169. return_ACPI_STATUS (AE_NO_MEMORY);
  170. }
  171. target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
  172. ACPI_MEMCPY (target_desc->string.pointer, buffer, length);
  173. }
  174. /* Set the new target length */
  175. target_desc->string.length = length;
  176. return_ACPI_STATUS (AE_OK);
  177. }