Files
borysp 989dac6fc8 [Pal] Fix semantics of DkSegmentRegister
On x64 DkSegmentRegister had weird semantics which also disabled some
usages like `0` as fsbase.
2020-12-17 16:18:26 +01:00

65 lines
1.5 KiB
C

#include <stdatomic.h>
#include "pal.h"
#include "pal_debug.h"
const char* private1 = "Hello World 1";
const char* private2 = "Hello World 2";
static atomic_int count = 0;
static void callback(void* args) {
pal_printf("Run in Child Thread: %s\n", (char*)args);
while (count < 10) {
while (!(count % 2)) {
DkThreadYieldExecution();
}
count++;
}
pal_printf("Threads Run in Parallel OK\n");
if (!DkSegmentRegisterSet(PAL_SEGMENT_FS, &private2)) {
pal_printf("Failed to set FS\n");
DkThreadExit(/*clear_child_tid=*/NULL);
}
const char* ptr2;
__asm__ volatile("mov %%fs:0, %0" : "=r"(ptr2)::"memory");
pal_printf("Private Message (FS Segment) 2: %s\n", ptr2);
count = 100;
DkThreadExit(/*clear_child_tid=*/NULL);
/* UNREACHABLE */
}
int main() {
if (!DkSegmentRegisterSet(PAL_SEGMENT_FS, &private1)) {
pal_printf("Failed to set FS\n");
return 1;
}
const char* ptr1;
__asm__ volatile("mov %%fs:0, %0" : "=r"(ptr1)::"memory");
pal_printf("Private Message (FS Segment) 1: %s\n", ptr1);
PAL_HANDLE thread1 = DkThreadCreate(callback, "Hello World");
if (!thread1)
return 1;
pal_printf("Child Thread Created\n");
while (count < 9) {
while (!!(count % 2)) {
DkThreadYieldExecution();
}
count++;
}
while (count != 100) {
DkThreadYieldExecution();
}
pal_printf("Child Thread Exited\n");
return 0;
}