@@ -145,6 +145,44 @@ struct zsock_addrinfo {
145
145
char _ai_canonname [DNS_MAX_NAME_SIZE + 1 ];
146
146
};
147
147
148
+ /**
149
+ * @brief Obtain a file descriptor's associated net context
150
+ *
151
+ * With CONFIG_USERSPACE enabled, the kernel's object permission system
152
+ * must apply to socket file descriptors. When a socket is opened, by default
153
+ * only the caller has permission, access by other threads will fail unless
154
+ * they have been specifically granted permission.
155
+ *
156
+ * This is achieved by tagging data structure definitions that implement the
157
+ * underlying object associated with a network socket file descriptor with
158
+ * '__net_socket`. All pointers to instances of these will be known to the
159
+ * kernel as kernel objects with type K_OBJ_NET_SOCKET.
160
+ *
161
+ * This API is intended for threads that need to grant access to the object
162
+ * associated with a particular file descriptor to another thread. The
163
+ * returned pointer represents the underlying K_OBJ_NET_SOCKET and
164
+ * may be passed to APIs like k_object_access_grant().
165
+ *
166
+ * In a system like Linux which has the notion of threads running in processes
167
+ * in a shared virtual address space, this sort of management is unnecessary as
168
+ * the scope of file descriptors is implemented at the process level.
169
+ *
170
+ * However in Zephyr the file descriptor scope is global, and MPU-based systems
171
+ * are not able to implement a process-like model due to the lack of memory
172
+ * virtualization hardware. They use discrete object permissions and memory
173
+ * domains instead to define thread access scope.
174
+ *
175
+ * User threads will have no direct access to the returned object
176
+ * and will fault if they try to access its memory; the pointer can only be
177
+ * used to make permission assignment calls, which follow exactly the rules
178
+ * for other kernel objects like device drivers and IPC.
179
+ *
180
+ * @param sock file descriptor
181
+ * @return pointer to associated network socket object, or NULL if the
182
+ * file descriptor wasn't valid or the caller had no access permission
183
+ */
184
+ __syscall void * zsock_get_context_object (int sock );
185
+
148
186
/**
149
187
* @brief Create a network socket
150
188
*
@@ -156,6 +194,11 @@ struct zsock_addrinfo {
156
194
* This function is also exposed as ``socket()``
157
195
* if :option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
158
196
* @endrst
197
+ *
198
+ * If CONFIG_USERSPACE is enabled, the caller will be granted access to the
199
+ * context object associated with the returned file descriptor.
200
+ * @see zsock_get_context_object()
201
+ *
159
202
*/
160
203
__syscall int zsock_socket (int family , int type , int proto );
161
204
0 commit comments