file: FDTABLE_LIMIT

This commit is contained in:
Matheus
2023-06-27 19:54:33 -03:00
parent d06e00dda7
commit 98fc4eb23d
2 changed files with 10 additions and 0 deletions
+8
View File
@@ -57,6 +57,9 @@ static int getfree(int start) {
}
static int growtable(int newcount) {
if (newcount > FDTABLE_LIMIT)
return EMFILE;
proc_t *proc = _cpu()->thread->proc;
__assert(newcount > proc->fdcount);
void *newtable = realloc(proc->fd, sizeof(fd_t) * newcount);
@@ -184,6 +187,11 @@ int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) {
}
if (exact) {
if (newfd >= FDTABLE_LIMIT) {
err = EBADF;
goto cleanup;
}
if (newfd >= proc->fdcount) {
err = growtable(newfd + 1);
if (err)
+2
View File
@@ -63,4 +63,6 @@ static inline int fileflagstovnodeflags(int flags) {
#define O_RSYNC 04010000
#define O_TMPFILE 020000000
#define FDTABLE_LIMIT 256
#endif