Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
3 changes: 3 additions & 0 deletions deps/musl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ stdenv.mkDerivation rec {
cp ${./patches/includeos_syscalls.h} $sourceRoot/src/internal/includeos_syscalls.h
cp ${./patches/syscall.h} $sourceRoot/src/internal/syscall.h

rm $sourceRoot/src/thread/x86_64/__set_thread_area.s
cp ${./patches/__set_thread_area.c} $sourceRoot/src/thread/x86_64/__set_thread_area.c

rm $sourceRoot/arch/x86_64/syscall_arch.h
rm $sourceRoot/arch/i386/syscall_arch.h
'';
Expand Down
8 changes: 8 additions & 0 deletions deps/musl/patches/__set_thread_area.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "syscall.h"

#define ARCH_SET_FS 0x1002

int __set_thread_area(void *p)
{
return __syscall(SYS_arch_prctl, ARCH_SET_FS, p);
}
2 changes: 1 addition & 1 deletion src/arch/aarch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(ARCH_OBJECTS
# profile_intr.asm
# apic_asm.asm
arch_start.asm
arch_musl.cpp
exceptions.asm
# interrupts.asm
# fiber.asm
Expand All @@ -15,7 +16,6 @@ set(ARCH_SOURCES
paging.cpp
cpu.cpp
timer.cpp
syscall_entry.cpp
)
enable_language(ASM)

Expand Down
27 changes: 27 additions & 0 deletions src/arch/aarch64/arch_musl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <os>
#include <errno.h>
#include <musl/common.hpp>
#include "cpu.hpp"

extern "C"
long sys_set_thread_area(struct user_desc *u_info)
{
set_tpidr(u_info); // This probably still does not work
return 0;
}

extern "C"
long syscall_SYS_set_thread_area(struct user_desc *u_desc) {
return strace(sys_set_thread_area, "set_thread_area", u_desc);
}

extern "C"
long sys_arch_prctl(int code, uintptr_t ptr) {
os::panic("This should not happen!");
return -ENOSYS;
}

extern "C"
long syscall_SYS_arch_prctl(int code, uintptr_t ptr) {
return strace(sys_arch_prctl, "arch_prctl", code, ptr);
}
18 changes: 0 additions & 18 deletions src/arch/aarch64/syscall_entry.cpp

This file was deleted.

1 change: 1 addition & 0 deletions src/arch/i686/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(ARCH_OBJECTS
profile_intr.asm
apic_asm.asm
arch_start.asm
arch_musl.cpp
exceptions.asm
interrupts.asm
fiber.asm
Expand Down
26 changes: 26 additions & 0 deletions src/arch/i686/arch_musl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <os>
#include <errno.h>
#include <musl/common.hpp>

extern "C"
long sys_set_thread_area(struct user_desc *u_info) {
os::panic("This should not happen!");
return -ENOSYS;
}

extern "C"
long syscall_SYS_set_thread_area(struct user_desc *u_info)
{
return strace(sys_set_thread_area, "set_thread_area", u_info);
}

extern "C"
long sys_arch_prctl(int code, uintptr_t ptr) {
os::panic("This should not happen!");
return -ENOSYS;
}

extern "C"
long syscall_SYS_arch_prctl(int code, uintptr_t ptr) {
return strace(sys_arch_prctl, "arch_prctl", code, ptr);
}
1 change: 1 addition & 0 deletions src/arch/x86_64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(ARCH_OBJECTS
apic_asm.asm
apic_longmode.asm
arch_start.asm
arch_musl.cpp
exceptions.asm
interrupts.asm
fiber_asm.asm
Expand Down
45 changes: 45 additions & 0 deletions src/arch/x86_64/arch_musl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <os>
#include <errno.h>
#include <likely>
#include <musl/common.hpp>
#include <arch/x86/cpu.hpp>

extern "C"
long sys_set_thread_area(struct user_desc *u_info)
{
return -ENOSYS;
}

extern "C"
long syscall_SYS_set_thread_area(struct user_desc *u_desc) {
return strace(sys_set_thread_area, "set_thread_area", u_desc);
}

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004

extern "C"
long sys_arch_prctl(int code, uintptr_t ptr) {
switch(code){
case ARCH_SET_GS:
if (UNLIKELY(!ptr)) return -EINVAL;
x86::CPU::set_gs((void*)ptr);
break;
case ARCH_SET_FS:
if (UNLIKELY(!ptr)) return -EINVAL;
x86::CPU::set_fs((void*)ptr);
break;
case ARCH_GET_GS:
os::panic("<arch_prctl> GET_GS called!\n");
case ARCH_GET_FS:
os::panic("<arch_prctl> GET_FS called!\n");
}
return 0;
}

extern "C"
long syscall_SYS_arch_prctl(int code, uintptr_t ptr) {
return strace(sys_arch_prctl, "arch_prctl", code, ptr);
}
50 changes: 1 addition & 49 deletions src/arch/x86_64/syscall_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <arch/x86/cpu.hpp>
#include <os.hpp>
#include <likely>
#include <kprint>
#include <errno.h>

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004

#ifdef __x86_64__
static long sys_prctl(int code, uintptr_t ptr)
{
switch(code){
case ARCH_SET_GS:
//kprintf("<arch_prctl> set_gs to %#lx\n", ptr);
if (UNLIKELY(!ptr)) return -EINVAL;
x86::CPU::set_gs((void*)ptr);
break;
case ARCH_SET_FS:
//kprintf("<arch_prctl> set_fs to %#lx\n", ptr);
if (UNLIKELY(!ptr)) return -EINVAL;
x86::CPU::set_fs((void*)ptr);
break;
case ARCH_GET_GS:
os::panic("<arch_prctl> GET_GS called!\n");
case ARCH_GET_FS:
os::panic("<arch_prctl> GET_FS called!\n");
}
return -EINVAL;
}
#endif

extern "C"
uintptr_t syscall_entry(uint64_t n, uint64_t a1, uint64_t a2, uint64_t a3,
uint64_t a4, uint64_t a5)
{
switch(n) {
case 158: // arch_prctl
sys_prctl(a1, a2);
break;
default:
kprintf("<syscall entry> no %lu (a1=%#lx a2=%#lx a3=%#lx a4=%#lx a5=%#lx) \n",
kprintf("<syscall entry> no %lu (a1=%#lx a2=%#lx a3=%#lx a4=%#lx a5=%#lx) \n",
n, a1, a2, a3, a4, a5);
}
return 0;
}

extern "C"
long syscall_SYS_set_thread_area(struct user_desc *u_info)
{
if (UNLIKELY(!u_info)) return -EINVAL;
#ifdef __x86_64__
x86::CPU::set_fs(u_info);
#else
x86::CPU::set_gs(u_info);
#endif
return 0;
}
2 changes: 1 addition & 1 deletion src/musl/access.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>

#include <fs/vfs.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/brk.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <string.h>
#include <os.hpp>
#include <errno.h>
Expand Down
2 changes: 1 addition & 1 deletion src/musl/chmod.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>

static long sys_chmod(const char* /*path*/, mode_t /*mode*/) {
Expand Down
2 changes: 1 addition & 1 deletion src/musl/chown.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>

static long sys_chown(const char* /*path*/, uid_t /*owner*/, gid_t /*group*/)
Expand Down
2 changes: 1 addition & 1 deletion src/musl/clock_gettime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>

static long sys_clock_gettime(clockid_t clk_id, struct timespec* tp)
{
Expand Down
2 changes: 1 addition & 1 deletion src/musl/close.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <posix/fd_map.hpp>

static long sys_close(int fd)
Expand Down
2 changes: 1 addition & 1 deletion src/musl/cwd.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>

#include <fs/vfs.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/musl/dup3.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/types.h>
#include <unistd.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/execve.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/types.h>
#include <unistd.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/exit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <arch.hpp>
#include <string>
#include <os>
Expand Down
2 changes: 1 addition & 1 deletion src/musl/faccessat.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>
#include <fcntl.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/faccessat2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>
#include <fcntl.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/fchdir.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>

static long sys_fchdir(int /*fd*/)
Expand Down
2 changes: 1 addition & 1 deletion src/musl/fchmod.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>

static long sys_fchmod(int /*fd*/, mode_t /*mode*/) {
Expand Down
2 changes: 1 addition & 1 deletion src/musl/fchmodat.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>
#include <fcntl.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/fchmodat2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>
#include <fcntl.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/fchown.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>

static long sys_fchown(int /*fd*/, uid_t /*owner*/, gid_t /*group*/)
Expand Down
2 changes: 1 addition & 1 deletion src/musl/fcntl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <posix/fd_map.hpp>

static long sys_fcntl(int fd, int cmd, va_list va)
Expand Down
2 changes: 1 addition & 1 deletion src/musl/fstat.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>

#include <posix/fd_map.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/musl/fstatat.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/stat.h>
#include <limits.h>
#include <posix/fd_map.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/musl/fsync.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>

static long sys_fsync(int /*fd*/)
Expand Down
2 changes: 1 addition & 1 deletion src/musl/ftruncate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>
#include <sys/types.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/getdents.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <dirent.h>
#include <posix/fd_map.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/geteuid.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <unistd.h>
#include <sys/types.h>

Expand Down
2 changes: 1 addition & 1 deletion src/musl/getgid.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <sys/types.h>

static long sys_getgid()
Expand Down
2 changes: 1 addition & 1 deletion src/musl/getpid.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>

int sys_getpid() {
return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/musl/getrandom.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.hpp"
#include <musl/common.hpp>
#include <kernel/rng.hpp>

// TODO: flags are ignored.
Expand Down
Loading