Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Oct 14, 2024
1 parent e8e5d77 commit dc00a54
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,31 @@ jobs:
run: ./configure CC=clang
- name: Make
run: make all self-check

build-windows-x86_64:
name: Compile (Windows x86_64)
needs: [ dist ]
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
strategy:
fail-fast: false
matrix:
feature: [ enable-x86_64, disable-x86_64 ]
compiler: [ gcc, clang ]
steps:
- name: Download source package artifact
uses: actions/download-artifact@v4
with:
name: xpar-${{ github.sha }}
- uses: msys2/setup-msys2@v2
with:
update: true
install: make gcc nasm clang tar gzip diffutils
- name: Extract source package
run: tar --strip-components=1 -xf xpar-${{ github.sha }}.tar.gz
- name: Configure
run: ./configure CC=${{ matrix.compiler }} --${{ matrix.feature }}
- name: Make
run: make all self-check
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Consult the man page.

The file format will change until the stable version v1.0 is reached.
Do not use xpar for critical data, do not expect backwards or forwards
compatibility until then. Currently tested only on Zen4 x86_64 Linux.
compatibility until then.

# Development

Expand All @@ -42,6 +42,7 @@ A rough outline of some development-related topics below.
- Write a proper readme, manpages, etc.
- Make sure that this builds on Windows and port over the assembly code.
- Fuzz to find segfaults.
- Apple M1-specific optimizations to CRC32.
- 32- vs 64-bit code: determine if there's any compatibility issues.

Low priority:
Expand Down
9 changes: 2 additions & 7 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#error "Here, have a nickel kid. Go buy yourself a real computer."
#endif

// This often gets us asprintf.
#define _GNU_SOURCE
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
Expand Down Expand Up @@ -51,11 +53,4 @@ typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32;
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32;
typedef size_t sz;

// ============================================================================
// Reed-Solomon code parameters (223 bytes of input, 32 bytes of parity).
// ============================================================================
#define K 223
#define N 255
#define T 32

#endif
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ AC_PROG_MAKE_SET
AC_PROG_CC

AC_CHECK_HEADERS([getopt.h io.h])
AC_CHECK_FUNCS([getopt_long asprintf setmode stat commit isatty fsync mmap CreateFileMappingA])
AC_CHECK_FUNCS([getopt_long asprintf stat _commit _setmode isatty fsync mmap CreateFileMappingA])
AC_DEFINE([XPAR_MINOR], [xpar_version_minor], [Minor version number of xpar])
AC_DEFINE([XPAR_MAJOR], [xpar_version_major], [Major version number of xpar])

Expand Down
7 changes: 7 additions & 0 deletions jmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#include <sys/types.h>
#include <sys/stat.h>

// ============================================================================
// Reed-Solomon code parameters (223 bytes of input, 32 bytes of parity).
// ============================================================================
#define K 223
#define N 255
#define T 32

// ============================================================================
// Implementation of Reed-Solomon codes. Follows the BCH view. Original code
// was written by Phil Karn, KA9Q, in 1999. This is a modified version due to
Expand Down
26 changes: 17 additions & 9 deletions platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,24 @@ int getopt_long_only(int argc, char * const * argv, const char * optstring, cons
}
#endif

#if defined(HAVE_MMAP) || defined(HAVE_CREATEFILEMAPPINGA)
#if defined(HAVE_MMAP)
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#else
#endif

#if defined(HAVE_CREATEFILEMAPPINGA)
#include <windows.h>
#endif

#if defined(HAVE_MMAP) && defined(HAVE_CREATEFILEMAPPINGA)
// Bummer! Which one to choose? On Windows we will prefer the native
// function, and its presence clearly signifies that we are on Windows.
#undef HAVE_MMAP
#endif

#if defined(HAVE_MMAP) || defined(HAVE_CREATEFILEMAPPINGA)
// Both of the functions below add a single page (4K) of
// padding to the end of the file. Some of the code performs
// controlled buffer overflows by a few bytes (i.e. when
Expand Down Expand Up @@ -305,29 +313,29 @@ void xpar_unmap(mmap_t * file) {
#if defined(HAVE_MMAP)
if (file->map) munmap(file->map, file->size + 4096);
#else
if (file->data) UnmapViewOfFile(file->data);
if (file->map) UnmapViewOfFile(file->map);
#endif
file->map = NULL; file->size = 0;
}
#endif

#if defined(HAVE_SETMODE) && defined(HAVE_IO_H)
#if defined(HAVE_IO_H)
#include <io.h>
#include <fcntl.h>
#endif

void platform_init(void) {
#if defined(HAVE_SETMODE) && defined(HAVE_IO_H)
setmode(STDIN_FILENO, O_BINARY);
setmode(STDOUT_FILENO, O_BINARY);
#if defined(HAVE__SETMODE)
_setmode(STDIN_FILENO, O_BINARY);
_setmode(STDOUT_FILENO, O_BINARY);
#endif
}

#include <errno.h>
void xfclose(FILE * des) {
if(fflush(des)) FATAL_PERROR("fflush");
#if defined(HAVE_COMMIT) && defined(HAVE_IO_H)
if (commit(fileno(des))) FATAL_PERROR("commit");
#if defined(HAVE__COMMIT)
if (_commit(fileno(des))) FATAL_PERROR("commit");
#elif defined(HAVE_FSYNC)
// EINVAL means that we tried to fsync something that can't be synced.
if (fsync(fileno(des))) {
Expand Down
3 changes: 0 additions & 3 deletions platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
// ============================================================================
#if !defined(HAVE_ASPRINTF)
int asprintf(char **strp, const char *fmt, ...);
#else
#define _GNU_SOURCE
#include <stdio.h>
#endif

// ============================================================================
Expand Down

0 comments on commit dc00a54

Please sign in to comment.