Skip to content

Commit 87480cd

Browse files
Andrew Boiecarlescufi
authored andcommitted
fdtable: init fd context objects
Anytime a file descriptor context object is updated, we need to reset its access permissions and initialization state. This is the most centralized place to do it. Signed-off-by: Andrew Boie <[email protected]>
1 parent 4482f83 commit 87480cd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/os/fdtable.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <kernel.h>
1919
#include <sys/fdtable.h>
2020
#include <sys/speculation.h>
21+
#include <syscall_handler.h>
2122

2223
struct fd_entry {
2324
void *obj;
@@ -132,6 +133,16 @@ int z_reserve_fd(void)
132133
void z_finalize_fd(int fd, void *obj, const struct fd_op_vtable *vtable)
133134
{
134135
/* Assumes fd was already bounds-checked. */
136+
#ifdef CONFIG_USERSPACE
137+
/* descriptor context objects are inserted into the table when they
138+
* are ready for use. Mark the object as initialized and grant the
139+
* caller (and only the caller) access.
140+
*
141+
* This call is a no-op if obj is invalid or points to something
142+
* not a kernel object.
143+
*/
144+
z_object_recycle(obj);
145+
#endif
135146
fdtable[fd].obj = obj;
136147
fdtable[fd].vtable = vtable;
137148
}

0 commit comments

Comments
 (0)