mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
fd: fix table cloning
This commit is contained in:
+10
-4
@@ -12,7 +12,7 @@ int fd_release(fd_t* fd){
|
|||||||
|
|
||||||
int fd_access(fdtable_t* fdtable, fd_t** fd, int ifd){
|
int fd_access(fdtable_t* fdtable, fd_t** fd, int ifd){
|
||||||
spinlock_acquire(&fdtable->lock);
|
spinlock_acquire(&fdtable->lock);
|
||||||
|
|
||||||
if(ifd >= fdtable->fdcount || fdtable->fd[ifd] == NULL){
|
if(ifd >= fdtable->fdcount || fdtable->fd[ifd] == NULL){
|
||||||
spinlock_release(&fdtable->lock);
|
spinlock_release(&fdtable->lock);
|
||||||
return EBADF;
|
return EBADF;
|
||||||
@@ -82,8 +82,8 @@ int fd_alloc(fdtable_t* fdtable, fd_t** fd, int* ifd){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int fd_free(fdtable_t* fdtable, int ifd){
|
int fd_free(fdtable_t* fdtable, int ifd){
|
||||||
spinlock_acquire(&fdtable->lock);
|
spinlock_acquire(&fdtable->lock);
|
||||||
|
|
||||||
if(ifd >= fdtable->fdcount || fdtable->fd[ifd] == NULL){
|
if(ifd >= fdtable->fdcount || fdtable->fd[ifd] == NULL){
|
||||||
spinlock_release(&fdtable->lock);
|
spinlock_release(&fdtable->lock);
|
||||||
return EBADF;
|
return EBADF;
|
||||||
@@ -114,12 +114,18 @@ int fd_tableclone(fdtable_t* source, fdtable_t* dest){
|
|||||||
|
|
||||||
spinlock_acquire(&source->lock);
|
spinlock_acquire(&source->lock);
|
||||||
|
|
||||||
|
if(fd_tableinit(dest)){
|
||||||
|
spinlock_release(&source->lock);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if(source->fdcount != dest->fdcount){
|
if(source->fdcount != dest->fdcount){
|
||||||
void* tmp = alloc(source->fdcount*sizeof(fd_t*));
|
void* tmp = realloc(dest->fd, source->fdcount*sizeof(fd_t*));
|
||||||
if(!tmp){
|
if(!tmp){
|
||||||
spinlock_release(&source->lock);
|
spinlock_release(&source->lock);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
dest->fd = tmp;
|
||||||
dest->fdcount = source->fdcount;
|
dest->fdcount = source->fdcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user