summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2019-08-03 16:14:26 +0000
committermidipix <writeonce@midipix.org>2019-08-03 16:14:26 +0000
commit3d4ab416844793fb1b4fc28ad966cb125d19e441 (patch)
treed3c5197d912d664726b232b55aa2c1fdf3728b65
parent831753b17817e33d06c841be66e48be1b05dba54 (diff)
downloadmmglue-3d4ab416844793fb1b4fc28ad966cb125d19e441.tar.bz2
mmglue-3d4ab416844793fb1b4fc28ad966cb125d19e441.tar.xz
midipix targets: __init_tls(): added __thread_list_lock support.
-rw-r--r--project/common.mk3
-rw-r--r--project/config/cfgdefs.in4
-rw-r--r--project/config/cfgdefs.sh31
-rw-r--r--src/arch/nt32/crt_glue.c19
-rw-r--r--src/arch/nt64/crt_glue.c19
5 files changed, 72 insertions, 4 deletions
diff --git a/project/common.mk b/project/common.mk
index f7f6929..af5155e 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -82,7 +82,8 @@ SHARED_OBJS += $(libc_core_files_S:%.S=%.lo)
$(STATIC_OBJS): headers.tag host.tag tree.tag
$(SHARED_OBJS): headers.tag host.tag tree.tag
-$(SHARED_OBJS): CFLAGS_SHARED += -DSHARED=
+$(SHARED_OBJS): CFLAGS_SHARED += $(LIBC_CFLAGS_SHARED) -DSHARED=
+$(STATIC_OBJS): CFLAGS_STATIC += $(LIBC_CFLAGS_STATIC)
src/%.o:$(PORT_DIR)/src/%.c $(HEADER_DEPS)
$(CC) -c -o $@ $< $(CFLAGS_STATIC)
diff --git a/project/config/cfgdefs.in b/project/config/cfgdefs.in
index bbad445..e03094a 100644
--- a/project/config/cfgdefs.in
+++ b/project/config/cfgdefs.in
@@ -4,6 +4,10 @@ LIBC_MAJOR = @libc_major@
LIBC_MINOR = @libc_minor@
LIBC_MICRO = @libc_micro@
+# libc version-specific defs
+LIBC_CFLAGS_SHARED += @libc_td_tid_addr@
+LIBC_CFLAGS_STATIC += @libc_td_tid_addr@
+
# build mode
LIBC_EXCL_FILES = @libc_excl_files@
diff --git a/project/config/cfgdefs.sh b/project/config/cfgdefs.sh
index 168e961..994ef54 100644
--- a/project/config/cfgdefs.sh
+++ b/project/config/cfgdefs.sh
@@ -101,6 +101,31 @@ cfgdefs_set_libc_options()
}
+cfgdefs_set_libc_cflags()
+{
+ libc_td_tid_addr=
+ mb_init_tls_src_file=$mb_source_dir/src/env/__init_tls.c
+
+ [ -z $libc_td_tid_addr ] \
+ && grep '__syscall(SYS_set_tid_address, &td->tid)' $mb_init_tls_src_file > /dev/null \
+ && libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_TID'
+
+ [ -z $libc_td_tid_addr ] \
+ && grep '__syscall(SYS_set_tid_address, &td->join_futex)' $mb_init_tls_src_file > /dev/null \
+ && libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_JOIN_FUTEX'
+
+ [ -z $libc_td_tid_addr ] \
+ && grep '__syscall(SYS_set_tid_address, &td->detach_state)' $mb_init_tls_src_file > /dev/null \
+ && libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_DETACH_STATE'
+
+ [ -z $libc_td_tid_addr ] \
+ && grep '__syscall(SYS_set_tid_address, &__thread_list_lock)' $mb_init_tls_src_file > /dev/null \
+ && libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_THREAD_LIST_LOCK'
+
+ return 0
+}
+
+
cfgdefs_output_custom_defs()
{
sed \
@@ -113,7 +138,8 @@ cfgdefs_output_custom_defs()
-e 's^@libc_excl_files@^'"$libc_excl_files"'^g' \
-e 's/@libc_source_tree@/'"$libc_source_tree"'/g' \
-e 's/@libc_syscall_arch@/'"$libc_syscall_arch"'/g' \
- -e 's!@alltypes_sed@!'"$alltypes_sed"'!g' \
+ -e 's/@libc_td_tid_addr@/'"$libc_td_tid_addr"'/g' \
+ -e 's!@alltypes_sed@!'"$alltypes_sed"'!g' \
"$mb_project_dir/project/config/cfgdefs.in" \
| sed -e 's/[ \t]*$//g' \
>> "$mb_pwd/cfgdefs.mk"
@@ -129,6 +155,9 @@ cfgdefs_detect_libc_version
# libc (variant-specific) options
cfgdefs_set_libc_options
+# libc (variant-specific) cflags
+cfgdefs_set_libc_cflags
+
# cfgdefs.in --> cfgdefs.mk
cfgdefs_output_custom_defs
diff --git a/src/arch/nt32/crt_glue.c b/src/arch/nt32/crt_glue.c
index a710c39..6fd9919 100644
--- a/src/arch/nt32/crt_glue.c
+++ b/src/arch/nt32/crt_glue.c
@@ -6,6 +6,8 @@
#include "psxglue.h"
#include "pthread_impl.h"
+volatile int __thread_list_lock;
+
extern const struct __ldso_vtbl * __ldso_vtbl;
extern const struct __psx_vtbl * __psx_vtbl;
extern const struct __seh_vtbl * __eh_vtbl;
@@ -44,7 +46,6 @@ void __init_tls (size_t * auxv)
T.pt.self = &T.pt;
T.pt.locale = &libc.global_locale;
- T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.tid);
T.pt.detach_state = DT_JOINABLE;
T.pt.locale = &libc.global_locale;
@@ -52,6 +53,22 @@ void __init_tls (size_t * auxv)
libc.can_do_threads = 1;
libc.tls_size = sizeof(struct __tls);
+
+#if defined(__LIBC_TD_TID_ADDR_TID)
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.tid);
+#elif defined(__LIBC_TD_TID_ADDR_JOIN_FUTEX)
+ T.pt.join_futex = -1;
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.join_futex);
+#elif defined(__LIBC_TD_TID_ADDR_DETACH_STATE)
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.detach_state);
+#elif defined(__LIBC_TD_TID_ADDR_THREAD_LIST_LOCK)
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.detach_state);
+ T.pt.next = &T.pt;
+ T.pt.prev = &T.pt;
+#else
+ #error could not detect tid address logic.
+#endif
+
};
void __libc_entry_routine(
diff --git a/src/arch/nt64/crt_glue.c b/src/arch/nt64/crt_glue.c
index a710c39..6fd9919 100644
--- a/src/arch/nt64/crt_glue.c
+++ b/src/arch/nt64/crt_glue.c
@@ -6,6 +6,8 @@
#include "psxglue.h"
#include "pthread_impl.h"
+volatile int __thread_list_lock;
+
extern const struct __ldso_vtbl * __ldso_vtbl;
extern const struct __psx_vtbl * __psx_vtbl;
extern const struct __seh_vtbl * __eh_vtbl;
@@ -44,7 +46,6 @@ void __init_tls (size_t * auxv)
T.pt.self = &T.pt;
T.pt.locale = &libc.global_locale;
- T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.tid);
T.pt.detach_state = DT_JOINABLE;
T.pt.locale = &libc.global_locale;
@@ -52,6 +53,22 @@ void __init_tls (size_t * auxv)
libc.can_do_threads = 1;
libc.tls_size = sizeof(struct __tls);
+
+#if defined(__LIBC_TD_TID_ADDR_TID)
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.tid);
+#elif defined(__LIBC_TD_TID_ADDR_JOIN_FUTEX)
+ T.pt.join_futex = -1;
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.join_futex);
+#elif defined(__LIBC_TD_TID_ADDR_DETACH_STATE)
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.detach_state);
+#elif defined(__LIBC_TD_TID_ADDR_THREAD_LIST_LOCK)
+ T.pt.tid = __syscall(SYS_set_tid_address, &T.pt.detach_state);
+ T.pt.next = &T.pt;
+ T.pt.prev = &T.pt;
+#else
+ #error could not detect tid address logic.
+#endif
+
};
void __libc_entry_routine(