diff --git a/headers/build/BeOSBuildCompatibility.h b/headers/build/BeOSBuildCompatibility.h index 928781604d..677af9e881 100644 --- a/headers/build/BeOSBuildCompatibility.h +++ b/headers/build/BeOSBuildCompatibility.h @@ -22,7 +22,11 @@ extern size_t strnlen(const char *string, size_t length); // BeOS only extern ssize_t read_pos(int fd, off_t pos, void *buffer, size_t count); -extern ssize_t write_pos(int fd, off_t pos, const void *buffer,size_t count); +extern ssize_t write_pos(int fd, off_t pos, const void *buffer, size_t count); +extern ssize_t readv_pos(int fd, off_t pos, const struct iovec *vec, + size_t count); +extern ssize_t writev_pos(int fd, off_t pos, const struct iovec *vec, + size_t count); // There's no O_NOTRAVERSE under Linux and FreeBSD, but there's a O_NOFOLLOW, which diff --git a/src/build/libroot/Jamfile b/src/build/libroot/Jamfile index 8dfa03842d..174d4b6c1f 100644 --- a/src/build/libroot/Jamfile +++ b/src/build/libroot/Jamfile @@ -22,6 +22,7 @@ UseHeaders [ FDirName $(HAIKU_TOP) headers build private kernel ] : true ; MakeLocate libroot_build.so : $(HOST_BUILD_COMPATIBILITY_LIB_DIR) ; BuildPlatformSharedLibrary libroot_build.so : + atomic.cpp byteorder.cpp errors.cpp fs.cpp diff --git a/src/build/libroot/atomic.cpp b/src/build/libroot/atomic.cpp new file mode 100644 index 0000000000..66708598a0 --- /dev/null +++ b/src/build/libroot/atomic.cpp @@ -0,0 +1,59 @@ +#include + +#include + +#include +#include + + +int32 +atomic_set(vint32 *value, int32 newValue) +{ + int32 oldValue = *value; + *value = newValue; + return oldValue; +} + + +int32 +atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst) +{ + int32 oldValue = *value; + if (oldValue == testAgainst) + *value = newValue; + return oldValue; +} + + +int32 +atomic_add(vint32 *value, int32 addValue) +{ + int32 oldValue = *value; + value += addValue; + return oldValue; +} + + +int32 +atomic_and(vint32 *value, int32 andValue) +{ + int32 oldValue = *value; + *value &= andValue; + return oldValue; +} + + +int32 +atomic_or(vint32 *value, int32 orValue) +{ + int32 oldValue = *value; + *value |= orValue; + return oldValue; +} + + +int32 +atomic_get(vint32 *value) +{ + return *value; +} diff --git a/src/build/libroot/fs.cpp b/src/build/libroot/fs.cpp index 14e2d6c64a..5e649791a0 100644 --- a/src/build/libroot/fs.cpp +++ b/src/build/libroot/fs.cpp @@ -959,3 +959,41 @@ write_pos(int fd, off_t pos, const void *buffer, size_t bufferSize) return bytesWritten; } + +// readv_pos +ssize_t +readv_pos(int fd, off_t pos, const struct iovec *vec, size_t count) +{ + // seek + off_t result = lseek(fd, pos, SEEK_SET); + if (result < 0) + return errno; + + // read + ssize_t bytesRead = readv(fd, vec, count); + if (bytesRead < 0) { + errno = bytesRead; + return -1; + } + + return bytesRead; +} + +// writev_pos +ssize_t +writev_pos(int fd, off_t pos, const struct iovec *vec, size_t count) +{ + // seek + off_t result = lseek(fd, pos, SEEK_SET); + if (result < 0) + return errno; + + // read + ssize_t bytesWritten = writev(fd, vec, count); + if (bytesWritten < 0) { + errno = bytesWritten; + return -1; + } + + return bytesWritten; +} diff --git a/src/build/libroot/sem.cpp b/src/build/libroot/sem.cpp index 207fc5cb92..4dc66cecc3 100644 --- a/src/build/libroot/sem.cpp +++ b/src/build/libroot/sem.cpp @@ -142,11 +142,63 @@ release_sem_etc(sem_id id, int32 count, uint32 flags) return B_OK; } -// atomic_add -int32 -atomic_add(vint32 *value, int32 addValue) +// get_sem_count +status_t +get_sem_count(sem_id id, int32 *threadCount) { - int32 oldValue = *value; - value += addValue; - return oldValue; + if (!check_sem(id)) + return B_BAD_SEM_ID; + + if (!threadCount) + return B_BAD_VALUE; + + *threadCount = sSemaphores[id].count; + return B_OK; +} + +// set_sem_owner +status_t +set_sem_owner(sem_id id, team_id team) +{ + if (!check_sem(id)) + return B_BAD_SEM_ID; + + return B_OK; +} + +// _get_sem_info +status_t +_get_sem_info(sem_id id, struct sem_info *info, size_t infoSize) +{ + if (!check_sem(id)) + return B_BAD_SEM_ID; + + if (!info) + return B_BAD_VALUE; + + info->sem = id; + info->team = 1; + info->name[0] = '\0'; + info->count = sSemaphores[id].count; + info->latest_holder = -1; + + return B_OK; +} + +// _get_next_sem_info +status_t +_get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info, + size_t infoSize) +{ + if (team < 0 || team > 2) + return B_BAD_TEAM_ID; + + for (int i = *cookie; i < kSemaphoreCount; i++) { + if (sSemaphores[i].inUse) { + *cookie = i + 1; + return _get_sem_info(i, info, infoSize); + } + } + + return B_ENTRY_NOT_FOUND; } diff --git a/src/build/libroot/thread.cpp b/src/build/libroot/thread.cpp index 15a5a90474..7998694b1d 100644 --- a/src/build/libroot/thread.cpp +++ b/src/build/libroot/thread.cpp @@ -5,6 +5,28 @@ static const thread_id kMainThreadID = 3; + +// kill_thread +status_t +kill_thread(thread_id thread) +{ + return B_BAD_VALUE; +} + +// resume_thread +status_t +resume_thread(thread_id thread) +{ + return B_BAD_VALUE; +} + +// suspend_thread +status_t +suspend_thread(thread_id thread) +{ + return B_BAD_VALUE; +} + // find_thread thread_id find_thread(const char *name)