Index: trunk/src/VBox/ImageMounter/vboximg-mount/Makefile.kmk
===================================================================
--- trunk/src/VBox/ImageMounter/vboximg-mount/Makefile.kmk	(revision 80529)
+++ trunk/src/VBox/ImageMounter/vboximg-mount/Makefile.kmk	(revision 80774)
@@ -19,21 +19,4 @@
 include $(KBUILD_PATH)/subheader.kmk
 
-ifeq ($(KBUILD_TARGET),darwin)
- VBOX_PATH_FUSE ?= $(lastword $(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/osxfuse/v*)))
- ifneq ($(VBOX_PATH_FUSE),)
-  LIB_FUSE     := $(VBOX_PATH_FUSE)/lib/libosxfuse.dylib
-  LIBPATH_FUSE := $(VBOX_PATH_FUSE)/lib
-  FUSE_INCS    := $(VBOX_PATH_FUSE)/include/osxfuse
- else
-  LIB_FUSE     := /usr/local/lib/libosxfuse.dylib
-  LIBPATH_FUSE := /usr/local/lib
-  FUSE_INCS    := /usr/local/include/osxfuse \
-  	/usr/local/include
- endif
-else
- LIB_FUSE := fuse
- FUSE_INCS := /usr/include
-endif
-
 #
 # vboximg-mount - Disk Image Flatting FUSE Program.
@@ -53,13 +36,10 @@
     vboximgMedia.h \
     vboximgOpts.h \
-    SelfSizingTable.h
+    SelfSizingTable.h \
+    fuse.cpp
 
 vboximg-mount_LIBS = \
 	$(LIB_DDU) \
-	$(LIB_RUNTIME) \
-	$(LIB_FUSE)
-
-vboximg-mount_INCS = $(FUSE_INCS)
-#vboximg-mount_CXXFLAGS.darwin = -std=c++11
+	$(LIB_RUNTIME)
 
 include $(FILE_KBUILD_SUB_FOOTER)
