少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
#include <config.h>
#include <glib.h>
 
#include <mono/metadata/file-mmap.h>
#include "MemoryMappedFile-c-api.h"
#include "File-c-api.h"
 
typedef struct {
    void *address;
    size_t length;
} MmapInstance;
 
enum {
    BAD_CAPACITY_FOR_FILE_BACKED = 1,
    CAPACITY_SMALLER_THAN_FILE_SIZE,
    FILE_NOT_FOUND,
    FILE_ALREADY_EXISTS,
    PATH_TOO_LONG,
    COULD_NOT_OPEN,
    CAPACITY_MUST_BE_POSITIVE,
    INVALID_FILE_MODE,
    COULD_NOT_MAP_MEMORY,
    ACCESS_DENIED,
    CAPACITY_LARGER_THAN_LOGICAL_ADDRESS_SPACE
};
 
#ifndef HOST_WIN32
 
typedef struct {
    int kind;
    int ref_count;
    size_t capacity;
    char *name;
    int fd;
} MmapHandle;
 
#endif
 
void mono_mmap_close (void *mmap_handle)
{
    /* Not Supported in UnityPAL */
    g_assert_not_reached();
}
 
void mono_mmap_configure_inheritability (void *mmap_handle, gboolean inheritability)
{
    /* Not Supported in UnityPAL */
    g_assert_not_reached();
}
 
void mono_mmap_flush (void *mmap_handle)
{
    /* Not Supported in UnityPAL */
    g_assert_not_reached();
}
 
void *mono_mmap_open_file (MonoString *string, int mode, MonoString *mapName, gint64 *capacity, int access, int options, int *error)
{
    /* Not Supported in UnityPAL */
    g_assert_not_reached();
    return NULL;
}
 
void *mono_mmap_open_handle (void *handle, MonoString *mapName, gint64 *capacity, int access, int options, int *error)
{
    /* Not Supported in UnityPAL */
    g_assert_not_reached();
    return NULL;
}
 
int mono_mmap_map (void *handle, gint64 offset, gint64 *size, int access, void **mmap_handle, void **base_address)
{
    /* We are dropping access parameter, UnityPAL does not support */
    g_assert (handle);
 
    MmapInstance *h = g_malloc0 (sizeof (MmapInstance));
    h->length = *size;
 
    h->address = UnityPalMemoryMappedFileMapWithParams((UnityPalFileHandle*) handle, (size_t) *size,  (size_t) offset);
 
    if (h->address)
    {
        *mmap_handle = h;
        *base_address = (char*) h->address + offset;
        return 0;
    }
    else
    {
        g_free (h);
        return COULD_NOT_MAP_MEMORY;
    }
}
 
gboolean
mono_mmap_unmap (void *mmap_handle)
{
    g_assert (mmap_handle);
 
    MmapInstance *h = (MmapInstance *)mmap_handle;
 
    UnityPalMemoryMappedFileUnmapWithParams(h->address, h->length);
 
    g_free (h);
 
    /* UnityPAL does not give any indication of success or failure of an unmap, forced
       to always return true */
 
    return TRUE;
}