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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* GATE PROJECT LICENSE:
+----------------------------------------------------------------------------+
| Copyright(c) 2018-2026, Stefan Meislinger                                  |
| All rights reserved.                                                       |
|                                                                            |
| Redistribution and use in source and binary forms, with or without         |
| modification, are permitted provided that the following conditions are met:|
|                                                                            |
| 1. Redistributions of source code must retain the above copyright notice,  |
|    this list of conditions and the following disclaimer.                   |
| 2. Redistributions in binary form must reproduce the above copyright       |
|    notice, this list of conditions and the following disclaimer in the     |
|    documentation and/or other materials provided with the distribution.    |
|                                                                            |
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  |
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE    |
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR        |
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF       |
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS   |
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN    |
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)    |
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF     |
| THE POSSIBILITY OF SUCH DAMAGE.                                            |
+----------------------------------------------------------------------------+
*/

#include "gate/system/os.h"
#include "gate/results.h"
#include "gate/strings.h"
#include "gate/debugging.h"

#if defined(GATE_SYS_WASM)

#include <emscripten/version.h>


gate_result_t gate_os_get_platform(gate_uint32_t* ptr_platform)
{
    if (ptr_platform)
    {
        *ptr_platform = GATE_OS_PLATFORM_WASM;
    }
    return GATE_RESULT_OK;
}

gate_uint32_t gate_os_address_space()
{
    return 32;
}

gate_uint32_t gate_os_up_time_seconds()
{
    return 0;
}

gate_result_t gate_os_print_osname(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
{
    static gate_string_t const wasm_os_name = GATE_STRING_INIT_STATIC("WebAssembly");
    gate_size_t len = gate_string_to_buffer(&wasm_os_name, buffer, buffer_len);
    
    if (buffer_used)
    {
        *buffer_used = len;
    }
    return (len > 0) ? GATE_RESULT_OK : GATE_RESULT_FAILED;
}

gate_result_t gate_os_print_productname(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
{
    static gate_string_t const wasm_product_name = GATE_STRING_INIT_STATIC("Emscripten WASM");

    gate_size_t len = gate_string_to_buffer(&wasm_product_name, buffer, buffer_len);
    
    if (buffer_used)
    {
        *buffer_used = len;
    }
    return (len > 0) ? GATE_RESULT_OK : GATE_RESULT_FAILED;
}

gate_result_t gate_os_get_version(gate_version_t* ptr_version)
{
    if (ptr_version)
    {
        /* NOTICE: lower-case variant was deprecated, upper-case is latest standard */
        ptr_version->major = 
#if defined(__EMSCRIPTEN_MAJOR__)
            __EMSCRIPTEN_MAJOR__;<--- Skipping configuration 'GATE_SYS_WASM;__EMSCRIPTEN_MAJOR__' since the value of '__EMSCRIPTEN_MAJOR__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#else
            __EMSCRIPTEN_major__;
#endif

        ptr_version->minor =
#if defined(__EMSCRIPTEN_MINOR__)
            __EMSCRIPTEN_MINOR__;<--- Skipping configuration 'GATE_SYS_WASM;__EMSCRIPTEN_MINOR__' since the value of '__EMSCRIPTEN_MINOR__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#else
            __EMSCRIPTEN_minor__;
#endif

        ptr_version->patch =
#if defined(__EMSCRIPTEN_TINY__)
            __EMSCRIPTEN_TINY__;<--- Skipping configuration 'GATE_SYS_WASM;__EMSCRIPTEN_TINY__' since the value of '__EMSCRIPTEN_TINY__' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
#else
            __EMSCRIPTEN_tiny__;
#endif

        ptr_version->build = 0;
    }
    return GATE_RESULT_OK;
}

gate_result_t gate_os_get_hostname_str(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
{
    (void)buffer;
    (void)buffer_len;
    (void)buffer_used;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_set_hostname(gate_string_t const* hostname)
{
    (void)hostname;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_hostdomainname_str(char* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
{
    (void)buffer;
    (void)buffer_len;
    (void)buffer_used;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_set_hostdomainname(gate_string_t const* domainname)
{
    (void)domainname;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_uid(gate_uint8_t* buffer, gate_size_t buffer_len, gate_size_t* buffer_used)
{
    (void)buffer;
    (void)buffer_len;
    (void)buffer_used;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_shutdown()
{
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_reboot()
{
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_cpu_architecture(gate_enumint_t* ptr_arch)
{
    (void)ptr_arch;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_cpu_info(gate_os_cpuinfo_t* info)
{
    (void)info;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_enum_cpu_features(gate_os_cpu_feature_callback_t callback, void* param)
{
    (void)callback;
    (void)param;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_process_cpu_affinity(gate_os_cpu_activation_t* affinity)
{
    (void)affinity;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_set_process_cpu_affinity(gate_os_cpu_activation_t const* affinity)
{
    (void)affinity;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_cpu_load_init(gate_os_cpu_load_state_t* state)
{
    (void)state;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_cpu_load_update(gate_os_cpu_load_state_t* state, gate_uint16_t* load65535)
{
    (void)state;
    (void)load65535;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_cpu_load_uninit(gate_os_cpu_load_state_t* state)
{
    (void)state;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_physical_memory(gate_uint64_t* ptr_total, gate_uint64_t* ptr_available)
{
    (void)ptr_total;
    (void)ptr_available;
    return GATE_RESULT_NOTIMPLEMENTED;
}

gate_result_t gate_os_get_virtual_memory(gate_uint64_t* ptr_total, gate_uint64_t* ptr_available)
{
    (void)ptr_total;
    (void)ptr_available;
    return GATE_RESULT_NOTIMPLEMENTED;
}

#endif  /* GATE_SYS_WASM */