Flutter Engine
The Flutter Engine
io_natives.cc
Go to the documentation of this file.
1// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "bin/io_natives.h"
6
7#include <stdlib.h>
8#include <string.h>
9
10#include "bin/builtin.h"
11#include "bin/dartutils.h"
12#include "bin/socket_base.h"
13#include "include/dart_api.h"
14#include "platform/assert.h"
15
16namespace dart {
17namespace bin {
18
19// Lists the native functions implementing advanced dart:io classes.
20// Some classes, like File and Directory, list their implementations in
21// builtin_natives.cc instead.
22#define IO_NATIVE_LIST(V) \
23 V(Crypto_GetRandomBytes, 1) \
24 V(Directory_Create, 2) \
25 V(Directory_CreateTemp, 2) \
26 V(Directory_Current, 1) \
27 V(Directory_Delete, 3) \
28 V(Directory_Exists, 2) \
29 V(Directory_FillWithDirectoryListing, 5) \
30 V(Directory_GetAsyncDirectoryListerPointer, 1) \
31 V(Directory_Rename, 3) \
32 V(Directory_SetAsyncDirectoryListerPointer, 2) \
33 V(Directory_SetCurrent, 2) \
34 V(Directory_SystemTemp, 1) \
35 V(EventHandler_SendData, 3) \
36 V(EventHandler_TimerMillisecondClock, 0) \
37 V(File_AreIdentical, 3) \
38 V(File_Close, 1) \
39 V(File_Copy, 3) \
40 V(File_Create, 3) \
41 V(File_CreateLink, 3) \
42 V(File_CreatePipe, 1) \
43 V(File_Delete, 2) \
44 V(File_DeleteLink, 2) \
45 V(File_Exists, 2) \
46 V(File_Flush, 1) \
47 V(File_GetPointer, 1) \
48 V(File_GetFD, 1) \
49 V(File_GetStdioHandleType, 1) \
50 V(File_GetType, 3) \
51 V(File_LastAccessed, 2) \
52 V(File_LastModified, 2) \
53 V(File_Length, 1) \
54 V(File_LengthFromPath, 2) \
55 V(File_LinkTarget, 2) \
56 V(File_Lock, 4) \
57 V(File_Open, 3) \
58 V(File_OpenStdio, 1) \
59 V(File_Position, 1) \
60 V(File_Read, 2) \
61 V(File_ReadByte, 1) \
62 V(File_ReadInto, 4) \
63 V(File_Rename, 3) \
64 V(File_RenameLink, 3) \
65 V(File_ResolveSymbolicLinks, 2) \
66 V(File_SetLastAccessed, 3) \
67 V(File_SetLastModified, 3) \
68 V(File_SetPointer, 2) \
69 V(File_SetPosition, 2) \
70 V(File_Stat, 2) \
71 V(File_Truncate, 2) \
72 V(File_WriteByte, 2) \
73 V(File_WriteFrom, 4) \
74 V(FileSystemWatcher_CloseWatcher, 1) \
75 V(FileSystemWatcher_GetSocketId, 2) \
76 V(FileSystemWatcher_InitWatcher, 0) \
77 V(FileSystemWatcher_IsSupported, 0) \
78 V(FileSystemWatcher_ReadEvents, 2) \
79 V(FileSystemWatcher_UnwatchPath, 2) \
80 V(FileSystemWatcher_WatchPath, 5) \
81 V(Filter_CreateZLibDeflate, 8) \
82 V(Filter_CreateZLibInflate, 4) \
83 V(Filter_Process, 4) \
84 V(Filter_Processed, 3) \
85 V(ResourceHandleImpl_toFile, 1) \
86 V(ResourceHandleImpl_toSocket, 1) \
87 V(ResourceHandleImpl_toRawSocket, 1) \
88 V(ResourceHandleImpl_toRawDatagramSocket, 1) \
89 V(InternetAddress_Parse, 1) \
90 V(InternetAddress_ParseScopedLinkLocalAddress, 1) \
91 V(InternetAddress_RawAddrToString, 1) \
92 V(IOService_NewServicePort, 0) \
93 V(Namespace_Create, 2) \
94 V(Namespace_GetDefault, 0) \
95 V(Namespace_GetPointer, 1) \
96 V(OSError_inProgressErrorCode, 0) \
97 V(Platform_NumberOfProcessors, 0) \
98 V(Platform_OperatingSystem, 0) \
99 V(Platform_OperatingSystemVersion, 0) \
100 V(Platform_PathSeparator, 0) \
101 V(Platform_LocalHostname, 0) \
102 V(Platform_ExecutableName, 0) \
103 V(Platform_ResolvedExecutableName, 0) \
104 V(Platform_Environment, 0) \
105 V(Platform_ExecutableArguments, 0) \
106 V(Platform_GetVersion, 0) \
107 V(Platform_LocaleName, 0) \
108 V(Process_Start, 12) \
109 V(Process_Wait, 5) \
110 V(Process_KillPid, 2) \
111 V(Process_SetExitCode, 1) \
112 V(Process_GetExitCode, 0) \
113 V(Process_Exit, 1) \
114 V(Process_Sleep, 1) \
115 V(Process_Pid, 1) \
116 V(Process_SetSignalHandler, 1) \
117 V(Process_ClearSignalHandler, 1) \
118 V(ProcessInfo_CurrentRSS, 0) \
119 V(ProcessInfo_MaxRSS, 0) \
120 V(RawSocketOption_GetOptionValue, 1) \
121 V(SecureSocket_Connect, 7) \
122 V(SecureSocket_Destroy, 1) \
123 V(SecureSocket_FilterPointer, 1) \
124 V(SecureSocket_GetSelectedProtocol, 1) \
125 V(SecureSocket_Handshake, 2) \
126 V(SecureSocket_MarkAsTrusted, 3) \
127 V(SecureSocket_NewX509CertificateWrapper, 1) \
128 V(SecureSocket_Init, 1) \
129 V(SecureSocket_PeerCertificate, 1) \
130 V(SecureSocket_RegisterBadCertificateCallback, 2) \
131 V(SecureSocket_RegisterKeyLogPort, 2) \
132 V(SecureSocket_RegisterHandshakeCompleteCallback, 2) \
133 V(SecurityContext_Allocate, 1) \
134 V(SecurityContext_UsePrivateKeyBytes, 3) \
135 V(SecurityContext_SetAlpnProtocols, 3) \
136 V(SecurityContext_SetClientAuthoritiesBytes, 3) \
137 V(SecurityContext_SetTrustedCertificatesBytes, 3) \
138 V(SecurityContext_TrustBuiltinRoots, 1) \
139 V(SecurityContext_SetAllowTlsRenegotiation, 2) \
140 V(SecurityContext_UseCertificateChainBytes, 3) \
141 V(ServerSocket_Accept, 2) \
142 V(ServerSocket_CreateBindListen, 7) \
143 V(ServerSocket_CreateUnixDomainBindListen, 5) \
144 V(SocketBase_IsBindError, 2) \
145 V(Socket_Available, 1) \
146 V(Socket_AvailableDatagram, 1) \
147 V(Socket_CreateBindConnect, 6) \
148 V(Socket_CreateUnixDomainBindConnect, 4) \
149 V(Socket_CreateBindDatagram, 6) \
150 V(Socket_CreateConnect, 4) \
151 V(Socket_CreateUnixDomainConnect, 3) \
152 V(Socket_GetPort, 1) \
153 V(Socket_GetRemotePeer, 1) \
154 V(Socket_GetError, 1) \
155 V(Socket_Fatal, 1) \
156 V(Socket_GetFD, 1) \
157 V(Socket_GetOption, 3) \
158 V(Socket_GetRawOption, 4) \
159 V(Socket_GetSocketId, 1) \
160 V(Socket_GetStdioHandle, 2) \
161 V(Socket_GetType, 1) \
162 V(Socket_JoinMulticast, 4) \
163 V(Socket_LeaveMulticast, 4) \
164 V(Socket_Read, 2) \
165 V(Socket_RecvFrom, 1) \
166 V(Socket_ReceiveMessage, 2) \
167 V(Socket_SendMessage, 5) \
168 V(Socket_SendTo, 6) \
169 V(Socket_SetOption, 4) \
170 V(Socket_SetRawOption, 4) \
171 V(Socket_SetSocketId, 3) \
172 V(Socket_WriteList, 4) \
173 V(Socket_HasPendingWrite, 1) \
174 V(SocketControlMessage_fromHandles, 2) \
175 V(SocketControlMessageImpl_extractHandles, 1) \
176 V(Stdin_ReadByte, 1) \
177 V(Stdin_GetEchoMode, 1) \
178 V(Stdin_SetEchoMode, 2) \
179 V(Stdin_GetEchoNewlineMode, 1) \
180 V(Stdin_SetEchoNewlineMode, 2) \
181 V(Stdin_GetLineMode, 1) \
182 V(Stdin_SetLineMode, 2) \
183 V(Stdin_AnsiSupported, 1) \
184 V(Stdout_GetTerminalSize, 1) \
185 V(Stdout_AnsiSupported, 1) \
186 V(StringToSystemEncoding, 1) \
187 V(SynchronousSocket_Available, 1) \
188 V(SynchronousSocket_CloseSync, 1) \
189 V(SynchronousSocket_CreateConnectSync, 3) \
190 V(SynchronousSocket_GetPort, 1) \
191 V(SynchronousSocket_GetRemotePeer, 1) \
192 V(SynchronousSocket_LookupRequest, 2) \
193 V(SynchronousSocket_ShutdownRead, 1) \
194 V(SynchronousSocket_ShutdownWrite, 1) \
195 V(SynchronousSocket_Read, 2) \
196 V(SynchronousSocket_ReadList, 4) \
197 V(SynchronousSocket_WriteList, 4) \
198 V(SystemEncodingToString, 1) \
199 V(X509_Der, 1) \
200 V(X509_Pem, 1) \
201 V(X509_Sha1, 1) \
202 V(X509_Subject, 1) \
203 V(X509_Issuer, 1) \
204 V(X509_StartValidity, 1) \
205 V(X509_EndValidity, 1)
206
208
209static const struct NativeEntries {
210 const char* name_;
212 int argument_count_;
214
216 int argument_count,
217 bool* auto_setup_scope) {
218 const char* function_name = nullptr;
221 ASSERT(function_name != nullptr);
222 ASSERT(auto_setup_scope != nullptr);
223 *auto_setup_scope = true;
224 int num_entries = sizeof(IOEntries) / sizeof(struct NativeEntries);
225 for (int i = 0; i < num_entries; i++) {
226 const struct NativeEntries* entry = &(IOEntries[i]);
227 if ((strcmp(function_name, entry->name_) == 0) &&
228 (entry->argument_count_ == argument_count)) {
229 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
230 }
231 }
232 return nullptr;
233}
234
236 int num_entries = sizeof(IOEntries) / sizeof(struct NativeEntries);
237 for (int i = 0; i < num_entries; i++) {
238 const struct NativeEntries* entry = &(IOEntries[i]);
239 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) {
240 return reinterpret_cast<const uint8_t*>(entry->name_);
241 }
242 }
243 return nullptr;
244}
245
246} // namespace bin
247} // namespace dart
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
#define ASSERT(E)
GAsyncResult * result
#define REGISTER_FUNCTION(name, count)
Definition: fuchsia.cc:41
int argument_count
Definition: fuchsia.cc:52
#define DECLARE_FUNCTION(name, count)
Definition: fuchsia.cc:42
static const struct dart::bin::NativeEntries IOEntries[]
IO_NATIVE_LIST(DECLARE_FUNCTION)
const uint8_t * IONativeSymbol(Dart_NativeFunction nf)
Definition: io_natives.cc:235
Dart_NativeFunction IONativeLookup(Dart_Handle name, int argument_count, bool *auto_setup_scope)
Definition: io_natives.cc:215
Definition: dart_vm.cc:33
const char *const name
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
const char *const function_name
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, const char **cstr)
Dart_NativeFunction function_