mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Added close(2) and fixed bugs in pipe(2) and others.
This commit is contained in:
parent
a7de7b4905
commit
e8cd27c353
6 changed files with 31 additions and 8 deletions
|
@ -80,7 +80,6 @@ int access(const char*, int);
|
|||
unsigned alarm(unsigned);
|
||||
int chdir(const char*);
|
||||
int chown(const char*, uid_t, gid_t);
|
||||
int close(int);
|
||||
size_t confstr(int, char*, size_t);
|
||||
char* crypt(const char*, const char*);
|
||||
char* ctermid(char*);
|
||||
|
@ -159,6 +158,7 @@ extern char* optarg;
|
|||
extern int opterr, optind, optopt;
|
||||
#endif
|
||||
|
||||
int close(int);
|
||||
void _exit(int);
|
||||
pid_t fork(void);
|
||||
pid_t getpid(void);
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace Maxsi
|
|||
DEFN_SYSCALL3(ssize_t, SysRead, 18, int, void*, size_t);
|
||||
DEFN_SYSCALL3(ssize_t, SysWrite, 19, int, const void*, size_t);
|
||||
DEFN_SYSCALL1(int, SysPipe, 20, int*);
|
||||
DEFN_SYSCALL1(int, SysClose, 21, int);
|
||||
|
||||
size_t Print(const char* Message)
|
||||
{
|
||||
|
@ -78,6 +79,10 @@ namespace Maxsi
|
|||
return SysPipe(pipefd);
|
||||
}
|
||||
|
||||
extern "C" int close(int fd)
|
||||
{
|
||||
return SysClose(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace Sortix
|
|||
{
|
||||
if ( devices[i] == NULL )
|
||||
{
|
||||
object->Refer();
|
||||
devices[i] = object;
|
||||
return i;
|
||||
}
|
||||
|
@ -87,7 +88,7 @@ namespace Sortix
|
|||
|
||||
void DescriptorTable::Free(int index)
|
||||
{
|
||||
ASSERT(index < index);
|
||||
ASSERT(index < numdevices);
|
||||
ASSERT(devices[index] != NULL);
|
||||
|
||||
if ( devices[index] != reserveddevideptr )
|
||||
|
@ -109,6 +110,7 @@ namespace Sortix
|
|||
ASSERT(devices[index] != NULL);
|
||||
ASSERT(devices[index] == reserveddevideptr);
|
||||
|
||||
object->Refer();
|
||||
devices[index] = object;
|
||||
}
|
||||
|
||||
|
@ -117,9 +119,14 @@ namespace Sortix
|
|||
Device** newlist = new Device*[numdevices];
|
||||
if ( newlist == NULL ) { return false; }
|
||||
|
||||
Memory::Copy(newlist, devices, sizeof(Device*) * numdevices);
|
||||
|
||||
// TODO: Possibly deal with a potential O_CLOFORK!
|
||||
for ( int i = 0; i < numdevices; i++ )
|
||||
{
|
||||
// TODO: Possibly deal with a potential O_CLOFORK!
|
||||
newlist[i] = devices[i];
|
||||
if ( !devices[i] ) { continue; }
|
||||
if ( devices[i] == reserveddevideptr ) { continue; }
|
||||
newlist[i]->Refer();
|
||||
}
|
||||
|
||||
ASSERT(forkinto->devices == NULL);
|
||||
|
||||
|
|
|
@ -117,10 +117,20 @@ namespace Sortix
|
|||
return 0;
|
||||
}
|
||||
|
||||
int SysClose(int fd)
|
||||
{
|
||||
Process* process = CurrentProcess();
|
||||
Device* dev = process->descriptors.Get(fd);
|
||||
if ( !dev ) { return -1; /* TODO: EBADF */ }
|
||||
process->descriptors.Free(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
Syscall::Register(SYSCALL_WRITE, (void*) SysWrite);
|
||||
Syscall::Register(SYSCALL_READ, (void*) SysRead);
|
||||
Syscall::Register(SYSCALL_CLOSE, (void*) SysClose);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ namespace Sortix
|
|||
|
||||
DevPipeStorage::~DevPipeStorage()
|
||||
{
|
||||
ASSERT(!readwaiting);
|
||||
ASSERT(!writewaiting);
|
||||
if ( readwaiting ) { Syscall::ScheduleResumption(readwaiting); }
|
||||
if ( writewaiting ) { Syscall::ScheduleResumption(writewaiting); }
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@
|
|||
#define SYSCALL_READ 18
|
||||
#define SYSCALL_WRITE 19
|
||||
#define SYSCALL_PIPE 20
|
||||
#define SYSCALL_MAX_NUM 21 /* index of highest constant + 1 */
|
||||
#define SYSCALL_CLOSE 21
|
||||
#define SYSCALL_MAX_NUM 22 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue