From 9d4e8c921196c2303812e3673b27f781218943aa Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 7 Mar 2015 06:20:55 +0100
Subject: [PATCH] nvcuda: Implement cuModuleLoad wrapper function.

---
 dlls/nvcuda/nvcuda.c    | 22 ++++++++++++++++++++++
 dlls/nvcuda/nvcuda.spec |  2 +-
 include/cuda.h          |  1 +
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/dlls/nvcuda/nvcuda.c b/dlls/nvcuda/nvcuda.c
index e11a1d51a9d..7c296cb6861 100644
--- a/dlls/nvcuda/nvcuda.c
+++ b/dlls/nvcuda/nvcuda.c
@@ -29,6 +29,7 @@
 
 #include "windef.h"
 #include "winbase.h"
+#include "winnls.h"
 #include "wine/library.h"
 #include "wine/debug.h"
 #include "wine/list.h"
@@ -261,6 +262,7 @@ static CUresult (*pcuModuleGetGlobal)(CUdeviceptr *dptr, size_t *bytes, CUmodule
 static CUresult (*pcuModuleGetGlobal_v2)(CUdeviceptr *dptr, size_t *bytes, CUmodule hmod, const char *name);
 static CUresult (*pcuModuleGetSurfRef)(CUsurfref *pSurfRef, CUmodule hmod, const char *name);
 static CUresult (*pcuModuleGetTexRef)(CUtexref *pTexRef, CUmodule hmod, const char *name);
+static CUresult (*pcuModuleLoad)(CUmodule *module, const char *fname);
 static CUresult (*pcuModuleLoadData)(CUmodule *module, const void *image);
 static CUresult (*pcuModuleLoadDataEx)(CUmodule *module, const void *image, unsigned int numOptions, CUjit_option *options, void **optionValues);
 static CUresult (*pcuModuleLoadFatBinary)(CUmodule *module, const void *fatCubin);
@@ -606,6 +608,7 @@ static BOOL load_functions(void)
     LOAD_FUNCPTR(cuModuleGetGlobal_v2);
     LOAD_FUNCPTR(cuModuleGetSurfRef);
     LOAD_FUNCPTR(cuModuleGetTexRef);
+    LOAD_FUNCPTR(cuModuleLoad);
     LOAD_FUNCPTR(cuModuleLoadData);
     LOAD_FUNCPTR(cuModuleLoadDataEx);
     LOAD_FUNCPTR(cuModuleLoadFatBinary);
@@ -1883,6 +1886,25 @@ CUresult WINAPI wine_cuModuleGetTexRef(CUtexref *pTexRef, CUmodule hmod, const c
     return pcuModuleGetTexRef(pTexRef, hmod, name);
 }
 
+CUresult WINAPI wine_cuModuleLoad(CUmodule *module, const char *fname)
+{
+    WCHAR filenameW[MAX_PATH];
+    char *unix_name;
+    CUresult ret;
+
+    TRACE("(%p, %s)\n", module, fname);
+
+    if (!fname)
+        return CUDA_ERROR_INVALID_VALUE;
+
+    MultiByteToWideChar(CP_ACP, 0, fname, -1, filenameW, ARRAY_SIZE(filenameW));
+    unix_name = wine_get_unix_file_name( filenameW );
+
+    ret = pcuModuleLoad(module, unix_name);
+    HeapFree(GetProcessHeap(), 0, unix_name);
+    return ret;
+}
+
 CUresult WINAPI wine_cuModuleLoadData(CUmodule *module, const void *image)
 {
     TRACE("(%p, %p)\n", module, image);
diff --git a/dlls/nvcuda/nvcuda.spec b/dlls/nvcuda/nvcuda.spec
index 84b5fcd8f4d..492d6c129c1 100644
--- a/dlls/nvcuda/nvcuda.spec
+++ b/dlls/nvcuda/nvcuda.spec
@@ -240,7 +240,7 @@
 @ stdcall cuModuleGetGlobal_v2(ptr ptr ptr str) wine_cuModuleGetGlobal_v2
 @ stdcall cuModuleGetSurfRef(ptr ptr str) wine_cuModuleGetSurfRef
 @ stdcall cuModuleGetTexRef(ptr ptr str) wine_cuModuleGetTexRef
-@ stub cuModuleLoad
+@ stdcall cuModuleLoad(ptr str) wine_cuModuleLoad
 @ stdcall cuModuleLoadData(ptr ptr) wine_cuModuleLoadData
 @ stdcall cuModuleLoadDataEx(ptr ptr long ptr ptr) wine_cuModuleLoadDataEx
 @ stdcall cuModuleLoadFatBinary(ptr ptr) wine_cuModuleLoadFatBinary
diff --git a/include/cuda.h b/include/cuda.h
index 327fe4d8ef3..2bf20f9533e 100644
--- a/include/cuda.h
+++ b/include/cuda.h
@@ -23,6 +23,7 @@
 #define CUDA_ERROR_INVALID_VALUE    1
 #define CUDA_ERROR_OUT_OF_MEMORY    2
 #define CUDA_ERROR_INVALID_CONTEXT  201
+#define CUDA_ERROR_FILE_NOT_FOUND   301
 #define CUDA_ERROR_INVALID_HANDLE   400
 #define CUDA_ERROR_NOT_SUPPORTED    801
 #define CUDA_ERROR_UNKNOWN          999
-- 
2.27.0

