Skip to content

Commit 0d7c006

Browse files
authored
Merge pull request #2350 from torgeiru/remove-arch-prctl-call
Removing arch_prctl from syscall and creating architecture specific musl calls
2 parents 577d8d8 + 848ae76 commit 0d7c006

File tree

10 files changed

+80
-68
lines changed

10 files changed

+80
-68
lines changed

deps/musl/default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ stdenv.mkDerivation rec {
2727
cp ${./patches/includeos_syscalls.h} $sourceRoot/src/internal/includeos_syscalls.h
2828
cp ${./patches/syscall.h} $sourceRoot/src/internal/syscall.h
2929
30+
rm $sourceRoot/src/thread/x86_64/__set_thread_area.s
31+
cp ${./patches/__set_thread_area.c} $sourceRoot/src/thread/x86_64/__set_thread_area.c
32+
3033
rm $sourceRoot/arch/x86_64/syscall_arch.h
3134
rm $sourceRoot/arch/i386/syscall_arch.h
3235
'';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "syscall.h"
2+
3+
#define ARCH_SET_FS 0x1002
4+
5+
int __set_thread_area(void *p)
6+
{
7+
return __syscall(SYS_arch_prctl, ARCH_SET_FS, p);
8+
}

src/arch/aarch64/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(ARCH_OBJECTS
77
# profile_intr.asm
88
# apic_asm.asm
99
arch_start.asm
10+
arch_musl.cpp
1011
exceptions.asm
1112
# interrupts.asm
1213
# fiber.asm
@@ -15,7 +16,6 @@ set(ARCH_SOURCES
1516
paging.cpp
1617
cpu.cpp
1718
timer.cpp
18-
syscall_entry.cpp
1919
)
2020
enable_language(ASM)
2121

src/arch/aarch64/arch_musl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <os>
2+
#include <errno.h>
3+
#include "cpu.hpp"
4+
5+
extern "C"
6+
long syscall_SYS_set_thread_area(struct user_desc *u_desc) {
7+
set_tpidr(u_info); // This probably still does not work
8+
return 0;
9+
}
10+
11+
extern "C"
12+
long syscall_SYS_arch_prctl(int code, uintptr_t ptr) {
13+
os::panic("Arch_prctl is specific to x86!");
14+
return -ENOSYS;
15+
}

src/arch/aarch64/syscall_entry.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/arch/i686/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(ARCH_OBJECTS
66
profile_intr.asm
77
apic_asm.asm
88
arch_start.asm
9+
arch_musl.cpp
910
exceptions.asm
1011
interrupts.asm
1112
fiber.asm

src/arch/i686/arch_musl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <os>
2+
#include <errno.h>
3+
4+
extern "C"
5+
long syscall_SYS_set_thread_area(struct user_desc *u_info)
6+
{
7+
os::panic("Libc not supported for 32 bit currently!");
8+
return -ENOSYS;
9+
}
10+
11+
extern "C"
12+
long syscall_SYS_arch_prctl(int code, uintptr_t ptr) {
13+
os::panic("Libc not supported for 32 bit currently!");
14+
return -ENOSYS;
15+
}

src/arch/x86_64/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(ARCH_OBJECTS
55
apic_asm.asm
66
apic_longmode.asm
77
arch_start.asm
8+
arch_musl.cpp
89
exceptions.asm
910
interrupts.asm
1011
fiber_asm.asm

src/arch/x86_64/arch_musl.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <os>
2+
#include <errno.h>
3+
#include <likely>
4+
#include <arch/x86/cpu.hpp>
5+
6+
extern "C"
7+
long syscall_SYS_set_thread_area(struct user_desc *u_desc) {
8+
os::panic("Setting thread pointer on 64 bit Intel/AMD should go via arch_prctl!");
9+
return -ENOSYS;
10+
}
11+
12+
#define ARCH_SET_GS 0x1001
13+
#define ARCH_SET_FS 0x1002
14+
#define ARCH_GET_FS 0x1003
15+
#define ARCH_GET_GS 0x1004
16+
17+
extern "C"
18+
long syscall_SYS_arch_prctl(int code, uintptr_t ptr) {
19+
switch(code){
20+
case ARCH_SET_GS:
21+
if (UNLIKELY(!ptr)) return -EINVAL;
22+
x86::CPU::set_gs((void*)ptr);
23+
break;
24+
case ARCH_SET_FS:
25+
if (UNLIKELY(!ptr)) return -EINVAL;
26+
x86::CPU::set_fs((void*)ptr);
27+
break;
28+
case ARCH_GET_GS:
29+
os::panic("<arch_prctl> GET_GS called!\n");
30+
case ARCH_GET_FS:
31+
os::panic("<arch_prctl> GET_FS called!\n");
32+
}
33+
return 0;
34+
}

src/arch/x86_64/syscall_entry.cpp

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,16 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
#include <arch/x86/cpu.hpp>
1817
#include <os.hpp>
19-
#include <likely>
2018
#include <kprint>
21-
#include <errno.h>
22-
23-
#define ARCH_SET_GS 0x1001
24-
#define ARCH_SET_FS 0x1002
25-
#define ARCH_GET_FS 0x1003
26-
#define ARCH_GET_GS 0x1004
27-
28-
#ifdef __x86_64__
29-
static long sys_prctl(int code, uintptr_t ptr)
30-
{
31-
switch(code){
32-
case ARCH_SET_GS:
33-
//kprintf("<arch_prctl> set_gs to %#lx\n", ptr);
34-
if (UNLIKELY(!ptr)) return -EINVAL;
35-
x86::CPU::set_gs((void*)ptr);
36-
break;
37-
case ARCH_SET_FS:
38-
//kprintf("<arch_prctl> set_fs to %#lx\n", ptr);
39-
if (UNLIKELY(!ptr)) return -EINVAL;
40-
x86::CPU::set_fs((void*)ptr);
41-
break;
42-
case ARCH_GET_GS:
43-
os::panic("<arch_prctl> GET_GS called!\n");
44-
case ARCH_GET_FS:
45-
os::panic("<arch_prctl> GET_FS called!\n");
46-
}
47-
return -EINVAL;
48-
}
49-
#endif
5019

5120
extern "C"
5221
uintptr_t syscall_entry(uint64_t n, uint64_t a1, uint64_t a2, uint64_t a3,
5322
uint64_t a4, uint64_t a5)
5423
{
55-
switch(n) {
56-
case 158: // arch_prctl
57-
sys_prctl(a1, a2);
58-
break;
59-
default:
60-
kprintf("<syscall entry> no %lu (a1=%#lx a2=%#lx a3=%#lx a4=%#lx a5=%#lx) \n",
24+
kprintf("<syscall entry> no %lu (a1=%#lx a2=%#lx a3=%#lx a4=%#lx a5=%#lx) \n",
6125
n, a1, a2, a3, a4, a5);
62-
}
26+
os::panic("Syscalls are not implemented in IncludeOS!");
6327
return 0;
6428
}
6529

66-
extern "C"
67-
long syscall_SYS_set_thread_area(struct user_desc *u_info)
68-
{
69-
if (UNLIKELY(!u_info)) return -EINVAL;
70-
#ifdef __x86_64__
71-
x86::CPU::set_fs(u_info);
72-
#else
73-
x86::CPU::set_gs(u_info);
74-
#endif
75-
return 0;
76-
}

0 commit comments

Comments
 (0)