Skip to content

Commit

Permalink
x264: reformat input.patch with #ifdef phoenix
Browse files Browse the repository at this point in the history
JIRA: PP-213
  • Loading branch information
niewim19 committed Sep 6, 2024
1 parent 4efb0f1 commit dbf53c3
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions x264/patches/input.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

--- x264_org/input/input.c 2024-09-05 11:57:22.943594154 +0200
+++ x264/input/input.c 2024-09-05 11:57:41.344630765 +0200
@@ -227,6 +227,15 @@
--- x264_org/input/input.c 2024-09-06 10:29:54.784756723 +0200
+++ x264/input/input.c 2024-09-06 11:05:56.206158357 +0200
@@ -227,7 +227,19 @@
}
#else
size_t padded_size = size + MMAP_PADDING;
+#ifdef phoenix
+ /**
+ * PHOENIX-RTOS PATCH
+ *
Expand All @@ -13,35 +13,33 @@
+ *
+ * https://github.com/phoenix-rtos/phoenix-rtos-project/issues/1155
+ */
+ padded_size = (1 + padded_size / SIZE_PAGE) * SIZE_PAGE;
+ if( (base = mmap( NULL, ((padded_size + (SIZE_PAGE - 1)) & ~(SIZE_PAGE - 1)), PROT_READ, MAP_PRIVATE, h->fd, offset )) != MAP_FAILED )
+#else
if( (base = mmap( NULL, padded_size, PROT_READ, MAP_PRIVATE, h->fd, offset )) != MAP_FAILED )
+#endif
{
/* Ask the OS to readahead pages. This improves performance whereas
@@ -241,9 +250,19 @@
/* Remap the file mapping of any padding that crosses a page boundary past the end of
* forcing page faults by manually accessing every page does not.
@@ -242,7 +254,22 @@
* the file into a copy of the last valid page to prevent reads from invalid memory. */
size_t aligned_size = (padded_size - 1) & ~h->align_mask;
- if( offset + aligned_size >= h->file_size )
- mmap( base + aligned_size, padded_size - aligned_size, PROT_READ, MAP_PRIVATE|MAP_FIXED, h->fd, (offset + size - 1) & ~h->align_mask );
-
+ /**
+ * PHOENIX-RTOS PATCH
+ *
+ * Phoenix implementation of mmap() fails if `size` is not aligned to page size
+ * It is important to remove this patch when this issue is resolved.
+ *
+ * https://github.com/phoenix-rtos/phoenix-rtos-project/issues/1155
+ */
+ if( offset + aligned_size >= h->file_size ) {
+ size_t paddedMinusAligned_aligned = (padded_size - aligned_size);
+ paddedMinusAligned_aligned = (1 + paddedMinusAligned_aligned / SIZE_PAGE) * SIZE_PAGE;
+ mmap( base + aligned_size, paddedMinusAligned_aligned, PROT_READ, MAP_PRIVATE|MAP_FIXED, h->fd, (offset + size - 1) & ~h->align_mask );
if( offset + aligned_size >= h->file_size )
+#ifdef phoenix
+ {
+ /**
+ * PHOENIX-RTOS PATCH
+ *
+ * Phoenix implementation of mmap() fails if `size` is not aligned to page size
+ * It is important to remove this patch when this issue is resolved.
+ *
+ * https://github.com/phoenix-rtos/phoenix-rtos-project/issues/1155
+ */
+ size_t phoenix_paddedMinusAligned = padded_size - aligned_size;
+ mmap( base + aligned_size, ((phoenix_paddedMinusAligned + (SIZE_PAGE - 1)) & ~(SIZE_PAGE - 1)), PROT_READ, MAP_PRIVATE|MAP_FIXED, h->fd, (offset + size - 1) & ~h->align_mask );
+ }
+#else
mmap( base + aligned_size, padded_size - aligned_size, PROT_READ, MAP_PRIVATE|MAP_FIXED, h->fd, (offset + size - 1) & ~h->align_mask );
+#endif

return base + align;
}
#endif
@@ -272,3 +291,4 @@
CloseHandle( h->map_handle );
#endif
}
+

0 comments on commit dbf53c3

Please sign in to comment.