2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #if defined(LINUX) || defined(FREEBSD)
32 #include <mm_malloc.h>
35 #include "offload_common.h"
47 if (console_enabled
> trace_level
) {
48 const uint8_t *arr
= (const uint8_t*) data
;
55 sprintf(bufferp
, "%02x", *arr
++);
59 sprintf(bufferp
, " ");
62 if ((count
&63) == 0) {
63 OFFLOAD_DEBUG_TRACE(trace_level
, "%s\n", buffer
);
69 OFFLOAD_DEBUG_TRACE(trace_level
, "%s\n", buffer
);
73 #endif // OFFLOAD_DEBUG
75 // The Marshaller and associated routines
77 void Marshaller::send_data(
82 OFFLOAD_DEBUG_TRACE(2, "send_data(%p, %lld)\n",
84 memcpy(buffer_ptr
, data
, (size_t)length
);
89 void Marshaller::receive_data(
94 OFFLOAD_DEBUG_TRACE(2, "receive_data(%p, %lld)\n",
96 memcpy(data
, buffer_ptr
, (size_t)length
);
101 // Send function pointer
102 void Marshaller::send_func_ptr(
110 name
= __offload_funcs
.find_name(data
);
112 #if OFFLOAD_DEBUG > 0
113 if (console_enabled
> 2) {
114 __offload_funcs
.dump();
116 #endif // OFFLOAD_DEBUG > 0
118 LIBOFFLOAD_ERROR(c_send_func_ptr
, data
);
121 length
= strlen(name
) + 1;
128 memcpy(buffer_ptr
, name
, length
);
129 buffer_ptr
+= length
;
133 // Receive function pointer
134 void Marshaller::receive_func_ptr(
141 name
= (const char*) buffer_ptr
;
142 if (name
[0] != '\0') {
143 *data
= __offload_funcs
.find_addr(name
);
145 #if OFFLOAD_DEBUG > 0
146 if (console_enabled
> 2) {
147 __offload_funcs
.dump();
149 #endif // OFFLOAD_DEBUG > 0
151 LIBOFFLOAD_ERROR(c_receive_func_ptr
, name
);
154 length
= strlen(name
) + 1;
161 buffer_ptr
+= length
;
165 // End of the Marshaller and associated routines
167 extern void *OFFLOAD_MALLOC(
175 OFFLOAD_DEBUG_TRACE(2, "%s(%lld, %lld)\n", __func__
, size
, align
);
177 if (align
< sizeof(void*)) {
178 align
= sizeof(void*);
181 ptr
= _mm_malloc(size
, align
);
183 LIBOFFLOAD_ERROR(c_offload_malloc
, size
, align
);
187 OFFLOAD_DEBUG_TRACE(2, "%s returned %p\n", __func__
, ptr
);