Index: trunk/src/VBox/ImageMounter/vboximg-mount/fuse-calls.h
===================================================================
--- trunk/src/VBox/ImageMounter/vboximg-mount/fuse-calls.h	(revision 80774)
+++ trunk/src/VBox/ImageMounter/vboximg-mount/fuse-calls.h	(revision 80774)
@@ -0,0 +1,66 @@
+/** @file
+ * Stubs for dynamically loading libfuse/libosxfuse and the symbols which are needed by
+ * VirtualBox.
+ */
+
+/*
+ * Copyright (C) 2019 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/** The file name of the fuse library */
+#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+# define RT_RUNTIME_LOADER_LIB_NAME  "libfuse.so.2"
+#elif defined(RT_OS_DARWIN)
+# define RT_RUNTIME_LOADER_LIB_NAME  "libosxfuse.dylib"
+#else
+# error "Unsupported host OS, manual work required"
+#endif
+
+/** The name of the loader function */
+#define RT_RUNTIME_LOADER_FUNCTION  RTFuseLoadLib
+
+/** The following are the symbols which we need from the fuse library. */
+#define RT_RUNTIME_LOADER_INSERT_SYMBOLS \
+ RT_PROXY_STUB(fuse_main_real, int, (int argc, char **argv, struct fuse_operations *fuse_ops, size_t op_size, void *pv), \
+                 (argc, argv, fuse_ops, op_size, pv)) \
+ RT_PROXY_STUB(fuse_opt_parse, int, (struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc), \
+                 (args, data, opts, proc)) \
+ RT_PROXY_STUB(fuse_opt_add_arg, int, (struct fuse_args *args, const char *arg), \
+                 (args, arg)) \
+
+#ifdef VBOX_FUSE_GENERATE_HEADER
+# define RT_RUNTIME_LOADER_GENERATE_HEADER
+# define RT_RUNTIME_LOADER_GENERATE_DECLS
+# include <iprt/runtime-loader.h>
+# undef RT_RUNTIME_LOADER_GENERATE_HEADER
+# undef RT_RUNTIME_LOADER_GENERATE_DECLS
+
+#elif defined(VBOX_FUSE_GENERATE_BODY)
+# define RT_RUNTIME_LOADER_GENERATE_BODY_STUBS
+# include <iprt/runtime-loader.h>
+# undef RT_RUNTIME_LOADER_GENERATE_BODY_STUBS
+
+#else
+# error This file should only be included to generate stubs for loading the Fuse library at runtime
+#endif
+
+#undef RT_RUNTIME_LOADER_LIB_NAME
+#undef RT_RUNTIME_LOADER_INSERT_SYMBOLS
+
Index: trunk/src/VBox/ImageMounter/vboximg-mount/fuse.cpp
===================================================================
--- trunk/src/VBox/ImageMounter/vboximg-mount/fuse.cpp	(revision 80774)
+++ trunk/src/VBox/ImageMounter/vboximg-mount/fuse.cpp	(revision 80774)
@@ -0,0 +1,34 @@
+/* $Id$ */
+/** @file
+ *
+ * Module to dynamically load libfuse and load all symbols
+ * which are needed by vboximg-mount.
+ */
+
+/*
+ * Copyright (C) 2019 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+#define LOG_GROUP RTLOGGROUP_DEFAULT
+#include "fuse.h"
+
+/* Declarations of the functions that we need from libfuse */
+#define VBOX_FUSE_GENERATE_BODY
+#include "fuse-calls.h"
Index: trunk/src/VBox/ImageMounter/vboximg-mount/fuse.h
===================================================================
--- trunk/src/VBox/ImageMounter/vboximg-mount/fuse.h	(revision 80774)
+++ trunk/src/VBox/ImageMounter/vboximg-mount/fuse.h	(revision 80774)
@@ -0,0 +1,175 @@
+/** @file
+ * Module to dynamically load libfuse/libosxfuse and load all symbols which are needed by
+ * vboximg-mount.
+ */
+
+/*
+ * Copyright (C) 2019 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ * --------------------------------------------------------------------
+ *
+ * This code is based on and contains parts of:
+ *
+ * libfuse
+ *
+ * FUSE: Filesystem in Userspace
+ * Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
+ *
+ * This program can be distributed under the terms of the GNU LGPLv2.
+ * See the file COPYING.LIB.
+ */
+
+#ifndef VBOX_INCLUDED_SRC_vboximg_mount_fuse_h
+#define VBOX_INCLUDED_SRC_vboximg_mount_fuse_h
+#ifndef RT_WITHOUT_PRAGMA_ONCE
+# pragma once
+#endif
+
+#include <iprt/types.h>
+#include <iprt/stdarg.h>
+
+RT_C_DECLS_BEGIN
+
+/* Forward declaration of stat buffer. */
+struct stat;
+
+/**
+ * Fuse option structure.
+ */
+typedef struct fuse_opt
+{
+    /** Argument template with optional parameter formatting. */
+    const char      *pszTempl;
+    /** Offset where the parameter is stored inside the data struct passed to fuse_opt_parse(). */
+    unsigned long   uOffset;
+    /** The value to set the variable to if the template has no argument format. */
+    int             uVal;
+} fuse_opt;
+
+#define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
+#define FUSE_OPT_END { NULL, 0, 0 }
+#define FUSE_OPT_KEY_NONOPT  -2
+
+/**
+ * Fuse argument vector.
+ */
+typedef struct fuse_args
+{
+    int argc;
+    char **argv;
+    int allocated;
+} fuse_args;
+
+#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
+
+
+/**
+ * Fuse file info structure - for us only the fh member is of interest for now.
+ */
+typedef struct fuse_file_info
+{
+    int           flags;
+    unsigned long fh_old;
+    int           writepage;
+    unsigned int  oth_flags;
+    uint64_t      fh;
+    uint64_t      lock_owner;
+} fuse_file_info;
+
+/** Option processing function. */
+typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key, struct fuse_args *outargs);
+
+/** Directory entry filler function. */
+typedef int (*fuse_fill_dir_t) (void *buf, const char *name, const struct stat *stbuf, off_t off);
+
+
+/**
+ * Fuse FS callback table implementing the filesystem functionality.
+ *
+ * Only required methods are filled out, others are stubbed (change as required).
+ */
+typedef struct fuse_operations
+{
+    int (*getattr) (const char *pszPath, struct stat *pStatBuf);
+    int (*readlink) (const char *pszPath, char *pbBuf, size_t cbBuf);
+    PFNRT getdir;
+    PFNRT mknod;
+    PFNRT mkdir;
+    PFNRT unlink;
+    PFNRT rmdir;
+    PFNRT symlink;
+    PFNRT rename;
+    PFNRT link;
+    PFNRT chmod;
+    PFNRT chown;
+    PFNRT truncate;
+    PFNRT utime;
+    int (*open) (const char *pszPath, struct fuse_file_info *pInfo);
+    int (*read) (const char *pszPath, char *pbBuf, size_t cbBuf, off_t off, struct fuse_file_info *pInfo);
+    int (*write) (const char *pszPath, const char *pbBuf, size_t cbBuf, off_t off, struct fuse_file_info *pInfo);
+    PFNRT statfs;
+    PFNRT flush;
+    int (*release) (const char *pszPath, struct fuse_file_info *pInfo);
+    PFNRT fsync;
+    PFNRT setxattr; /* OSXFuse has a different parameter layout. */
+    PFNRT getxattr; /* OSXFuse has a different parameter layout. */
+    PFNRT listxattr;
+    PFNRT removexattr;
+    int (*opendir) (const char *pszPath, struct fuse_file_info *pInfo);
+    int (*readdir) (const char *pszPath, void *pvBuf, fuse_fill_dir_t pfnFiller, off_t offset, struct fuse_file_info *pInfo);
+    PFNRT releasedir;
+    PFNRT fsyncdir;
+    PFNRT init;
+    PFNRT destroy;
+    PFNRT access;
+    PFNRT create;
+    PFNRT ftruncate;
+    PFNRT fgettatr;
+    PFNRT lock;
+    PFNRT utimens;
+    PFNRT bmap;
+    unsigned int flag_null_path_ok: 1;
+    unsigned int flag_nopath: 1;
+    unsigned int flag_utime_omit_ok: 1;
+    unsigned int flag_reserved: 20;
+    PFNRT ioctl;
+    PFNRT poll;
+    PFNRT write_buf;
+    PFNRT read_buf;
+    PFNRT flock;
+    PFNRT fallocate;
+#ifdef RT_OS_DARWIN
+    PFNRT rsvd00;
+    PFNRT rsvd01;
+    PFNRT rsvd02;
+    PFNRT statfs_x;
+    PFNRT setvolname;
+    PFNRT exchange;
+    PFNRT getxtimes;
+    PFNRT setbkuptime;
+    PFNRT setchgtime;
+    PFNRT setcrtime;
+    PFNRT chflags;
+    PFNRT setattr_x;
+    PFNRT fsetattr_x;
+#endif
+} fuse_operations;
+
+/* Declarations of the functions that we need from libfuse */
+#define VBOX_FUSE_GENERATE_HEADER
+
+#include "fuse-calls.h"
+
+#undef VBOX_FUSE_GENERATE_HEADER
+
+RT_C_DECLS_END
+
+#endif /* !VBOX_INCLUDED_SRC_vboximg_mount_fuse_h */
+
Index: trunk/src/VBox/ImageMounter/vboximg-mount/vboximg-mount.cpp
===================================================================
--- trunk/src/VBox/ImageMounter/vboximg-mount/vboximg-mount.cpp	(revision 80529)
+++ trunk/src/VBox/ImageMounter/vboximg-mount/vboximg-mount.cpp	(revision 80774)
@@ -29,5 +29,4 @@
 #endif
 #define MAX_READERS (INT32_MAX / 32)
-#include <fuse.h>
 #ifdef UNIX_DERIVATIVE
 #include <errno.h>
@@ -80,4 +79,5 @@
 #include <iprt/time.h>
 
+#include "fuse.h"
 #include "vboximgCrypto.h"
 #include "vboximgMedia.h"
@@ -934,4 +934,8 @@
         return RTMsgErrorExitFailure("VDInit failed, rc=%Rrc\n", rc);
 
+    rc = RTFuseLoadLib();
+    if (RT_FAILURE(rc))
+        return RTMsgErrorExitFailure("Failed to load the fuse library, rc=%Rrc\n", rc);
+
     memset(&g_vboximgOps, 0, sizeof(g_vboximgOps));
     g_vboximgOps.open        = vboximgOp_open;
@@ -1330,5 +1334,5 @@
         RTPrintf("\nvboximg-mount: Going into background...\n");
 
-    rc = fuse_main(args.argc, args.argv, &g_vboximgOps, NULL);
+    rc = fuse_main_real(args.argc, args.argv, &g_vboximgOps, sizeof(g_vboximgOps), NULL);
 
     int rc2 = RTVfsFileRelease(g_hVfsFileDisk);
