Void system calls must now have a return value.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-01-12 15:20:55 +01:00
parent 96e4c00c5f
commit d890488304
11 changed files with 22 additions and 136 deletions

View File

@ -25,10 +25,10 @@
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1_VOID(sys_exit, SYSCALL_EXIT, int);
DEFN_SYSCALL1(int, sys_exit, SYSCALL_EXIT, int);
extern "C" void _exit(int status)
{
sys_exit(status);
while(true); // TODO: noreturn isn't set on sys_exit.
__builtin_unreachable();
}

View File

@ -111,65 +111,6 @@ inline type fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \
return a; \
}
#define DEFN_SYSCALL0_VOID(fn, num) \
inline void fn() \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL1_VOID(fn, num, P1) \
inline void fn(P1 p1) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \
inline void fn(P1 p1, P2 p2) \
{ \
unsigned long a; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \
inline void fn(P1 p1, P2 p2, P3 p3) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \
inline void fn(P1 p1, P2 p2, P3 p3, P4 p4) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \
inline void fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4), "S" ((unsigned long)p5)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
// System call functions for x86_64. (amd64)
#elif defined(__x86_64__)
@ -242,66 +183,6 @@ type fn(P1, P2, P3, P4, P5) \
return a; \
}
#define DEFN_SYSCALL0_VOID(fn, num) \
void fn() \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL1_VOID(fn, num, P1) \
void fn(P1) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \
void fn(P1, P2) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \
void fn(P1, P2, P3) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \
void fn(P1, P2, P3, P4) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \
void fn(P1, P2, P3, P4, P5) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
// Unknown platform with no implementation available.
#else
#error System call interface is not declared for host system.

View File

@ -25,7 +25,7 @@
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL3_VOID(SysSeek, SYSCALL_SEEK, int, off_t*, int);
DEFN_SYSCALL3(int, SysSeek, SYSCALL_SEEK, int, off_t*, int);
extern "C" off_t lseek(int fd, off_t offset, int whence)
{

View File

@ -36,7 +36,7 @@ extern "C" void SignalHandler(int signum)
handlers[signum](signum);
}
DEFN_SYSCALL1_VOID(sys_register_signal_handler, SYSCALL_REGISTER_SIGNAL_HANDLER, sighandler_t);
DEFN_SYSCALL1(int, sys_register_signal_handler, SYSCALL_REGISTER_SIGNAL_HANDLER, sighandler_t);
extern "C" void init_signal()
{

View File

@ -25,7 +25,7 @@
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1_VOID(SysSleep, SYSCALL_SLEEP, long);
DEFN_SYSCALL1(int, SysSleep, SYSCALL_SLEEP, long);
extern "C" unsigned sleep(unsigned secs)
{

View File

@ -25,7 +25,7 @@
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1_VOID(SysUSleep, SYSCALL_USLEEP, long);
DEFN_SYSCALL1(int, SysUSleep, SYSCALL_USLEEP, long);
extern "C" int usleep(useconds_t usecs)
{

View File

@ -56,7 +56,7 @@ const uint8_t PIC_MODE_BUF_MASTER = 0x0C; // Buffered mode/master
const uint8_t PIC_MODE_SFNM = 0x10; // Special fully nested (not)
extern "C" { unsigned long asm_is_cpu_interrupted = 0; }
const bool DEBUG_EXCEPTION = false;
const bool DEBUG_EXCEPTION = true;
const bool DEBUG_IRQ = false;
const bool DEBUG_ISR = false;
bool initialized;

View File

@ -144,13 +144,13 @@ namespace Sortix
return -1;
}
void SysSeek(int fd, off_t* offset, int whence)
int SysSeek(int fd, off_t* offset, int whence)
{
// TODO: Validate that offset is a legal user-space off_t!
Process* process = CurrentProcess();
Device* dev = process->descriptors.Get(fd);
if ( !dev ) { errno = EBADF; *offset = -1; return; }
if ( !dev->IsType(Device::BUFFER) ) { errno = EBADF; *offset = -1; return; }
if ( !dev ) { errno = EBADF; *offset = -1; return -1; }
if ( !dev->IsType(Device::BUFFER) ) { errno = EBADF; *offset = -1; return -1; }
DevBuffer* buffer = (DevBuffer*) dev;
off_t origin;
switch ( whence )
@ -158,12 +158,13 @@ namespace Sortix
case SEEK_SET: origin = 0; break;
case SEEK_CUR: origin = buffer->Position(); break;
case SEEK_END: origin = buffer->Size(); break;
default: errno = EINVAL; *offset = -1; return;
default: errno = EINVAL; *offset = -1; return -1;
}
off_t newposition = origin + *offset;
if ( newposition < 0 ) { errno = EINVAL; *offset = -1; return; }
if ( !buffer->Seek(newposition) ) { *offset = -1; return; }
if ( newposition < 0 ) { errno = EINVAL; *offset = -1; return -1; }
if ( !buffer->Seek(newposition) ) { *offset = -1; return -1; }
*offset = buffer->Position();
return 0;
}
int SysClose(int fd)

View File

@ -406,9 +406,10 @@ namespace Sortix
t->DeliverSignal(SIGKILL);
}
void SysExit(int status)
int SysExit(int status)
{
CurrentProcess()->Exit(status);
return 0;
}
bool Process::DeliverSignal(int signum)

View File

@ -248,20 +248,22 @@ Thread::State GetThreadState(Thread* thread)
return thread->state;
}
void SysSleep(size_t secs)
int SysSleep(size_t secs)
{
uintmax_t timetosleep = ((uintmax_t) secs) * 1000ULL * 1000ULL;
uint32_t wakeat = Time::MicrosecondsSinceBoot() + timetosleep;
do { Yield(); }
while ( Time::MicrosecondsSinceBoot() < wakeat );
return 0;
}
void SysUSleep(size_t usecs)
int SysUSleep(size_t usecs)
{
uintmax_t timetosleep = (uintmax_t) usecs;
uint32_t wakeat = Time::MicrosecondsSinceBoot() + timetosleep;
do { Yield(); }
while ( Time::MicrosecondsSinceBoot() < wakeat );
return 0;
}
extern "C" void yield_cpu_handler();

View File

@ -240,9 +240,10 @@ namespace Sortix
kthread_exit();
}
void SysRegisterSignalHandler(sighandler_t sighandler)
int SysRegisterSignalHandler(sighandler_t sighandler)
{
CurrentThread()->sighandler = sighandler;
return 0;
}
void Thread::SetHavePendingSignals()