Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merging Datacore-windows into test-build-branch #16

Merged
merged 12 commits into from
Oct 25, 2021
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.13)
project(OpenZFS)
project(OpenZFS LANGUAGES C CXX ASM)
SET (CMAKE_ASM_COMPILER_ID Clang)
SET (CMAKE_ASM_COMPILER clang-cl.exe)

include(GNUInstallDirs)

Expand Down
13 changes: 7 additions & 6 deletions include/os/windows/spl/sys/systm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ struct bsd_timeout_wrapper {
* bsd_timeout will create a new thread, and the new thread will
* first sleep the desired duration, then call the wanted function
*/
#define BSD_TIMEOUT_MAGIC 0x42994299
static inline void bsd_timeout_handler(void *arg)
{
struct bsd_timeout_wrapper *btw = arg;
KeWaitForSingleObject(&btw->timer, Executive, KernelMode, TRUE, NULL);
if (btw->init == 0x42994299) btw->func(btw->arg);
if (btw->init == BSD_TIMEOUT_MAGIC)
btw->func(btw->arg);
thread_exit();
}

#define BSD_TIMEOUT_MAGIC 0x42994299
static inline void bsd_untimeout(void(*func)(void *), void *ID)
{
/*
Expand All @@ -58,11 +59,11 @@ static inline void bsd_untimeout(void(*func)(void *), void *ID)
struct bsd_timeout_wrapper *btw = (struct bsd_timeout_wrapper *)ID;
LARGE_INTEGER p = { .QuadPart = -1 };
VERIFY3P(btw, !=, NULL);
btw->init = 0;
// Investigate why this assert triggers on Unload
// ASSERT(btw->init == BSD_TIMEOUT_MAGIC); // timer was not initialized
if (btw->init == BSD_TIMEOUT_MAGIC)
// If timer was armed, release it.
if (btw->init == BSD_TIMEOUT_MAGIC) {
btw->init = 0; // stop it from running func()
KeSetTimer(&btw->timer, p, NULL);
}
}

static inline void bsd_timeout(void *FUNC, void *ID, struct timespec *TIM)
Expand Down
10 changes: 10 additions & 0 deletions lib/libzfs/libzfs_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static zfs_uri_handler_t uri_handlers[] = {
{ NULL, NULL }
};

#ifndef _WIN32
static int
pkcs11_get_urandom(uint8_t *buf, size_t bytes)
{
Expand All @@ -101,6 +102,15 @@ pkcs11_get_urandom(uint8_t *buf, size_t bytes)

return (bytes_read);
}
#else
static int
pkcs11_get_urandom(uint8_t *buf, size_t bytes)
{
// random_init()/random_fini() are empty
random_get_bytes((uint8_t *)buf, bytes);
return (bytes);
}
#endif

static int
zfs_prop_parse_keylocation(libzfs_handle_t *restrict hdl, const char *str,
Expand Down
3 changes: 2 additions & 1 deletion lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
strlcat(mntopts, "," MNTOPT_ZFSUTIL, sizeof (mntopts));

/* Create the directory if it doesn't already exist */
#ifndef _WIN32
if (lstat(mountpoint, &buf) != 0) {
if (mkdirp(mountpoint, 0755) != 0) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
Expand All @@ -496,7 +497,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
mountpoint));
}
}

#endif
/*
* Overlay mounts are enabled by default but may be disabled
* via the 'overlay' property. The -O flag remains for compatibility.
Expand Down
8 changes: 4 additions & 4 deletions module/icp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ wdk_add_library(icpkern
api/kcf_miscapi.c
asm-x86_64/aes/aeskey.c
asm-x86_64/aes/aes_aesni.S
asm-x86_64/aes/aes_amd64.S
# asm-x86_64/aes/aes_amd64.S
asm-x86_64/modes/aesni-gcm-x86_64.S
asm-x86_64/modes/gcm_pclmulqdq.S
asm-x86_64/modes/ghash-x86_64.S
asm-x86_64/sha1/sha1-x86_64.S
asm-x86_64/sha2/sha256_impl.S
asm-x86_64/sha2/sha512_impl.S
# asm-x86_64/sha1/sha1-x86_64.S
# asm-x86_64/sha2/sha256_impl.S
# asm-x86_64/sha2/sha512_impl.S
core/kcf_callprov.c
core/kcf_mech_tabs.c
core/kcf_prov_lib.c
Expand Down
2 changes: 1 addition & 1 deletion module/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ wdk_add_library(luakern
#lundump.h
lvm.h
lzio.h
setjmp/setjmp_x86_64.S
setjmp/win_setjmp_x86_64.S
)
target_link_libraries(luakern PRIVATE splkern)
9 changes: 4 additions & 5 deletions module/lua/ldo.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ static intptr_t stack_remaining(void) {
#if defined(__i386__)
#define JMP_BUF_CNT 6
#elif defined(__x86_64__)
#ifdef _WIN32
#define JMP_BUF_CNT 10 // +rsi +rdi see win_setjmp_x86_64.S
#else
#define JMP_BUF_CNT 8
#endif
#elif defined(__sparc__) && defined(__arch64__)
#define JMP_BUF_CNT 6
#elif defined(__powerpc__)
Expand All @@ -94,11 +98,6 @@ static intptr_t stack_remaining(void) {
#define JMP_BUF_CNT 1
#endif

#if defined(_WIN32)
#undef JMP_BUF_CNT
#define JMP_BUF_CNT 1 // Until linking is figured out
#endif

typedef struct _label_t { long long unsigned val[JMP_BUF_CNT]; } label_t;

int setjmp(label_t *) __attribute__ ((__nothrow__));
Expand Down
13 changes: 12 additions & 1 deletion module/lua/setjmp/setjmp_x86_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
* Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
*/

#ifdef _WIN32

#define ENTRY(x) \
.text; \
.align 8; \
.globl x; \
x:

#define SET_SIZE(x)

#else

#define ENTRY(x) \
.text; \
Expand All @@ -33,7 +44,7 @@ x:

#define SET_SIZE(x) \
.size x, [.-x]

#endif // WIN32

/*
* Setjmp and longjmp implement non-local gotos using state vectors
Expand Down
95 changes: 95 additions & 0 deletions module/lua/setjmp/win_setjmp_x86_64.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Jorgen Lundman <lundman@lundman.net>
*/

// Windows x64:
// Calling: rcx, rdx, r8, and r9 (float: xmm0-xmm3)
// Return: rax (float: xmm0)
// Volatile: rax, rcx, rdx, r8-r11
// Nonvolatile: rbx, rbp, rsp, rdi, rsi, r12-r15

// Unix x64:
// Calling: rdi, rsi, rdx, rcx, r8, r9 (float: xmm0-xmm7)
// Return: rax (float: xmm0)
// Volatile:
// Nonvolatile: rbx, rbp, rsp, r12-r15

// outcome:
// rdi -> rcx
// save rdi, rsi.

#define ENTRY(x) \
.text; \
.align 8; \
.globl x; \
.def x; .scl 2; .type 32; .endef ; \
x:

#define SET_SIZE(x)

/*
* Setjmp and longjmp implement non-local gotos using state vectors
* type label_t.
*/
#ifdef __x86_64__

ENTRY(setjmp)
nop
movq %rsp, 0(%rcx)
movq %rbp, 8(%rcx)
movq %rbx, 16(%rcx)
movq %r12, 24(%rcx)
movq %r13, 32(%rcx)
movq %r14, 40(%rcx)
movq %r15, 48(%rcx)
movq %rdi, 56(%rcx)
movq %rsi, 64(%rcx)
movq 0(%rsp), %rdx /* return address */
movq %rdx, 72(%rcx) /* rip */
xorl %eax, %eax /* return 0 */
ret
SET_SIZE(setjmp)

ENTRY(longjmp)
movq 0(%rdi), %rsp
movq 8(%rdi), %rbp
movq 16(%rdi), %rbx
movq 24(%rdi), %r12
movq 32(%rdi), %r13
movq 40(%rdi), %r14
movq 48(%rdi), %r15
movq 56(%rdi), %rdi
movq 64(%rdi), %rsi
movq 72(%rdi), %rdx /* return address */
movq %rdx, 0(%rsp)
xorl %eax, %eax
incl %eax /* return 1 */
ret
SET_SIZE(longjmp)

#ifdef __ELF__
.section .note.GNU-stack,"",%progbits
#endif

#endif /* __x86_64__ */
39 changes: 39 additions & 0 deletions module/os/windows/spl/spl-vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,45 @@ spl_vnode_init(void)
void
spl_vnode_fini(void)
{
// We need to free all delayed vnodes - this can easily go
// wrong, still haven't figured out how to tell Windows
// to let go for a FILEOBJECT.
if (vnode_active > 0) {
vnode_drain_delayclose(1);
if (vnode_active > 0) {
// vnode ages up to 5s. then, we loop all
// still active nodes, mark them dead, and old
// so they are immediately freed, as well as
// go through the tree of fileobjects to free.

delay(hz*5); // hardcoded age, see vnode_drain_delayclose

dprintf("%s: forcing free (this can go wrong)n", __func__);
struct vnode *rvp;
clock_t then = gethrtime() - SEC2NSEC(6); // hardcoded

mutex_enter(&vnode_all_list_lock);
for (rvp = list_head(&vnode_all_list);
rvp;
rvp = list_next(&vnode_all_list, rvp)) {
vnode_fileobjects_t *node;

rvp->v_flags |= VNODE_DEAD|VNODE_FLUSHING;
rvp->v_age = then;

mutex_enter(&rvp->v_mutex);
while (node = avl_first(&rvp->v_fileobjects)) {
avl_remove(&rvp->v_fileobjects, node);
kmem_free(node, sizeof (*node));
}
mutex_exit(&rvp->v_mutex);
}
mutex_exit(&vnode_all_list_lock);
// here's hopin'
vnode_drain_delayclose(1);
}
}

mutex_destroy(&vnode_all_list_lock);
list_destroy(&vnode_all_list);
mutex_destroy(&spl_getf_lock);
Expand Down