Fixed aligned_realloc.

Fixed aligned_realloc.

Kept track of allocation size as well as base_ptr in
alligned_alloc.

Future optimizations possible:
  1. Do not re-create memory if size remains unchanged
  2. Do not re-create memory if size is reduced by some margin.

Change-Id: I83e27885ebfc5742a906caed41d2d37c4e6b5205
Reviewed-on: https://wn-project.dnsalias.net/22
Reviewed-by: awoloszyn <2926f0436f8103ab8257713335cf26447d8bf68a@google.com>
Tested-by: awoloszyn <2926f0436f8103ab8257713335cf26447d8bf68a@google.com>

--- Libraries/WNMemory/inc/WNAllocation.h
+++ Libraries/WNMemory/inc/WNAllocation.h
@@ -52,18 +52,8 @@

             #ifdef _WN_WINDOWS
                 return(::_aligned_malloc(_size, _alignment));
-            #elif defined _WN_ANDROID
-                return(::memalign(_alignment, _size));
-            #elif defined _WN_POSIX
-                wn_void* ptr;
-
-                if (::posix_memalign(&ptr, _alignment, _size) != 0) {
-                    return(wn_nullptr);
-                }
-
-                return(ptr);
             #else
-                wn_void* temp_ptr = malloc((_size + _alignment - 1) + sizeof(wn_void*));
+                wn_void* temp_ptr = malloc((_size + _alignment - 1) + 2 * sizeof(wn_void*));

                 if (temp_ptr == wn_nullptr) {
                     return(wn_nullptr);
@@ -73,6 +63,7 @@
                                                                sizeof(wn_void*) + _alignment - 1) & ~(_alignment - 1)));

                 *(reinterpret_cast<wn_void**>(ptr) - 1) = temp_ptr;
+                *(reinterpret_cast<size_t*>(ptr) - 2) = _size;

                 return(ptr);
             #endif
@@ -91,9 +82,12 @@
                 return(::_aligned_realloc(_ptr, _new_size, _alignment));
             #else
                 wn_void* ptr = aligned_malloc(_new_size, _alignment);
-
-                ptr = memcpy(ptr, _ptr, _new_size);
-
+                size_t copy_size = 0;
+                if (_ptr) {
+                  size_t old_size = *(reinterpret_cast<size_t*>(_ptr) - 2);
+                  size_t copy_size = old_size < _new_size? old_size: _new_size;
+                  ptr = memcpy(ptr, _ptr, copy_size);
+                }
                 aligned_free(_ptr);

                 return(ptr);
@@ -103,10 +97,10 @@
         WN_FORCE_INLINE wn_void aligned_free(wn_void* _ptr) {
             #ifdef _WN_WINDOWS
                 ::_aligned_free(_ptr);
-            #elif defined _WN_POSIX
-                free(_ptr);
             #else
-                free(*(reinterpret_cast<wn_void**>(_ptr) - 1));
+                if (_ptr) {
+                  free(*(reinterpret_cast<wn_void**>(_ptr) - 1));
+                }
             #endif
         }


Remove redundant template argument

Remove redundant template argument

--- OOModel/src/CodeGenerationVisitor.h
+++ OOModel/src/CodeGenerationVisitor.h
@@ -38,7 +38,7 @@
 class ReferenceExpression;
 class MetaCallExpression;

-class CodeGenerationVisitor : public Model::Visitor<CodeGenerationVisitor, void> {
+class CodeGenerationVisitor : public Model::Visitor<CodeGenerationVisitor> {
 	private:
 		QMap<QString, Model::Node*> args_;


fixed a printf type

fixed a printf type

--- Test_Code/main.c
+++ Test_Code/main.c
@@ -41,7 +41,7 @@
 }

 int main() {
-    printf("check config: %d sensors", sensor_array.sensors_number);
+    printf("check config: %zu sensors", sensor_array.sensors_number);

     uint32_t i;


Modify readi and writei as streaming

Modify readi and writei as streaming

--- apps/examples/testcase/ta_tc/audio/utc/utc_audio_main.c
+++ apps/examples/testcase/ta_tc/audio/utc/utc_audio_main.c
@@ -54,16 +54,11 @@
  ****************************************************************************/

 extern sem_t tc_sem;
-
 extern int working_tc;

 struct pcm *g_pcm;

-unsigned int g_byte_size;
-
-char *g_record_buffer;
-
-static void clean_all_data(int fd)
+static void clean_all_data(int fd, char *buffer)
 {
 	if (fd > 0) {
 		close(fd);
@@ -71,11 +66,11 @@

 	if (g_pcm) {
 		pcm_close(g_pcm);
+		g_pcm = NULL;
 	}

-	if (g_record_buffer) {
-		free(g_record_buffer);
-		g_record_buffer = NULL;
+	if (buffer) {
+		free(buffer);
 	}
 }

@@ -538,11 +533,19 @@
 static void utc_audio_pcm_frames_to_bytes_p(void)
 {
 	ssize_t size;
+	unsigned int bytes;
+	unsigned int frame_size;
+
 	/* set basic configuration values for next test */
 	pcm_set_config(g_pcm, NULL);
 	size = pcm_get_buffer_size(g_pcm);
-	g_byte_size = pcm_frames_to_bytes(g_pcm, size);
-	TC_ASSERT_GT("pcm_frames_to_bytes", g_byte_size, 0);
+	TC_ASSERT_GT("pcm_get_buffer_size", size, 0);
+
+	frame_size = pcm_bytes_to_frames(g_pcm, size);
+	TC_ASSERT_GT("pcm_bytes_to_frames", frame_size, 0);
+
+	bytes = pcm_frames_to_bytes(g_pcm, frame_size);
+	TC_ASSERT_GT("pcm_frames_to_bytes", bytes, 0);
 	TC_SUCCESS_RESULT();
 }

@@ -572,9 +575,14 @@
 */
 static void utc_audio_pcm_bytes_to_frames_p(void)
 {
-
+	ssize_t size;
 	unsigned int frame_size;
-	frame_size = pcm_bytes_to_frames(g_pcm, g_byte_size);
+
+	pcm_set_config(g_pcm, NULL);
+	size = pcm_get_buffer_size(g_pcm);
+	TC_ASSERT_GT("pcm_get_buffer_size", size, 0);
+
+	frame_size = pcm_bytes_to_frames(g_pcm, size);
 	TC_ASSERT_GT("pcm_bytes_to_frame", frame_size, 0);
 	TC_SUCCESS_RESULT();
 }
@@ -590,8 +598,8 @@
 static void utc_audio_pcm_bytes_to_frames_n(void)
 {
 	unsigned int frame;
-	frame = pcm_frames_to_bytes(NULL, 0);
-	TC_ASSERT_LEQ("pcm_frames_to_bytes", frame, 0);
+	frame = pcm_bytes_to_frames(NULL, 0);
+	TC_ASSERT_LEQ("pcm_bytes_to_frames", frame, 0);
 	TC_SUCCESS_RESULT();
 }

@@ -638,43 +646,39 @@
 {
 	int fd;
 	char input_str[16];
-	ssize_t size;
-	ssize_t bytes;
-	int frames_read = 0;
-	unsigned int total_frames_read = 0;
-	unsigned int rate;
-	int remain;
 	int ret;
 	char *str;
-
-	size = pcm_get_buffer_size(g_pcm);
-	rate = pcm_get_rate(g_pcm);
-	bytes = rate * (pcm_format_to_bits(pcm_get_format(g_pcm)) / 8) * pcm_get_channels(g_pcm) * AUDIO_RECORD_DURATION;
-
-	g_record_buffer = (char *)malloc(bytes);	//rate * bit * channels * duration
-	TC_ASSERT_NEQ("pcm_readi_p", g_record_buffer, NULL);
-
-	remain = pcm_bytes_to_frames(g_pcm, bytes);
-	printf("Record will be start for 3s, press any key to start(Total frame: %d, %d bytes)\n", remain, bytes);
+	char *buffer;
+	unsigned int bytes_per_frame;
+	int frames_read;
+	int remain;
+
+	buffer = malloc(pcm_get_buffer_size(g_pcm));
+	TC_ASSERT_NEQ_CLEANUP("pcm_readi", buffer, NULL, clean_all_data(0, 0));
+
+	fd = open(AUDIO_TEST_FILE, O_RDWR | O_CREAT);
+	TC_ASSERT_GT_CLEANUP("pcm_readi", fd, 0, clean_all_data(0, buffer));
+
+	bytes_per_frame = pcm_frames_to_bytes(g_pcm, 1);
+	frames_read = 0;
+	remain = AUDIO_DEFAULT_RATE * AUDIO_RECORD_DURATION;
+
+	printf("Record will be start for 3s, press any key to start(Total frame: %d)\n", remain);
 	fflush(stdout);
 	str = gets(input_str);
-	TC_ASSERT_NEQ_CLEANUP("pcm_readi", str, NULL, free(g_record_buffer));
+	TC_ASSERT_NEQ_CLEANUP("pcm_readi", str, NULL, clean_all_data(fd, buffer));

 	while (remain > 0) {
-		frames_read = pcm_readi(g_pcm, (void *)&g_record_buffer[pcm_frames_to_bytes(g_pcm, total_frames_read)], remain);
-		total_frames_read += frames_read;
+		frames_read = pcm_readi(g_pcm, buffer, remain);
 		remain -= frames_read;
+		ret = write(fd, buffer, bytes_per_frame * frames_read);
+		TC_ASSERT_EQ_CLEANUP("pcm_readi", ret, (bytes_per_frame * frames_read), clean_all_data(fd, buffer));
 	}
-	printf("Record done. Writing file...\n");
-
-	pcm_close(g_pcm);
-	fd = open(AUDIO_TEST_FILE, O_RDWR | O_CREAT);
-	ret = write(fd, g_record_buffer, bytes);
-	TC_ASSERT_GT_CLEANUP("pcm_reaid_p", ret, 0, close(fd));
-	close(fd);
-
-	printf("Writing done. Playback will start.\n");
-
+
+	printf("Record done.\n");
+	sleep(2);
+
+	clean_all_data(fd, buffer);
 	TC_SUCCESS_RESULT();
 }

@@ -690,21 +694,25 @@
 {
 	int ret;
 	ssize_t size;
+	char *buffer;
+
 	g_pcm = pcm_open(0, 0, PCM_IN, NULL);
-	TC_ASSERT_GT_CLEANUP("pcm_readi", pcm_get_file_descriptor(g_pcm), 0, clean_all_data(0));
+	TC_ASSERT_GT("pcm_readi", pcm_get_file_descriptor(g_pcm), 0);

 	size = pcm_get_buffer_size(g_pcm);
-
-	ret = pcm_readi(NULL, g_record_buffer, size);
-	TC_ASSERT_LT_CLEANUP("pcm_readi", ret, 0, clean_all_data(0));
+	buffer = (char *)malloc(size);
+	TC_ASSERT_GT_CLEANUP("pcm_readi", buffer, 0, clean_all_data(0, NULL));
+
+	ret = pcm_readi(NULL, buffer, size);
+	TC_ASSERT_LT_CLEANUP("pcm_readi", ret, 0, clean_all_data(0, buffer));

 	ret = pcm_readi(g_pcm, NULL, size);
-	TC_ASSERT_LT_CLEANUP("pcm_readi", ret, 0, clean_all_data(0));
-
-	ret = pcm_readi(g_pcm, g_record_buffer, 0);
-	TC_ASSERT_LT_CLEANUP("pcm_readi", ret, 0, clean_all_data(0));
-
-	clean_all_data(0);
+	TC_ASSERT_LT_CLEANUP("pcm_readi", ret, 0, clean_all_data(0, buffer));
+
+	ret = pcm_readi(g_pcm, buffer, 0);
+	TC_ASSERT_LT_CLEANUP("pcm_readi", ret, 0, clean_all_data(0, buffer));
+
+	clean_all_data(0, buffer);
 	TC_SUCCESS_RESULT();
 }

@@ -719,39 +727,39 @@
 static void utc_audio_pcm_writei_p(void)
 {
 	int fd;
-	ssize_t bytes;
 	int ret;
-	int total_frames_write = 0;
-	int remain;
-
-	fd = open(AUDIO_TEST_FILE, O_RDONLY);
-	TC_ASSERT_GEQ("pcm_writei", fd, 0);
+
+	char *buffer;
+	int num_read;
+	int total_frames;
+	unsigned int size;

 	/* use default config here */
 	g_pcm = pcm_open(0, 0, PCM_OUT, NULL);
-	TC_ASSERT_GT_CLEANUP("pcm_writei", pcm_is_ready(g_pcm), 0, close(fd));
-
-	bytes = lseek(fd, 0, SEEK_END);
-	lseek(fd, 0, SEEK_SET);
-
-	g_record_buffer = (char *)malloc(bytes);	//rate * bit * channels * duration
-	TC_ASSERT_NEQ_CLEANUP("pcm_readi_p", g_record_buffer, NULL, clean_all_data(fd));
-
-	remain = pcm_bytes_to_frames(g_pcm, bytes);
-
-	printf("playback start!! Total frames: %d\n", remain);
-
-	ret = read(fd, g_record_buffer, bytes);
-	TC_ASSERT_GEQ_CLEANUP("pcm_writei", ret, 0, clean_all_data(fd));
-	close(fd);
-
-	while (remain > 0) {
-		ret = pcm_writei(g_pcm, (void *)&g_record_buffer[pcm_frames_to_bytes(g_pcm, total_frames_write)], remain);
-		total_frames_write += ret;
-		remain -= ret;
-	}
-
-	pcm_close(g_pcm);
+	TC_ASSERT_GT("pcm_writei", pcm_is_ready(g_pcm), 0);
+
+	size = pcm_get_buffer_size(g_pcm);
+	buffer = malloc(size);
+	TC_ASSERT_NEQ_CLEANUP("pcm_writei", buffer, NULL, clean_all_data(0, NULL));
+
+	fd = open(AUDIO_TEST_FILE, O_RDONLY);
+	TC_ASSERT_GEQ_CLEANUP("pcm_writei", fd, 0, clean_all_data(0, buffer));
+
+	printf("Playback start!!\n");
+	total_frames = 0;
+	do {
+		num_read = read(fd, buffer, size);
+		if (num_read > 0) {
+			total_frames += num_read;
+			ret = pcm_writei(g_pcm, buffer, pcm_bytes_to_frames(g_pcm, num_read));
+			TC_ASSERT_GEQ_CLEANUP("pcm_writei", ret, 0, clean_all_data(fd, buffer));
+		}
+	} while (num_read > 0);
+
+	sleep(2);
+	printf("Playback done! Total Frames: %d\n", pcm_bytes_to_frames(g_pcm, total_frames));
+
+	clean_all_data(fd, buffer);
 	TC_SUCCESS_RESULT();
 }

@@ -767,20 +775,25 @@
 {
 	int ret;
 	ssize_t size;
+	char *buffer;
+
 	g_pcm = pcm_open(0, 0, PCM_IN, NULL);
 	TC_ASSERT_GT("pcm_writei", pcm_get_file_descriptor(g_pcm), 0);

 	size = pcm_get_buffer_size(g_pcm);
-
-	ret = pcm_writei(NULL, g_record_buffer, size);
-	TC_ASSERT_LT_CLEANUP("pcm_writei", ret, 0, clean_all_data(0));
+	buffer = (char *)malloc(size);
+	TC_ASSERT_NEQ_CLEANUP("pcm_writei", buffer, 0, clean_all_data(0, NULL));
+
+	ret = pcm_writei(NULL, buffer, size);
+	TC_ASSERT_LT_CLEANUP("pcm_writei", ret, 0, clean_all_data(0, buffer));

 	ret = pcm_writei(g_pcm, NULL, size);
-	TC_ASSERT_LT_CLEANUP("pcm_writei", ret, 0, clean_all_data(0));
-
-	ret = pcm_writei(g_pcm, g_record_buffer, 0);
-	TC_ASSERT_LT_CLEANUP("pcm_writei", ret, 0, clean_all_data(0));
-	clean_all_data(0);
+	TC_ASSERT_LT_CLEANUP("pcm_writei", ret, 0, clean_all_data(0, buffer));
+
+	ret = pcm_writei(g_pcm, buffer, 0);
+	TC_ASSERT_LT_CLEANUP("pcm_writei", ret, 0, clean_all_data(0, buffer));
+
+	clean_all_data(0, buffer);
 	TC_SUCCESS_RESULT();
 }


Minor documentation fix

Minor documentation fix

--- OgreMain/include/OgreRenderSystem.h
+++ OgreMain/include/OgreRenderSystem.h
@@ -373,10 +373,10 @@
 			macAPICocoaUseNSView
 			bool "true" or "false"
 			"false"
-			On the Mac platform the most diffused method to embed ogre in a custom application is to use the IntefaceBuilder
+			On the Mac platform the most diffused method to embed OGRE in a custom application is to use Interface Builder
 				and add to the interface an instance of OgreView.
 				The pointer to this instance is then used as "externalWindowHandle".
-				However, there are cases where you are NOT using the Interface Builder and you get the Cocoa NSView* of an existing interface.
+				However, there are cases where you are NOT using Interface Builder and you get the Cocoa NSView* of an existing interface.
 				For example, this is happens when you want to render into a Java/AWT interface.
 				In short, by setting this flag to "true" the Ogre::Root::createRenderWindow interprets the "externalWindowHandle" as a NSView*
 				instead of an OgreView*. See OgreOSXCocoaView.h/mm.


net: drop the packet when fails to do software segmentation or header check

Commit cecda693a969816bac5e470e1d9c9c0ef5567bca ("net: keep original skb
which only needs header checking during software GSO") keeps the original
skb for packets that only needs header check, but it doesn't drop the
packet if software segmentation or header check were failed.

Fixes cecda693a9 ("net: keep original skb which only needs header checking during software GSO")
Cc: Eric Dumazet <a0baddf32b28d2f9429941ed4af2fe636e210591@gmail.com>
Signed-off-by: Jason Wang <808efd45667dbd241e4e026b5673172419ecb43e@redhat.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- net/core/dev.c
+++ net/core/dev.c
@@ -2673,7 +2673,7 @@

 		segs = skb_gso_segment(skb, features);
 		if (IS_ERR(segs)) {
-			segs = NULL;
+			goto out_kfree_skb;
 		} else if (segs) {
 			consume_skb(skb);
 			skb = segs;


net: check the return value of ndo_select_queue()

Check the return value of ndo_select_queue(). If the value isn't smaller
than the real_num_tx_queues, print a warning message, and reset it to zero.

Signed-off-by: Changli Gao <e0c990ad75746f704921cca52caa8fdda39c56b7@gmail.com>
Signed-off-by: Eric Dumazet <a0baddf32b28d2f9429941ed4af2fe636e210591@gmail.com>
----
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- net/core/dev.c
+++ net/core/dev.c
@@ -1848,6 +1848,20 @@
 }
 EXPORT_SYMBOL(skb_tx_hash);

+static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
+{
+	if (unlikely(queue_index >= dev->real_num_tx_queues)) {
+		if (net_ratelimit()) {
+			WARN(1, "%s selects TX queue %d, but "
+			     "real number of TX queues is %d\n",
+			     dev->name, queue_index,
+			     dev->real_num_tx_queues);
+		}
+		return 0;
+	}
+	return queue_index;
+}
+
 static struct netdev_queue *dev_pick_tx(struct net_device *dev,
 					struct sk_buff *skb)
 {
@@ -1861,6 +1875,7 @@

 		if (ops->ndo_select_queue) {
 			queue_index = ops->ndo_select_queue(dev, skb);
+			queue_index = dev_cap_txqueue(dev, queue_index);
 		} else {
 			queue_index = 0;
 			if (dev->real_num_tx_queues > 1)


Improve relocation code to compensate instruction shifts with rewritten instructions

--- src/Relocation.c
+++ src/Relocation.c
@@ -514,24 +514,19 @@
             *(address + instruction->instruction.raw.imm[0].offset) = 0x02;
             address += instruction->instruction.length;

+            ZyrexUpdateRelocationContext(context, instruction->instruction.length,
+                (ZyanU8)context->bytes_read, (ZyanU8)context->bytes_written);
+
             // Generate `JMP` to `0` branch
             *address++ = 0xEB;
             *address++ = 0x05;
+            ZyrexUpdateRelocationContext(context, 2, (ZyanU8)context->bytes_read,
+                (ZyanU8)context->bytes_written + instruction->instruction.length);

             // Generate `JMP` to `1` branch
             ZyrexWriteRelativeJump(address, instruction->absolute_target_address);
-            address += 5;
-
-            // Update relocation context
-
-            // TODO: Correctly update translation-map and instructions_written
-            // TODO: At the moment we can't substitute a single instruction with multiple ones as this would
-            // TODO: confuse the `ZyrexUpdateInstructionOffsets` function
-
-            const ZyanUSize bytes_written =
-                address - ((ZyanU8*)context->destination + context->bytes_written);
-            ZyrexUpdateRelocationContext(context, bytes_written,
-                (ZyanU8)context->bytes_read, (ZyanU8)context->bytes_written);
+            ZyrexUpdateRelocationContext(context, 2, (ZyanU8)context->bytes_read,
+                (ZyanU8)context->bytes_written + instruction->instruction.length + 2);

             return ZYAN_STATUS_SUCCESS;
         }
@@ -690,6 +685,39 @@
 }

 /**
+ * @brief   Takes the offset of an instruction in the source buffer and returns the offset of the
+ *          same instruction in the destination buffer.
+ *
+ * @param   context             A pointer to the `ZyrexRelocationContext` struct.
+ * @param   offset_source       The offset of the instruction in the source buffer.
+ * @param   offset_destination  Receives the offset of the instruction in the destination buffer.
+ *
+ * If the source instruction has been rewritten into a code-block of multiple instructions, the
+ * offset of the first instruction is returned.
+ *
+ * @return  A zyan status code.
+ */
+static ZyanStatus ZyrexGetRelocatedInstructionOffset(ZyrexRelocationContext* context,
+    ZyanU8 offset_source, ZyanU8* offset_destination)
+{
+    ZYAN_ASSERT(context);
+    ZYAN_ASSERT(offset_destination);
+    ZYAN_ASSERT(context->instructions.size <= context->translation_map->count);
+
+    for (ZyanUSize i = 0; i < context->translation_map->count; ++i)
+    {
+        const ZyrexInstructionTranslationItem* item = &context->translation_map->items[i];
+        if (item->offset_source == offset_source)
+        {
+            *offset_destination = item->offset_destination;
+            return ZYAN_STATUS_SUCCESS;
+        }
+    }
+
+    return ZYAN_STATUS_NOT_FOUND;
+}
+
+/**
  * @brief   Updates the offsets of instructions with relative offsets pointing to instructions
  *          inside the relocated code.
  *
@@ -699,7 +727,7 @@
  *
  * As some of the instructions might have been enlarged or rewritten, there is a chance that the
  * relative offset of previous instructions does not point to the correct target any longer. This
- * function compensates for any instruction shifts happened during the relocation process.
+ * function compensates all instruction shifts happened during the relocation process.
  */
 static ZyanStatus ZyrexUpdateInstructionOffsets(ZyrexRelocationContext* context)
 {
@@ -707,11 +735,13 @@

     for (ZyanUSize i = 0; i < context->instructions.size; ++i)
     {
-        const ZyrexAnalyzedInstruction* const item = ZyanVectorGet(&context->instructions, i);
-        ZYAN_ASSERT(item);
-
-        if (!item->has_relative_target || item->has_external_target)
-        {
+        const ZyrexAnalyzedInstruction* const instruction =
+            ZyanVectorGet(&context->instructions, i);
+
+        if (!instruction->has_relative_target || instruction->has_external_target)
+        {
+            // The instruction does not have a relative target or the relative offset is pointing
+            // to an address outside of the destination buffer
             continue;
         }

@@ -722,30 +752,40 @@

         ZyanU8 offset = 0;
         ZyanU8 size   = 0;
-        if (ZyrexIsRelativeBranchInstruction(&item->instruction))
-        {
-            offset = item->instruction.raw.imm[0].offset;
-            size   = item->instruction.raw.imm[0].size;
-        }
-        if (ZyrexIsRelativeMemoryInstruction(&item->instruction))
-        {
-            offset = item->instruction.raw.disp.offset;
-            size   = item->instruction.raw.disp.size;
-        }
-
-        const ZyanU8 source_offset = context->translation_map->items[i].offset_destination;
-        const ZyanU8 destination_offset =
-            context->translation_map->items[item->outgoing].offset_destination;
-
-        void* const offset_address = (ZyanU8*)context->destination + source_offset + offset;
-        const ZyanI32 value = ZyrexCalculateRelativeOffset(item->instruction.length,
-            source_offset, destination_offset);
+        if (ZyrexIsRelativeBranchInstruction(&instruction->instruction))
+        {
+            offset = instruction->instruction.raw.imm[0].offset;
+            size   = instruction->instruction.raw.imm[0].size;
+        }
+        if (ZyrexIsRelativeMemoryInstruction(&instruction->instruction))
+        {
+            offset = instruction->instruction.raw.disp.offset;
+            size   = instruction->instruction.raw.disp.size;
+        }
+        ZYAN_ASSERT(size > 0);
+
+        // Lookup the offset of the instruction in the destination buffer
+        ZyanU8 offset_instruction;
+        ZYAN_CHECK(ZyrexGetRelocatedInstructionOffset(context, (ZyanU8)instruction->address_offset,
+            &offset_instruction));
+
+        // Lookup the offset of the destination instruction in the destination buffer
+        const ZyrexAnalyzedInstruction* const destination =
+            ZyanVectorGet(&context->instructions, instruction->outgoing);
+        ZYAN_ASSERT(destination);
+        ZyanU8 offset_destination;
+        ZYAN_CHECK(ZyrexGetRelocatedInstructionOffset(context, (ZyanU8)destination->address_offset,
+            &offset_destination));
+
+        void* const address_of_offset = (ZyanU8*)context->destination + offset_instruction + offset;
+        const ZyanI32 value = ZyrexCalculateRelativeOffset(instruction->instruction.length,
+            offset_instruction, offset_destination);

         switch (size)
         {
-        case  8: *((ZyanI8* )offset_address) = (ZyanI8 )value; break;
-        case 16: *((ZyanI16*)offset_address) = (ZyanI16)value; break;
-        case 32: *((ZyanI32*)offset_address) = (ZyanI32)value; break;
+        case  8: *((ZyanI8* )address_of_offset) = (ZyanI8 )value; break;
+        case 16: *((ZyanI16*)address_of_offset) = (ZyanI16)value; break;
+        case 32: *((ZyanI32*)address_of_offset) = (ZyanI32)value; break;
         default:
             ZYAN_UNREACHABLE;
         }


Flushing prefixes of autoconfigured IPv6 addresses with ndp -P caused an uvm fault.  The function in6_purgeaddr() might already free the prefix before prelist_remove() is called.  So call in6_purgeaddr() for all addresses first and then loop over the remaining prefixes and call prelist_remove(). OK claudio@

--- netinet6/nd6.c
+++ netinet6/nd6.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: nd6.c,v 1.92 2012/09/19 09:47:25 bluhm Exp $	*/
+/*	$OpenBSD: nd6.c,v 1.93 2013/01/15 10:15:19 bluhm Exp $	*/
 /*	$KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $	*/

 /*
@@ -1389,6 +1389,7 @@
 		struct nd_prefix *pr, *next;

 		s = splsoftnet();
+		/* First purge the addresses referenced by a prefix. */
 		for (pr = LIST_FIRST(&nd_prefix); pr; pr = next) {
 			struct in6_ifaddr *ia, *ia_next;

@@ -1408,6 +1409,18 @@
 				if (ia->ia6_ndpr == pr)
 					in6_purgeaddr(&ia->ia_ifa);
 			}
+		}
+		/*
+		 * Purging the addresses might remove the prefix as well.
+		 * So run the loop again to access only prefixes that have
+		 * not been freed already.
+		 */
+		for (pr = LIST_FIRST(&nd_prefix); pr; pr = next) {
+			next = LIST_NEXT(pr, ndpr_entry);
+
+			if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
+				continue; /* XXX */
+
 			prelist_remove(pr);
 		}
 		splx(s);


Bug fix tag_store: use_global_cache instead of rman

--- src/overpass_api/data/tag_store.h
+++ src/overpass_api/data/tag_store.h
@@ -393,7 +393,7 @@
     return elems;
   }

-  auto & tags_by_id = rman ? rman->tags_by_id().get<Object>() : this->tags_by_id;
+  auto & tags_by_id = rman->tags_by_id().get<Object>();

   std::map< Index, std::vector< Object > > elems_filtered;

@@ -413,7 +413,7 @@
 template< typename Index, typename Object >
 void Tag_Store< Index, Object >::prefetch_all(const std::map< Index, std::vector< Object > >& elems)
 {
-  auto & tags_by_id = rman ? rman->tags_by_id().get<Object>() : this->tags_by_id;
+  auto & tags_by_id = use_global_cache ? rman->tags_by_id().get<Object>() : this->tags_by_id;

   if (elems.empty()) {
     if (!use_global_cache)


parallels: parse virtual network properties

Fill bridge name and mac for bridged network and
DHCP server parameter for host-only network.

Signed-off-by: Dmitry Guryanov <82bcdc4bd8b0265ee488eb5c489ce233d2f86b5c@parallels.com>

--- src/parallels/parallels_network.c
+++ src/parallels/parallels_network.c
@@ -35,6 +35,158 @@
     virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__,    \
                      __FUNCTION__, __LINE__, _("Can't parse prlctl output"))

+#define SYSFS_NET_DIR "/sys/class/net"
+
+static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj)
+{
+    const char *ifname;
+    char *bridgeLink = NULL;
+    char *bridgePath = NULL;
+    char *bridgeAddressPath = NULL;
+    char *bridgeAddress = NULL;
+    int len = 0;
+    int ret = -1;
+
+    if (!(ifname = virJSONValueObjectGetString(jobj, "Bound To"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (virAsprintf(&bridgeLink, "%s/%s/brport/bridge",
+                    SYSFS_NET_DIR, ifname) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (virFileResolveLink(bridgeLink, &bridgePath) < 0) {
+        virReportSystemError(errno, _("cannot read link '%s'"), bridgeLink);
+        goto cleanup;
+    }
+
+    if (!(def->bridge = strdup(basename(bridgePath)))) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (virAsprintf(&bridgeAddressPath, "%s/%s/brport/bridge/address",
+                    SYSFS_NET_DIR, ifname) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if ((len = virFileReadAll(bridgeAddressPath, 18, &bridgeAddress)) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Error reading file '%s'"), bridgeAddressPath);
+
+        goto cleanup;
+    }
+
+    if (len < VIR_MAC_STRING_BUFLEN) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Error reading MAC from '%s'"), bridgeAddressPath);
+    }
+
+    bridgeAddress[VIR_MAC_STRING_BUFLEN - 1] = '\0';
+    if (virMacAddrParse(bridgeAddress, &def->mac) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Can't parse MAC '%s'"), bridgeAddress);
+        goto cleanup;
+    }
+    def->mac_specified = 1;
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(bridgeLink);
+    VIR_FREE(bridgePath);
+    VIR_FREE(bridgeAddress);
+    VIR_FREE(bridgeAddressPath);
+    return ret;
+}
+
+static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name)
+{
+    const char *tmp;
+    virJSONValuePtr jobj = NULL, jobj2;
+    int ret = -1;
+
+    if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    jobj = parallelsParseOutput("prlsrvctl", "net", "info", "-j", name, NULL);
+
+    if (!jobj) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (!(jobj2 = virJSONValueObjectGet(jobj, "Parallels adapter"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (!(def->ips[0].family = strdup("ipv4"))) {
+        virReportOOMError();
+        goto cleanup;
+    };
+    if (!(tmp = virJSONValueObjectGetString(jobj2, "IP address"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (virSocketAddrParseIPv4(&def->ips[0].address, tmp) < 0) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (!(tmp = virJSONValueObjectGetString(jobj2, "Subnet mask"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (virSocketAddrParseIPv4(&def->ips[0].netmask, tmp) < 0) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (!(jobj2 = virJSONValueObjectGet(jobj, "DHCPv4 server"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (!(tmp = virJSONValueObjectGetString(jobj2, "IP scope start address"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (virSocketAddrParseIPv4(&def->ips[0].ranges[0].start, tmp) < 0) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (!(tmp = virJSONValueObjectGetString(jobj2, "IP scope end address"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (virSocketAddrParseIPv4(&def->ips[0].ranges[0].end, tmp) < 0) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    ret = 0;
+cleanup:
+    virJSONValueFree(jobj);
+    return ret;
+}
+
 static virNetworkObjPtr
 parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
 {
@@ -60,6 +212,26 @@
     md5_buffer(tmp, strlen(tmp), md5);
     memcpy(def->uuid, md5, VIR_UUID_BUFLEN);
     def->uuid_specified = 1;
+
+    if (!(tmp = virJSONValueObjectGetString(jobj, "Type"))) {
+        parallelsParseError();
+        goto cleanup;
+    }
+
+    if (STREQ(tmp, "bridged")) {
+        def->forward.type = VIR_NETWORK_FORWARD_BRIDGE;
+
+        if (parallelsGetBridgedNetInfo(def, jobj) < 0)
+            goto cleanup;
+    } else if (STREQ(tmp, "host-only")) {
+        def->forward.type = VIR_NETWORK_FORWARD_NONE;
+
+        if (parallelsGetHostOnlyNetInfo(def, def->name) < 0)
+            goto cleanup;
+    } else {
+        parallelsParseError();
+        goto cleanup;
+    }

     if (!(net = virNetworkAssignDef(&privconn->networks, def, false))) {
         virNetworkDefFree(def);


Make a small code clean on handle_inter_mode()

Change-Id: I5fb4898045a481f7996c2ad019d2f741aab08fc7

--- av1/encoder/rdopt.c
+++ av1/encoder/rdopt.c
@@ -6744,24 +6744,24 @@
           av1_set_mvcost(x, mbmi->ref_frame[0], 0, mbmi->ref_mv_idx);
 #endif  // CONFIG_REF_MV
           rate_mv = av1_mv_bit_cost(&frame_mv[refs[0]].as_mv,
-                                    &x->mbmi_ext->ref_mvs[refs[0]][0].as_mv,
+                                    &mbmi_ext->ref_mvs[refs[0]][0].as_mv,
                                     x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
 #if CONFIG_REF_MV
           av1_set_mvcost(x, mbmi->ref_frame[1], 1, mbmi->ref_mv_idx);
 #endif  // CONFIG_REF_MV
           rate_mv += av1_mv_bit_cost(
-              &frame_mv[refs[1]].as_mv, &x->mbmi_ext->ref_mvs[refs[1]][0].as_mv,
+              &frame_mv[refs[1]].as_mv, &mbmi_ext->ref_mvs[refs[1]][0].as_mv,
               x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
         }
       } else if (this_mode == NEAREST_NEWMV || this_mode == NEAR_NEWMV) {
         frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int;
         rate_mv = av1_mv_bit_cost(&frame_mv[refs[1]].as_mv,
-                                  &x->mbmi_ext->ref_mvs[refs[1]][0].as_mv,
+                                  &mbmi_ext->ref_mvs[refs[1]][0].as_mv,
                                   x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
       } else {
         frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int;
         rate_mv = av1_mv_bit_cost(&frame_mv[refs[0]].as_mv,
-                                  &x->mbmi_ext->ref_mvs[refs[0]][0].as_mv,
+                                  &mbmi_ext->ref_mvs[refs[0]][0].as_mv,
                                   x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
       }
 #else
@@ -6777,13 +6777,13 @@
         av1_set_mvcost(x, mbmi->ref_frame[0], 0, mbmi->ref_mv_idx);
 #endif  // CONFIG_REF_MV
         rate_mv = av1_mv_bit_cost(&frame_mv[refs[0]].as_mv,
-                                  &x->mbmi_ext->ref_mvs[refs[0]][0].as_mv,
+                                  &mbmi_ext->ref_mvs[refs[0]][0].as_mv,
                                   x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
 #if CONFIG_REF_MV
         av1_set_mvcost(x, mbmi->ref_frame[1], 1, mbmi->ref_mv_idx);
 #endif  // CONFIG_REF_MV
         rate_mv += av1_mv_bit_cost(&frame_mv[refs[1]].as_mv,
-                                   &x->mbmi_ext->ref_mvs[refs[1]][0].as_mv,
+                                   &mbmi_ext->ref_mvs[refs[1]][0].as_mv,
                                    x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
       }
 #endif  // CONFIG_EXT_INTER


Setting up for switching over to 0mq

Setting up for switching over to 0mq

--- bin/mtr_srv/mtr_srv.h
+++ bin/mtr_srv/mtr_srv.h
@@ -5,30 +5,44 @@
 #define NUM_MTRS 4
 #define TIMEOUT 100	//100 * 10us = 1ms

+typedef struct {
+	double gearRatio[NUM_MTRS];
+	double ctsPerRad[NUM_MTRS];
+} mtrParms_t;
+
 typedef enum {
-	IDLE=1,	//Ready for command
-	CLIENT_REQ=2, //Client will set this first to alert other clients
-	SRV_GRANT=4, //Server grants request by setting client ID = reqID
-	RUN_CMD=8, //Client sets cmd id/data then sets flag to this state
-	BUSY=16,		//Server busy processing command
-	DATA_READY=32 //Signal the client to read the data, client must set back to ready
-} srvState_t;
+	MOTION=0,
+	PARAMETER
+} mtrCmdType_t;
+
+//The units are in radians and will be converted to encoder counts here out
+typedef struct {
+	double pos;
+	double velMax;
+	double velFinal;
+	double accel;
+} mtrMove_t;

 typedef struct {
-	mtrID_t 		mtrID;
-	cmdID_t 		cmdID;
-	srvState_t	state;
-	uint32_t		data;
-	uint32_t		reqID;
-	uint32_t		grantID;
-} mtrCmdIf_t;
+	mtrCmdType cmdType;			 //Is this a move or a parameter
+	uint8_t	enabled[NUM_MTRS]; //If true that joints command/move will be processed
+	mtrMove_t move[NUM_MTRS];   //motion details in radians
+	cmdID_t cmdID[NUM_MTRS];	 //command ID for each joint
+	uint32_t cmdData[NUM_MTRS]; //The data to tx with the command ID
+} mtrCmdRcv_t;

+typedef struct {
+	uint32_t reply[NUM_MTRS];
+} mtrCmdRep_t;
+
+
+//Messages to publish to subscribers to display record data
 typedef struct {
 	int32_t	pos[NUM_MTRS];
 	int32_t	cmdPos[NUM_MTRS];
 	int32_t	vel[NUM_MTRS];
 	int32_t	voltage[NUM_MTRS];
 	uint32_t	status[NUM_MTRS];
-} mtrTlmIf_t;
+} mtrTlmPub_t;

 #endif