Changeset 1287


Ignore:
Timestamp:
Mar 11, 2004, 4:05:55 AM (21 years ago)
Author:
bird
Message:

#967: Initial per thread data rewrite.

Location:
trunk/src/emx
Files:
8 added
5 deleted
45 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1286 r1287  
    136136int __dup (int handle);
    137137int __dup2 (int handle1, int handle2);
    138 int __endthread (int tid);
     138int __endthread (void *pvThrd);
    139139int __execname (char *buf, size_t bufsize);
    140140void __exit (int ret) __attribute__ ((__noreturn__));
     
    171171int __imphandle (int handle);
    172172int __impsockhandle (int handle, int flags);
    173 int __initthread (void *preg);
    174173int __ioctl1 (int handle, int code);
    175174int __ioctl2 (int handle, unsigned long request, int arg);
     
    226225int __write (int handle, __const__ void *buf, size_t nbyte);
    227226
    228 
    229 
    230227#if defined (__cplusplus)
    231228}
  • trunk/src/emx/include/emx/thread.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    1 /* emx/thread.h (emx+gcc) */
    2 
    3 #ifndef _EMX_THREAD_H
    4 #define _EMX_THREAD_H
    5 
    6 #if defined (__cplusplus)
    7 extern "C" {
    8 #endif
    9 
    10 #include <time.h> /* struct tm; */
    11 
    12 struct _uheap;
    13 
    14 struct _thread
    15 {
    16   int             _th_errno;                /* comes first, cf. errnofun.s */
    17   void          * _th_arg;
    18   void          (*_th_start)(void *);
    19   unsigned char * _th_strtok_ptr;
    20   char            _th_asctime_buf[26+2];    /* 2 chars for padding */
    21   char            _th_tmpnam_buf[16];       /* cf. stdio.h */
    22   struct tm       _th_gmtime_buf;
    23   unsigned int    _th_rand;                 /* Used by rand() */
    24   void          * _th_store;                /* Pointer to user data */
    25   char            _th_vollabel[12];         /* Used by _getvol() */
    26   char            _th_error[28];            /* Used by strerror() */
    27   struct _uheap * _th_rheap;                /* Default regular heap */
    28   struct _uheap * _th_theap;                /* Default tiled heap */
    29   char            _th_ttyname[32];          /* Used by ttyname() */
    30   char            _th_inetntoa[16];         /* Used by inetntoa() */
    31   int             _th_reserved[974];        /* 4096 bytes, total */
    32 };
    33 
    34 struct _thread *_thread (void);
    35 
    36 
    37 #if defined (__cplusplus)
    38 }
    39 #endif
    40 
    41 #endif /* not _EMX_THREAD_H */
     1#error "This file is dead. use InnoTekLIBC/thread.h!"
  • trunk/src/emx/include/emx/umalloc.h

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1286 r1287  
    606606/* Each thread has its own default heap. */
    607607
    608 #define _UM_DEFAULT_REGULAR_HEAP tp->_th_rheap
    609 #define _UM_DEFAULT_TILED_HEAP   tp->_th_theap
    610 #define _UM_MT_DECL              struct _thread *tp = _thread ();
     608#define _UM_DEFAULT_REGULAR_HEAP pThrd->pRegularHeap
     609#define _UM_DEFAULT_TILED_HEAP   pThrd->pTiledHeap
     610#define _UM_MT_DECL              __LIBC_PTHREAD pThrd = __libc_threadCurrent();
    611611
    612612/* Note that _um_regular_heap is declared in <umalloc.h>.
  • trunk/src/emx/src/lib/io/tmpnam.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    44#include "libc-alias.h"
    55#include <stdio.h>
    6 #include <emx/thread.h>
     6#include <InnoTekLIBC/thread.h>
    77#include "_tmp.h"
    88
     
    1212  if (string == NULL)
    1313    {
    14       struct _thread *tp = _thread ();
    15       string = tp->_th_tmpnam_buf;
     14      __LIBC_PTHREAD pThrd = __libc_threadCurrent ();
     15      string = pThrd->szTmpNamBuf;
    1616    }
    1717  if (_tmpidxnam (string) >= 0)
  • trunk/src/emx/src/lib/io/ttyname.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    44#include <unistd.h>
    55#include <emx/syscalls.h>
    6 #include <emx/thread.h>
     6#include <InnoTekLIBC/thread.h>
    77
    88char *_STD(ttyname) (int handle)
    99{
    10   struct _thread *tp = _thread ();
     10  __LIBC_PTHREAD pThrd = __libc_threadCurrent ();
    1111
    12   if (__ttyname (handle, tp->_th_ttyname, sizeof (tp->_th_ttyname)) == 0)
    13     return tp->_th_ttyname;
     12  if (__ttyname (handle, pThrd->szTTYNameBuf, sizeof (pThrd->szTTYNameBuf)) == 0)
     13    return pThrd->szTTYNameBuf;
    1414  else
    1515    return NULL;
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.49 to 1.50
    r1286 r1287  
    4646    "__streamv_rmutex" @26
    4747    "__streamvec_head" @27
    48     "__thread_tab" @28
     48; fixme "" @28
    4949    "__tmpidx" @29
    5050    "__tzi" @30
     
    7676    "__HUGE_VAL" @103
    7777    "__LHUGE_VAL" @104
    78     "___alloc_thread" @105
     78; fixme    "___alloc_thread" @105
    7979    "___atod" @106
    8080    "___chdir" @107
     
    8989    "___dup" @116
    9090    "___dup2" @117
    91     "___endthread" @118
     91; fixme    "___endthread" @118
    9292    "___exit" @119
    9393    "___fcntl" @120
     
    110110    "___init_app" @137
    111111    "___init_dll" @138
    112     "___initthread" @139
     112; fixme    "___initthread" @139
    113113    "___ioctl1" @140
    114114    "___ioctl2" @141
     
    134134    "___lseek" @161
    135135    "___mkdir" @162
    136     "___newthread" @163
     136; fixme    "___newthread" @163
    137137    "___open" @164
    138138    "___pipe" @165
     
    741741    "__swchar" @768
    742742    "__sys_dump_heap_objs" @769
    743     "__sys_exception" @770
     743    "_sys_exception" @770
    744744    "__tcalloc" @771
    745745    "__tfree" @772
    746746    "__theapmin" @773
    747     "__thread" @774
     747; fixme    "__thread" @774
    748748    "__threadstore" @775
    749749    "__tmalloc" @776
     
    10781078    "___umoddi3"                                @1103
    10791079    "__alloca"                                  @1104
     1080    "__std_usleep" @1105
    10801081
    1081     "__std_usleep" @1105
     1082    "___libc_Back_threadCleanup" @1106
     1083    "___libc_Back_threadEnd" @1107
     1084    "___libc_Back_threadInit" @1108
     1085    "___libc_Back_threadStartup" @1109
     1086    "___libc_TLSAlloc" @1110
     1087    "___libc_TLSFree" @1111
     1088    "___libc_TLSGet" @1112
     1089    "___libc_TLSSet" @1113
  • trunk/src/emx/src/lib/malloc/calloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313void *_STD(calloc) (size_t count, size_t size)
  • trunk/src/emx/src/lib/malloc/heapchk.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313int _heapchk (void)
  • trunk/src/emx/src/lib/malloc/heapmin.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313int _heapmin (void)
  • trunk/src/emx/src/lib/malloc/heapset.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313int _heapset (unsigned fill)
  • trunk/src/emx/src/lib/malloc/heapwalk.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    55#include <umalloc.h>
    66#include <emx/umalloc.h>
    7 #include <emx/thread.h>
     7#include <InnoTekLIBC/thread.h>
    88
    99int _heap_walk (_um_callback1 *callback)
  • trunk/src/emx/src/lib/malloc/initr.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    55#include <emx/umalloc.h>
    66#include <sys/smutex.h>
    7 #include <emx/thread.h>
     7#include <InnoTekLIBC/thread.h>
    88
    99/** This is the default regular heap. */
  • trunk/src/emx/src/lib/malloc/initt.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    44#include <emx/umalloc.h>
    55#include <sys/smutex.h>
    6 #include <emx/thread.h>
     6#include <InnoTekLIBC/thread.h>
    77
    88/** This is the default tiled heap. */
  • trunk/src/emx/src/lib/malloc/malloc.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313void *_STD(malloc) (size_t size)
  • trunk/src/emx/src/lib/malloc/posix_memalign.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1286 r1287  
    2828#include <umalloc.h>
    2929#include <emx/umalloc.h>
    30 #include <emx/thread.h>
     30#include <InnoTekLIBC/thread.h>
    3131#include <assert.h>
    3232
  • trunk/src/emx/src/lib/malloc/tcalloc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313void *_tcalloc (size_t count, size_t size)
  • trunk/src/emx/src/lib/malloc/theapmin.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313int _theapmin (void)
  • trunk/src/emx/src/lib/malloc/tmalloc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313void *_tmalloc (size_t size)
  • trunk/src/emx/src/lib/malloc/trealloc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313void *_trealloc (void *block, size_t new_size)
  • trunk/src/emx/src/lib/malloc/udefault.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313Heap_t _udefault (Heap_t h)
  • trunk/src/emx/src/lib/malloc/utdefaul.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    99#include <sys/rmutex.h>
    1010#include <emx/umalloc.h>
    11 #include <emx/thread.h>
     11#include <InnoTekLIBC/thread.h>
    1212
    1313Heap_t _utdefault (Heap_t h)
  • trunk/src/emx/src/lib/misc/getvol.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    44#include <stdlib.h>
    55#include <string.h>
    6 #include <emx/thread.h>
     6#include <InnoTekLIBC/thread.h>
    77#include <emx/syscalls.h>
    88#define INCL_DOSFILEMGR
     
    1313char *_getvol (char drive)
    1414{
    15   struct _thread *tp = _thread();
     15  __LIBC_PTHREAD pThrd = __libc_threadCurrent();
    1616  FS_VAR();
    1717
     
    3333  if (rc != 0)
    3434    return NULL;
    35   strcpy (tp->_th_vollabel, fsinfo.vol.szVolLabel);
    36 
    37   return tp->_th_vollabel;
     35  return strcpy (pThrd->szVolLabelBuf, fsinfo.vol.szVolLabel);
    3836}
  • trunk/src/emx/src/lib/misc/rand.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    33#include "libc-alias.h"
    44#include <stdlib.h>
    5 #include <emx/thread.h>
     5#include <InnoTekLIBC/thread.h>
    66
    77int _STD(rand) (void)
    88{
    9   struct _thread *tp = _thread();
    10   tp->_th_rand = tp->_th_rand * 69069 + 5;
    11   return (tp->_th_rand >> 16) & 0x7fff;
     9  __LIBC_PTHREAD pThrd = __libc_threadCurrent();
     10  pThrd->iRand = pThrd->iRand * 69069 + 5;
     11  return (pThrd->iRand >> 16) & 0x7fff;
    1212}
    1313
    1414void _STD(srand) (unsigned int seed)
    1515{
    16   struct _thread *tp = _thread();
    17   tp->_th_rand = seed;
     16  __LIBC_PTHREAD pThrd = __libc_threadCurrent();
     17  pThrd->iRand = seed;
    1818}
  • trunk/src/emx/src/lib/process/386/_errno.s

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    1212__errno:
    1313__errno_fun:
    14         fs
    15         movl    12, %eax                /* ptib2 */
    16         movl    0(%eax), %eax           /* TID */
    17         movl    __thread_tab(,%eax,4), %eax
    18 /       addl    $0, %eax                /* address of errno */
     14    movl    ___libc_gpTLS, %eax
     15    movl    (%eax), %eax
     16    orl     %eax, %eax
     17    jnz     done
     18    call    ___libc_threadCurrentSlow
     19done:
    1920        EPILOGUE(_errno)
  • trunk/src/emx/src/lib/process/beginthr.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1286 r1287  
    55#include <string.h>
    66#include <errno.h>
    7 #include <emx/thread.h>
    8 #include <emx/syscalls.h>
    97#define INCL_DOSPROCESS
    108#define INCL_DOSERRORS
     
    1210#define INCL_FSMACROS
    1311#include <os2emx.h>
    14 
    15 #define MAX_THREADS 1024
    16 
    17 static struct _thread thread_1 =
    18 {
    19   0,                            /* _th_errno */
    20   NULL,                         /* _th_arg */
    21   NULL,                         /* _th_start */
    22   NULL,                         /* _th_strtok_ptr (must be NULL) */
    23   {0},                          /* _th_asctime_buf */
    24   {0},                          /* _th_tmpnam_buf */
    25   {0},                          /* _th_gmtime_buf */
    26   1,                            /* _th_rand */
    27   NULL,                         /* _th_store */
    28   "",                           /* _th_vollabel */
    29   "",                           /* _th_error */
    30   NULL,                         /* _th_rheap */
    31   NULL,                         /* _th_theap */
    32   ""                            /* _th_ttyname */
    33 };
    34 
    35 struct _thread *_thread_tab[MAX_THREADS+1] = {NULL, &thread_1};
     12#include <emx/syscalls.h>
     13#include <InnoTekLIBC/thread.h>
     14#include <InnoTekLIBC/backend.h>
    3615
    3716
    38 struct _thread *__alloc_thread (void); /* used in thread.s */
     17/**
     18 * Thread wrapper routine.
     19 *
     20 * @param   pThrd   Pointer to thread structure allocated for this thread.
     21 */
     22static void _System threadWrapper(__LIBC_PTHREAD pThrd)
     23{
     24    int                         tid;
     25    EXCEPTIONREGISTRATIONRECORD reg;
     26    FS_VAR();
    3927
    40 struct _thread *__alloc_thread (void)
    41 {
    42   struct _thread *tp;
    43   ULONG rc;
    44   FS_VAR();
     28    __libc_Back_threadStartup(&reg);
     29    pThrd->u.startup.pfnStart(pThrd->u.startup.pvArg);
    4530
    46   FS_SAVE_LOAD();
    47   rc = DosAllocMem ((PPVOID)&tp, sizeof (struct _thread),
    48                     PAG_COMMIT|PAG_READ|PAG_WRITE);
    49   FS_RESTORE();
    50   if (rc != 0)
    51     return NULL;
    52   memset (tp, 0, sizeof (struct _thread));
    53   tp->_th_rand = 1;             /* Initialize rand() */
    54   return tp;
     31    FS_SAVE_LOAD();
     32    tid = _gettid();
     33    __libc_threadFree(pThrd);
     34    __libc_Back_threadEnd(&reg);
     35    for (;;)
     36        DosExit(tid == 1 ? EXIT_PROCESS : EXIT_THREAD, 0);
    5537}
    5638
    5739
    58 static void start_thread (struct _thread *tp)
     40int _beginthread(void (*pfnStart)(void *), void *pvStack, unsigned cbStack, void *pvArg)
    5941{
    60   EXCEPTIONREGISTRATIONRECORD reg;
     42    APIRET          rc;
     43    TID             tid;
     44    __LIBC_PTHREAD  pThrd;
     45    FS_VAR();
    6146
    62   __initthread (&reg);
    63   tp->_th_start (tp->_th_arg);
    64   _endthread();
     47    /*
     48     * Allocate a thread structure.
     49     */
     50    pThrd = __libc_threadAlloc();
     51    if (!pThrd)
     52    {
     53        errno = ENOMEM;
     54        return -1;
     55    }
     56
     57    /*
     58     * Set the startup thread info and create a new thread.
     59     */
     60    pThrd->u.startup.pfnStart = pfnStart;
     61    pThrd->u.startup.pvArg    = pvArg;
     62    FS_SAVE_LOAD();
     63    rc = DosCreateThread(&tid,
     64                         (PFNTHREAD)threadWrapper,
     65                         (ULONG)pThrd,
     66                         CREATE_READY | STACK_COMMITTED,
     67                         cbStack);
     68    FS_RESTORE();
     69    if (!rc)
     70        return tid;
     71
     72    /*
     73     * Set errno and cleanup.
     74     */
     75    if (rc == ERROR_NOT_ENOUGH_MEMORY)
     76        errno = ENOMEM;
     77    else if (rc == ERROR_MAX_THRDS_REACHED)
     78        errno = EAGAIN;
     79    else
     80        errno = EINVAL;
     81    __libc_threadFree(pThrd);
     82    return -1;
    6583}
    6684
    6785
    68 int _beginthread (void (*start)(void *arg), void *stack, unsigned stack_size,
    69                   void *arg_list)
     86void _endthread(void)
    7087{
    71   ULONG rc;
    72   TID tid;
    73   struct _thread *tp;
    74   FS_VAR();
     88    __LIBC_PTHREAD  pThrd = __libc_threadCurrent();
     89    int             tid;
     90    FS_VAR();
    7591
    76   tp = __alloc_thread ();
    77   if (tp == NULL)
    78     {
    79       errno = ENOMEM;
    80       return -1;
    81     }
    82   tp->_th_start = start;
    83   tp->_th_arg = arg_list;
    84   FS_SAVE_LOAD();
    85   rc = DosCreateThread (&tid, (PFNTHREAD)start_thread, (ULONG)tp,
    86                         CREATE_SUSPENDED | STACK_COMMITTED, stack_size);
    87   if (rc != 0)
    88     {
    89       if (rc == ERROR_NOT_ENOUGH_MEMORY)
    90         errno = ENOMEM;
    91       else if (rc == ERROR_MAX_THRDS_REACHED)
    92         errno = EAGAIN;
    93       else
    94         errno = EINVAL;
    95       DosFreeMem (tp);
    96       FS_RESTORE();
    97       return -1;
    98     }
    99   if (tid > MAX_THREADS)
    100     {
    101       DosKillThread (tid);
    102       errno = EAGAIN;
    103       DosFreeMem (tp);
    104       FS_RESTORE();
    105       return -1;
    106     }
    107   if (__newthread (tid) != 0)
    108     {
    109       DosKillThread (tid);
    110       DosFreeMem (tp);
    111       FS_RESTORE();
    112       return -1;
    113     }
    114   _thread_tab[tid] = tp;
    115   rc = DosResumeThread (tid);
    116   if (rc != 0)
    117     {
    118       errno = ESRCH;
    119       DosFreeMem (tp);
    120       FS_RESTORE();
    121       return -1;
    122     }
    123   FS_RESTORE();
    124   return tid;
     92    FS_SAVE_LOAD();
     93    tid = _gettid();
     94    __libc_threadFree(pThrd);
     95    for (;;)
     96        DosExit(tid == 1 ? EXIT_PROCESS : EXIT_THREAD, 0);
    12597}
    126 
    127 
    128 void _endthread (void)
    129 {
    130   struct _thread *tp;
    131   int tid;
    132   FS_VAR();
    133 
    134   tid = _gettid ();
    135   tp = _thread ();
    136   FS_SAVE_LOAD();
    137   if (tp != &thread_1)
    138     DosFreeMem (tp);
    139   _thread_tab[tid] = NULL;
    140   __endthread (tid);
    141   for (;;)
    142     DosExit ((tid == 1 ? EXIT_PROCESS : EXIT_THREAD), 0);
    143 }
  • trunk/src/emx/src/lib/process/threadst.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1286 r1287  
    33#include "libc-alias.h"
    44#include <stdlib.h>
    5 #include <emx/thread.h>
     5#include <InnoTekLIBC/thread.h>
    66
     7/**
     8 * @obsolete
     9 */
    710void **_threadstore (void)
    811{
    9   return &_thread()->_th_store;
     12  return &__libc_threadCurrent()->pvThreadStoreVar;
    1013}
  • trunk/src/emx/src/lib/startup/startup.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1286 r1287  
    4343
    4444
    45 /** @page Startup
     45/** @page Startup   Startup
    4646 *
    4747 * Quick description of how we startup a process which modules uses LIBC.
     
    5757 *          - __init_dll initiates _sys_pid and _sys_ppid globals.
    5858 *          - __init_dll creates _sys_heap_fmutex and _sys_gmtxHimem.
    59  *          - __init_dll then initializes _sys_thread_table and calls __newthread() in
    60  *            sys/__newthread.c to create the thread 1 entry.
    61  *              - __newthread() will call __sys_newthread() which inits the high memory
    62  *                heap (or low if no high mem) when calling _hmalloc().
     59 *          - __init_dll then initiates __libc_gpTLS with an allocated TLS ULONG.
     60 *            The thread structure it self isn't initialized untill it's actually
     61 *            referenced, and when it is there is static structure for the first
     62 *            thread needing its per thread area.
    6363 *          - __init_dll calls __init_environ() which initializes environ and _org_environ.
    6464 *              - __init_environ() will call _hmalloc() thus initiating the high heap.
  • trunk/src/emx/src/lib/str/strerror.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1286 r1287  
    55#include <stdlib.h>
    66#include <string.h>
    7 #include <emx/thread.h>
     7#include <InnoTekLIBC/thread.h>
    88#include <sys/errno.h>
    99
     
    1515    {
    1616      static char msg[] = "Unknown error ";
    17       struct _thread *tp = _thread();
    18       memcpy (tp->_th_error, msg, sizeof (msg) - 1);
    19       _itoa (errnum, tp->_th_error + sizeof (msg) - 1, 10);
     17      __LIBC_PTHREAD pThrd = __libc_threadCurrent();
     18      memcpy (pThrd->szStrErrorBuf, msg, sizeof (msg) - 1);
     19      _itoa (errnum, pThrd->szStrErrorBuf + sizeof (msg) - 1, 10);
    2020      errno = EINVAL; /* this is actually an invalid error number. */
    21       return tp->_th_error;
     21      return pThrd->szStrErrorBuf;
    2222    }
    2323}
  • trunk/src/emx/src/lib/str/strerror_r.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1286 r1287  
    2727#include <stdlib.h>
    2828#include <string.h>
    29 #include <emx/thread.h>
     29#include <InnoTekLIBC/thread.h>
    3030#include <sys/errno.h>
    3131
  • trunk/src/emx/src/lib/str/strtok.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1286 r1287  
    33#include "libc-alias.h"
    44#include <string.h>
    5 #include <emx/thread.h>
     5#include <InnoTekLIBC/thread.h>
    66
    77char *_STD(strtok) (char *string1, const char *string2)
     
    99  char table[256];
    1010  unsigned char *p, *result;
    11   struct _thread *tp = _thread ();
     11  __LIBC_PTHREAD pThrd = __libc_threadCurrent ();
    1212  if (string1 != NULL)
    1313    p = (unsigned char *)string1;
    1414  else
    1515    {
    16       if (tp->_th_strtok_ptr == NULL)
     16      if (pThrd->pszStrTokPos == NULL)
    1717        return NULL;
    18       p = tp->_th_strtok_ptr;
     18      p = pThrd->pszStrTokPos;
    1919    }
    2020  memset (table, 0, 256);
     
    3232      if (p == result)
    3333        {
    34           tp->_th_strtok_ptr = NULL;
     34          pThrd->pszStrTokPos = NULL;
    3535          return NULL;
    3636        }
     
    3838  else
    3939    *p++ = 0;
    40   tp->_th_strtok_ptr = p;
     40  pThrd->pszStrTokPos = p;
    4141  return (char *)result;
    4242}
  • trunk/src/emx/src/lib/sys/__init.c

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1286 r1287  
    2525#include <emx/umalloc.h>
    2626#include <alloca.h>
     27#include <InnoTekLIBC/thread.h>
    2728
    2829
     
    7778    argc = 0; arg_size = 0;
    7879    /* argv[0] */
    79     PUTC(_ARG_NONZERO);
     80    PUTC((char)_ARG_NONZERO);
    8081    PUTV;
    8182    for (;;)
     
    9495            break;
    9596        flag_ptr = pool;
    96         PUTC(_ARG_NONZERO);
     97        PUTC((char)_ARG_NONZERO);
    9798        PUTV;
    9899        bs = 0; quote = 0;
     
    226227    _sys_init_ret(pStackFrame);
    227228
    228 failure:
     229    failure:
    229230    DosExit(EXIT_PROCESS, 255);
    230231}
     
    233234char const _sys_sig_valid[NSIG] =
    234235{
    235   0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1
     236    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1
    236237};
    237238
    238239struct sig_descr const sig_info[NSIG] =
    239240{
    240   {"SIG0",     ST_TERM,   ST_TERM},
    241   {"SIGHUP",   ST_TERM,   ST_IGNORE},
    242   {"SIGINT",   ST_TERM,   ST_IGNORE},
    243   {"SIGQUIT",  ST_TERM,   ST_IGNORE},
    244   {"SIGILL",   ST_NEXT,   ST_NEXT},
    245   {"SIGTRAP",  ST_NEXT,   ST_NEXT},
    246   {"SIGABRT",  ST_TERM,   ST_TERM},
    247   {"SIGEMT",   ST_TERM,   ST_TERM},
    248   {"SIGFPE",   ST_NEXT,   ST_NEXT},
    249   {"SIGKILL",  ST_TERM,   ST_TERM},
    250   {"SIGBUS",   ST_TERM,   ST_TERM},
    251   {"SIGSEGV",  ST_NEXT,   ST_NEXT},
    252   {"SIGSYS",   ST_TERM,   ST_TERM},
    253   {"SIGPIPE",  ST_TERM,   ST_IGNORE},
    254   {"SIGALRM",  ST_TERM,   ST_IGNORE},
    255   {"SIGTERM",  ST_NEXT,   ST_IGNORE},
    256   {"SIGUSR1",  ST_IGNORE, ST_IGNORE},
    257   {"SIGUSR2",  ST_IGNORE, ST_IGNORE},
    258   {"SIGCLD",   ST_IGNORE, ST_IGNORE},
    259   {"SIG19",    ST_TERM,   ST_TERM},
    260   {"SIG20",    ST_TERM,   ST_TERM},
    261   {"SIGBREAK", ST_TERM,   ST_IGNORE}
     241    {"SIG0",     ST_TERM,   ST_TERM},
     242    {"SIGHUP",   ST_TERM,   ST_IGNORE},
     243    {"SIGINT",   ST_TERM,   ST_IGNORE},
     244    {"SIGQUIT",  ST_TERM,   ST_IGNORE},
     245    {"SIGILL",   ST_NEXT,   ST_NEXT},
     246    {"SIGTRAP",  ST_NEXT,   ST_NEXT},
     247    {"SIGABRT",  ST_TERM,   ST_TERM},
     248    {"SIGEMT",   ST_TERM,   ST_TERM},
     249    {"SIGFPE",   ST_NEXT,   ST_NEXT},
     250    {"SIGKILL",  ST_TERM,   ST_TERM},
     251    {"SIGBUS",   ST_TERM,   ST_TERM},
     252    {"SIGSEGV",  ST_NEXT,   ST_NEXT},
     253    {"SIGSYS",   ST_TERM,   ST_TERM},
     254    {"SIGPIPE",  ST_TERM,   ST_IGNORE},
     255    {"SIGALRM",  ST_TERM,   ST_IGNORE},
     256    {"SIGTERM",  ST_NEXT,   ST_IGNORE},
     257    {"SIGUSR1",  ST_IGNORE, ST_IGNORE},
     258    {"SIGUSR2",  ST_IGNORE, ST_IGNORE},
     259    {"SIGCLD",   ST_IGNORE, ST_IGNORE},
     260    {"SIG19",    ST_TERM,   ST_TERM},
     261    {"SIG20",    ST_TERM,   ST_TERM},
     262    {"SIGBREAK", ST_TERM,   ST_IGNORE}
    262263};
    263264
    264265
    265 static void say (const char *msg)
    266 {
    267   __write (2, msg, strlen (msg));
    268 };
    269 
    270 
    271 static void _sys_terminate (int signo)
    272 {
    273   FS_VAR();
    274   PPIB pPib;
    275   PTIB pTib;
    276   DosGetInfoBlocks (&pTib, &pPib);
    277   say ("\r\n");
    278   say (pPib->pib_pchcmd);
    279   say (":");
    280 
    281   if (signo == SIGABRT)
    282     say ("\r\nAbnormal program termination\r\n");
    283   else
    284     {
    285       say ("\r\nProcess terminated by ");
    286       say (sig_info[signo].name);
    287       say ("\r\n");
    288     }
    289   FS_SAVE_LOAD();
    290   while (1)
    291     DosExit (EXIT_PROCESS, 3);
    292 }
    293 
    294 
    295 static void _sys_signal_acknowledge (int signo)
    296 {
    297   FS_VAR();
    298   FS_SAVE_LOAD();
    299   switch (signo)
    300     {
    301     case SIGINT:
    302       DosAcknowledgeSignalException (XCPT_SIGNAL_INTR);
    303       break;
    304     case SIGTERM:
    305       DosAcknowledgeSignalException (XCPT_SIGNAL_KILLPROC);
    306       break;
    307     case SIGBREAK:
    308       DosAcknowledgeSignalException (XCPT_SIGNAL_BREAK);
    309       break;
    310     }
    311   FS_RESTORE();
     266static void say(const char *msg)
     267{
     268    __write(2, msg, strlen (msg));
     269}
     270
     271
     272static void _sys_terminate(int signo)
     273{
     274    PPIB    pPib;
     275    PTIB    pTib;
     276    FS_VAR();
     277    DosGetInfoBlocks(&pTib, &pPib);
     278    say("\r\n");
     279    say(pPib->pib_pchcmd);
     280    say(":");
     281
     282    if (signo == SIGABRT)
     283        say("\r\nAbnormal program termination\r\n");
     284    else
     285    {
     286        say("\r\nProcess terminated by ");
     287        say(sig_info[signo].name);
     288        say("\r\n");
     289    }
     290    FS_SAVE_LOAD();
     291    while (1)
     292        DosExit(EXIT_PROCESS, 3);
     293}
     294
     295
     296static void _sys_signal_acknowledge(int signo)
     297{
     298    FS_VAR();
     299    FS_SAVE_LOAD();
     300    switch (signo)
     301    {
     302        case SIGINT:
     303            DosAcknowledgeSignalException(XCPT_SIGNAL_INTR);
     304            break;
     305        case SIGTERM:
     306            DosAcknowledgeSignalException(XCPT_SIGNAL_KILLPROC);
     307            break;
     308        case SIGBREAK:
     309            DosAcknowledgeSignalException(XCPT_SIGNAL_BREAK);
     310            break;
     311    }
     312    FS_RESTORE();
    312313}
    313314
     
    315316/* Called from OS/2 exception handler for signal exceptions. */
    316317
    317 static ULONG _sys_signal (int signo)
    318 {
    319   thread_data *tp;
    320 
    321   tp = SYS_THREAD;
    322   if (tp == NULL)
    323     return XCPT_CONTINUE_SEARCH;
    324   __sigaddset (&tp->sig_pending, signo);
    325   _sys_signal_acknowledge (signo);
    326   _sys_deliver_pending_signals (tp);
    327   switch (sig_info[signo].fun_action)
    328   {
    329     case ST_TERM:
    330       _sys_terminate (signo);
    331     case ST_NEXT:
    332       return XCPT_CONTINUE_SEARCH;
    333     case ST_IGNORE:
    334       return XCPT_CONTINUE_EXECUTION;
    335   }
    336   return XCPT_CONTINUE_SEARCH;  /* Keep the optimizer happy */
     318static ULONG _sys_signal(int signo)
     319{
     320    __LIBC_PTHREAD pThrd = __libc_threadCurrentNoAuto();
     321    if (pThrd == NULL)
     322        return XCPT_CONTINUE_SEARCH;
     323    __sigaddset (&pThrd->b.sys.sig_pending, signo);
     324    _sys_signal_acknowledge(signo);
     325    _sys_deliver_pending_signals(pThrd);
     326    switch (sig_info[signo].fun_action)
     327    {
     328        case ST_TERM:
     329            _sys_terminate(signo);
     330        case ST_NEXT:
     331            return XCPT_CONTINUE_SEARCH;
     332        case ST_IGNORE:
     333            return XCPT_CONTINUE_EXECUTION;
     334    }
     335    return XCPT_CONTINUE_SEARCH;  /* Keep the optimizer happy */
    337336}
    338337
     
    340339/* Called from OS/2 exception handler for traps. */
    341340
    342 static ULONG _sys_trap (int signo)
    343 {
    344   thread_data *tp;
    345   void (*handler)(int signo);
    346 
    347   tp = SYS_THREAD;
    348   if (tp == NULL)
    349     return XCPT_CONTINUE_SEARCH;
    350   handler = tp->signals[signo].sa_handler;
    351   if (handler != SIG_IGN && handler != SIG_DFL)
    352     handler (signo);
    353   switch (sig_info[signo].fun_action)
    354     {
    355     case ST_TERM:
    356       _sys_terminate (signo);
    357     case ST_NEXT:
    358       return XCPT_CONTINUE_SEARCH;
    359     case ST_IGNORE:
    360       return XCPT_CONTINUE_EXECUTION;
    361     }
    362   return XCPT_CONTINUE_SEARCH;  /* Keep the optimizer happy */
    363 }
    364 
    365 
    366 static void _sys_deliver_signal (thread_data *tp, int signo)
    367 {
    368   struct sigaction *p;
    369   void (*handler)(int signo);
    370   sigset_t mask, old_blocked;
    371 
    372   /* TODO: Critical section */
    373 
    374   mask = _SIGMASK (signo);
    375   p = &tp->signals[signo];
    376 
    377   tp->sig_pending &= ~mask;
    378   handler = p->sa_handler;
    379 
    380   if (handler == SIG_IGN)
    381     {
    382       /* Ignore the signal. */
    383     }
    384   else if (handler == SIG_DFL)
    385     {
    386       if (sig_info[signo].dfl_action != ST_IGNORE)
    387         _sys_terminate (signo);
    388     }
    389   else
    390     {
    391       if (p->sa_flags & SA_SYSV)
     341static ULONG _sys_trap(int signo)
     342{
     343    __LIBC_PTHREAD  pThrd;
     344    void          (*handler)(int signo);
     345
     346    pThrd = __libc_threadCurrentNoAuto();
     347    if (pThrd == NULL)
     348        return XCPT_CONTINUE_SEARCH;
     349    handler = pThrd->b.sys.signals[signo].sa_handler;
     350    if (handler != SIG_IGN && handler != SIG_DFL)
     351        handler(signo);
     352    switch (sig_info[signo].fun_action)
     353    {
     354        case ST_TERM:
     355            _sys_terminate(signo);
     356        case ST_NEXT:
     357            return XCPT_CONTINUE_SEARCH;
     358        case ST_IGNORE:
     359            return XCPT_CONTINUE_EXECUTION;
     360    }
     361    return XCPT_CONTINUE_SEARCH;  /* Keep the optimizer happy */
     362}
     363
     364
     365static void _sys_deliver_signal(__LIBC_PTHREAD pThrd, int signo)
     366{
     367    struct sigaction *p;
     368    void (*handler)(int signo);
     369    sigset_t mask, old_blocked;
     370
     371    /* TODO: Critical section */
     372
     373    mask = _SIGMASK(signo);
     374    p = &pThrd->b.sys.signals[signo];
     375
     376    pThrd->b.sys.sig_pending &= ~mask;
     377    handler = p->sa_handler;
     378
     379    if (handler == SIG_IGN)
     380    {
     381        /* Ignore the signal. */
     382    }
     383    else if (handler == SIG_DFL)
     384    {
     385        if (sig_info[signo].dfl_action != ST_IGNORE)
     386            _sys_terminate(signo);
     387    }
     388    else
     389    {
     390        if (p->sa_flags & SA_SYSV)
    392391        {
    393           p->sa_handler = SIG_DFL;
    394           handler (signo);
     392            p->sa_handler = SIG_DFL;
     393            handler(signo);
    395394        }
    396       else if (p->sa_flags & SA_ACK)
     395        else if (p->sa_flags & SA_ACK)
    397396        {
    398           tp->sig_blocked |= mask;
    399           handler (signo);
     397            pThrd->b.sys.sig_blocked |= mask;
     398            handler(signo);
    400399        }
    401       else
     400        else
    402401        {
    403           old_blocked = tp->sig_blocked;
    404           SET_BLOCKED (tp, tp->sig_blocked | mask | p->sa_mask);
    405           handler (signo);
    406           tp->sig_blocked = old_blocked;
     402            old_blocked = pThrd->b.sys.sig_blocked;
     403            SET_BLOCKED(&pThrd->b.sys, pThrd->b.sys.sig_blocked | mask | p->sa_mask);
     404            handler(signo);
     405            pThrd->b.sys.sig_blocked = old_blocked;
    407406        }
    408407    }
     
    410409
    411410
    412 void _sys_deliver_pending_signals (thread_data *tp)
    413 {
    414   int signo;
    415 
    416   /* TODO: Critical section */
    417   while ((tp->sig_pending & ~tp->sig_blocked) != 0)
    418     {
    419       for (signo = 1; signo < NSIG; ++signo)
    420         if (tp->sig_pending & ~tp->sig_blocked & _SIGMASK (signo))
    421           _sys_deliver_signal (tp, signo);
     411void _sys_deliver_pending_signals(__LIBC_PTHREAD pThrd)
     412{
     413    int signo;
     414
     415    /* TODO: Critical section */
     416    while ((pThrd->b.sys.sig_pending & ~pThrd->b.sys.sig_blocked) != 0)
     417    {
     418        for (signo = 1; signo < NSIG; ++signo)
     419            if (pThrd->b.sys.sig_pending & ~pThrd->b.sys.sig_blocked & _SIGMASK(signo))
     420                _sys_deliver_signal(pThrd, signo);
    422421    }
    423422}
    424423
    425424/* from kLib/kHeapDbg.h */
    426 typedef enum { enmRead, enmWrite, enmUnknown } ENMACCESS;
     425typedef enum
     426{
     427    enmRead, enmWrite, enmUnknown
     428} ENMACCESS;
    427429extern BOOL _Optlink kHeapDbgException(void *    pvAccess,
    428430                                       ENMACCESS enmAccess,
     
    432434asm (".weak kHeapDbgException");
    433435
    434 ULONG _sys_exception (PEXCEPTIONREPORTRECORD report,
    435                       PEXCEPTIONREGISTRATIONRECORD registration,
    436                       PCONTEXTRECORD context,
    437                       PVOID whatever)
    438 {
    439   __asm__ ("cld");              /* Don't trust */
    440   if (report->fHandlerFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
     436ULONG _System _sys_exception(PEXCEPTIONREPORTRECORD report,
     437                             PEXCEPTIONREGISTRATIONRECORD registration,
     438                             PCONTEXTRECORD context,
     439                             PVOID whatever)
     440{
     441    __asm__ ("cld");              /* Don't trust */
     442    if (report->fHandlerFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
     443        return XCPT_CONTINUE_SEARCH;
     444    switch (report->ExceptionNum)
     445    {
     446        case XCPT_SIGNAL:
     447            if (report->cParameters >= 1)
     448            {
     449                if (report->ExceptionInfo[0] == XCPT_SIGNAL_INTR)
     450                    return _sys_signal(SIGINT);
     451                else if (report->ExceptionInfo[0] == XCPT_SIGNAL_KILLPROC)
     452                    return _sys_signal(SIGTERM);
     453                else if (report->ExceptionInfo[0] == XCPT_SIGNAL_BREAK)
     454                    return _sys_signal(SIGBREAK);
     455            }
     456            break;
     457        case XCPT_ACCESS_VIOLATION:
     458            /* If we're linking libc01.elh or someone is linking static libc
     459               together with kLib the electric fence heap will get the opportunity
     460               to check if any access violation was caused by someone touching any
     461               of the electric fences. */
     462            if (    kHeapDbgException
     463                &&  (   report->ExceptionInfo[0] == XCPT_READ_ACCESS
     464                        || report->ExceptionInfo[0] == XCPT_WRITE_ACCESS
     465                        || report->ExceptionInfo[0] == XCPT_EXECUTE_ACCESS
     466                        || report->ExceptionInfo[0] == XCPT_UNKNOWN_ACCESS)
     467               )
     468            {
     469                ENMACCESS enmAccess = enmRead;
     470                switch (report->ExceptionInfo[0])
     471                {
     472                    case XCPT_WRITE_ACCESS:     enmAccess = enmWrite; break;
     473                    case XCPT_UNKNOWN_ACCESS:   enmAccess = enmUnknown; break;
     474                }
     475                /* This call returns true if the page was commited in order
     476                   to workaround the immediate problem. If it returns false
     477                   the default action should be taken. */
     478                if (kHeapDbgException((void*)report->ExceptionInfo[1],
     479                                      enmAccess,
     480                                      report->ExceptionAddress,
     481                                      report))
     482                    return XCPT_CONTINUE_EXECUTION;
     483            }
     484        case XCPT_DATATYPE_MISALIGNMENT:
     485            return _sys_trap(SIGSEGV);
     486
     487        case XCPT_INTEGER_DIVIDE_BY_ZERO:
     488        case XCPT_INTEGER_OVERFLOW:
     489        case XCPT_ARRAY_BOUNDS_EXCEEDED:
     490        case XCPT_FLOAT_DENORMAL_OPERAND:
     491        case XCPT_FLOAT_DIVIDE_BY_ZERO:
     492        case XCPT_FLOAT_INEXACT_RESULT:
     493        case XCPT_FLOAT_INVALID_OPERATION:
     494        case XCPT_FLOAT_OVERFLOW:
     495        case XCPT_FLOAT_STACK_CHECK:
     496        case XCPT_FLOAT_UNDERFLOW:
     497            return _sys_trap(SIGFPE);
     498
     499        case XCPT_ILLEGAL_INSTRUCTION:
     500        case XCPT_INVALID_LOCK_SEQUENCE:
     501        case XCPT_PRIVILEGED_INSTRUCTION:
     502            return _sys_trap(SIGILL);
     503    }
    441504    return XCPT_CONTINUE_SEARCH;
    442   switch (report->ExceptionNum)
    443     {
    444     case XCPT_SIGNAL:
    445       if (report->cParameters >= 1)
    446         {
    447           if (report->ExceptionInfo[0] == XCPT_SIGNAL_INTR)
    448             return _sys_signal (SIGINT);
    449           else if (report->ExceptionInfo[0] == XCPT_SIGNAL_KILLPROC)
    450             return _sys_signal (SIGTERM);
    451           else if (report->ExceptionInfo[0] == XCPT_SIGNAL_BREAK)
    452             return _sys_signal (SIGBREAK);
    453         }
    454       break;
    455     case XCPT_ACCESS_VIOLATION:
    456       /* If we're linking libc01.elh or someone is linking static libc
    457          together with kLib the electric fence heap will get the opportunity
    458          to check if any access violation was caused by someone touching any
    459          of the electric fences. */
    460       if (    kHeapDbgException
    461           &&  (   report->ExceptionInfo[0] == XCPT_READ_ACCESS
    462                || report->ExceptionInfo[0] == XCPT_WRITE_ACCESS
    463                || report->ExceptionInfo[0] == XCPT_EXECUTE_ACCESS
    464                || report->ExceptionInfo[0] == XCPT_UNKNOWN_ACCESS)
    465           )
    466         {
    467           ENMACCESS enmAccess = enmRead;
    468           switch (report->ExceptionInfo[0])
    469           {
    470             case XCPT_WRITE_ACCESS:     enmAccess = enmWrite; break;
    471             case XCPT_UNKNOWN_ACCESS:   enmAccess = enmUnknown; break;
    472           }
    473           /* This call returns true if the page was commited in order
    474              to workaround the immediate problem. If it returns false
    475              the default action should be taken. */
    476           if (kHeapDbgException((void*)report->ExceptionInfo[1],
    477                                 enmAccess,
    478                                 report->ExceptionAddress,
    479                                 report))
    480                   return XCPT_CONTINUE_EXECUTION;
    481         }
    482     case XCPT_DATATYPE_MISALIGNMENT:
    483       return _sys_trap (SIGSEGV);
    484 
    485     case XCPT_INTEGER_DIVIDE_BY_ZERO:
    486     case XCPT_INTEGER_OVERFLOW:
    487     case XCPT_ARRAY_BOUNDS_EXCEEDED:
    488     case XCPT_FLOAT_DENORMAL_OPERAND:
    489     case XCPT_FLOAT_DIVIDE_BY_ZERO:
    490     case XCPT_FLOAT_INEXACT_RESULT:
    491     case XCPT_FLOAT_INVALID_OPERATION:
    492     case XCPT_FLOAT_OVERFLOW:
    493     case XCPT_FLOAT_STACK_CHECK:
    494     case XCPT_FLOAT_UNDERFLOW:
    495       return _sys_trap (SIGFPE);
    496 
    497     case XCPT_ILLEGAL_INSTRUCTION:
    498     case XCPT_INVALID_LOCK_SEQUENCE:
    499     case XCPT_PRIVILEGED_INSTRUCTION:
    500       return _sys_trap (SIGILL);
    501     }
    502   return XCPT_CONTINUE_SEARCH;
    503 }
    504 
    505 
    506 void _sys_get_clock (unsigned long *ms)
    507 {
    508   ULONG val_ms;
    509   FS_VAR();
    510 
    511   FS_SAVE_LOAD();
    512   DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &val_ms, sizeof (val_ms));
    513   FS_RESTORE();
    514   *ms = val_ms;
    515 }
    516 
    517 
    518 void _sys_init_thread (thread_data *tp)
    519 {
    520   int n;
    521 
    522   __sigemptyset (&tp->sig_blocked);
    523   __sigemptyset (&tp->sig_pending);
    524   for (n = 0; n < NSIG; ++n)
    525     {
    526       tp->signals[n].sa_handler = SIG_DFL;
    527       tp->signals[n].sa_flags   = SA_ACK;
    528       __sigemptyset (&tp->signals[n].sa_mask);
    529     }
    530   tp->fd.hdir = HDIR_CREATE;
    531   tp->fd.cFiles = 0;
    532 }
     505}
     506
     507
     508void _sys_get_clock(unsigned long *ms)
     509{
     510    ULONG val_ms;
     511    FS_VAR();
     512
     513    FS_SAVE_LOAD();
     514    DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &val_ms, sizeof (val_ms));
     515    FS_RESTORE();
     516    *ms = val_ms;
     517}
     518
     519
  • trunk/src/emx/src/lib/sys/__initdll.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1286 r1287  
    1111*/
    1212
    13 
    14 /*******************************************************************************
    15 *   Defined Constants And Macros                                               *
    16 *******************************************************************************/
    17 #define SYS_PRIVATE_HEAP_SIZE 0x100000
    1813
    1914/*******************************************************************************
     
    3530#include <emx/umalloc.h>
    3631#include <alloca.h>
    37 
    3832#include "syscalls.h"
     33#include <InnoTekLIBC/thread.h>
    3934
    4035/* Make this function an weak external. */
     
    4540*   Global Variables                                                           *
    4641*******************************************************************************/
     42__LIBC_PPTHREAD     __libc_gpTLS;
     43
    4744extern unsigned char _osminor;
    4845extern unsigned char _osmajor;
     
    5956    PTIB    ptib;
    6057    PPIB    ppib;
    61     int     n;
    6258    static int initialized = 0;
    6359
     
    110106
    111107    /*
    112      * Initialize thread table and entry for this thread.
     108     * Initialize TLS.
    113109     */
    114     /** @todo Remove this table, replace it with a pointer backed by TLS memory. */
    115     for (n = 0; n < MAX_THREADS; ++n)
    116         _sys_thread_table[n] = NULL;
    117     __newthread(ptib->tib_ptib2->tib2_ultid);
     110    if (!__libc_gpTLS)                  /* !paranoia! */
     111    {
     112        rc = DosAllocThreadLocalMemory(1, (PULONG*)&__libc_gpTLS);
     113        if (rc)
     114            return -1;
     115    }
    118116
    119117    /*
  • trunk/src/emx/src/lib/sys/filefind.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1286 r1287  
    1212#include <emx/syscalls.h>
    1313#include "syscalls.h"
     14#include <InnoTekLIBC/thread.h>
    1415
    1516/**
     
    114115{
    115116    ULONG               rc;
    116     struct find_data   *pFD = &SYS_THREAD->fd;
     117    struct find_data   *pFD = &__libc_threadCurrent()->b.sys.fd;
    117118    FS_VAR();
    118119
     
    145146    FS_SAVE_LOAD();
    146147    memset(&pFD->achBuffer[0], 0, sizeof(pFD->achBuffer));
    147     rc = DosFindFirst(pszName,
     148    rc = DosFindFirst((PCSZ)pszName,
    148149                      &pFD->hdir,
    149150                      attr & (FILE_NORMAL | FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED),
     
    181182{
    182183    ULONG               rc;
    183     struct find_data   *pFD = &SYS_THREAD->fd;
     184    struct find_data   *pFD = &__libc_threadCurrent()->b.sys.fd;
    184185    FS_VAR();
    185186
  • trunk/src/emx/src/lib/sys/raise.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    77#include <errno.h>
    88#include <emx/syscalls.h>
     9#include <InnoTekLIBC/thread.h>
    910#include "syscalls.h"
    1011
    11 int _STD(raise) (int signo)
     12int _STD(raise)(int signo)
    1213{
    13   thread_data *tp;
     14    __LIBC_PTHREAD  pThrd = __libc_threadCurrent();
    1415
    15   if (signo < 1 || signo >= NSIG || !_sys_sig_valid[signo])
     16    if (signo < 1 || signo >= NSIG || !_sys_sig_valid[signo])
    1617    {
    17       errno = EINVAL;
    18       return -1;
     18        errno = EINVAL;
     19        return -1;
    1920    }
    20   tp = SYS_THREAD;
    21   if (tp == NULL)
     21    if (pThrd->b.sys.signals[signo].sa_handler != SIG_IGN)
    2222    {
    23       errno = EINVAL;
    24       return -1;
     23        __sigaddset(&pThrd->b.sys.sig_pending, signo);
     24        _sys_deliver_pending_signals(pThrd);
    2525    }
    26   if (tp->signals[signo].sa_handler != SIG_IGN)
    27     {
    28       __sigaddset (&tp->sig_pending, signo);
    29       _sys_deliver_pending_signals (tp);
    30     }
    31   return 0;
     26    return 0;
    3227}
  • trunk/src/emx/src/lib/sys/sigaction.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1286 r1287  
    66#include <errno.h>
    77#include <emx/syscalls.h>
     8#include <InnoTekLIBC/thread.h>
    89#include "syscalls.h"
    910
    10 int _STD(sigaction) (int signo, const struct sigaction *iact,
    11   struct sigaction *oact)
     11int _STD(sigaction)(int signo, const struct sigaction *iact,
     12                    struct sigaction *oact)
    1213{
    13   struct sigaction output, *s;
    14   thread_data *tp;
     14    struct sigaction    output;
     15    struct sigaction   *s;
     16    __LIBC_PTHREAD      pThrd;
    1517
    16   if (signo < 1 || signo >= NSIG || signo == SIGKILL || !_sys_sig_valid[signo])
     18    if (signo < 1 || signo >= NSIG || signo == SIGKILL || !_sys_sig_valid[signo])
    1719    {
    18       errno = EINVAL;
    19       return -1;
     20        errno = EINVAL;
     21        return -1;
    2022    }
    21   if (signo == SIGKILL && iact != NULL)
     23    if (signo == SIGKILL && iact != NULL)
    2224    {
    23       errno = EINVAL;
    24       return -1;
     25        errno = EINVAL;
     26        return -1;
    2527    }
    26   tp = SYS_THREAD;
    27   if (tp == NULL)
     28    pThrd = __libc_threadCurrent();
     29    s = &pThrd->b.sys.signals[signo];
     30    output = *s;
     31    if (iact != NULL)
    2832    {
    29       errno = EINVAL;
    30       return -1;
    31     }
    32   s = &tp->signals[signo];
    33   output = *s;
    34   if (iact != NULL)
    35     {
    36       *s = *iact;
    37       if ((s->sa_handler == SIG_DFL
    38            && sig_info[signo].dfl_action != ST_IGNORE)
    39           || s->sa_handler == SIG_IGN)
    40         sigdelset (&tp->sig_pending, signo);
     33        *s = *iact;
     34        if (    (   s->sa_handler == SIG_DFL
     35                 && sig_info[signo].dfl_action != ST_IGNORE)
     36            ||  s->sa_handler == SIG_IGN)
     37            sigdelset(&pThrd->b.sys.sig_pending, signo);
    4138    }
    4239
    43   if (oact != NULL)
    44     *oact = output;
    45   return 0;
     40    if (oact != NULL)
     41        *oact = output;
     42    return 0;
    4643}
  • trunk/src/emx/src/lib/sys/signal.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    77#include <emx/syscalls.h>
    88#include "syscalls.h"
     9#include <InnoTekLIBC/thread.h>
    910
    10 typedef void sigfun (int sig);
     11typedef void sigfun(int sig);
    1112
    12 sigfun *_STD(signal) (int sig, sigfun *handler)
     13sigfun *_STD(signal)(int sig, sigfun *handler)
    1314{
    14   if (handler == SIG_ACK)
     15    if (handler == SIG_ACK)
    1516    {
    16       thread_data *tp;
     17        __LIBC_PTHREAD pThrd;
    1718
    18       if (sig < 1 || sig >= NSIG || sig == SIGKILL || !_sys_sig_valid[sig])
     19        if (sig < 1 || sig >= NSIG || sig == SIGKILL || !_sys_sig_valid[sig])
    1920        {
    20           errno = EINVAL;
    21           return SIG_ERR;
     21            errno = EINVAL;
     22            return SIG_ERR;
    2223        }
    23       tp = SYS_THREAD;
    24       if (tp == NULL)
    25         return SIG_ERR;
    26       sigdelset (&tp->sig_blocked, sig);
    27       _sys_deliver_pending_signals (tp);
    28       return tp->signals[sig].sa_handler;
     24        pThrd = __libc_threadCurrent();
     25        if (pThrd == NULL)
     26            return SIG_ERR;
     27        sigdelset(&pThrd->b.sys.sig_blocked, sig);
     28        _sys_deliver_pending_signals(pThrd);
     29        return pThrd->b.sys.signals[sig].sa_handler;
    2930    }
    30   else
     31    else
    3132    {
    32       struct sigaction isa, osa;
     33        struct sigaction isa, osa;
    3334
    34       isa.sa_handler = handler;
    35       isa.sa_mask = 0;
    36       isa.sa_flags = SA_ACK;
    37       if (sigaction (sig, &isa, &osa) != 0)
    38         return SIG_ERR;
    39       else
    40         return osa.sa_handler;
     35        isa.sa_handler = handler;
     36        isa.sa_mask = 0;
     37        isa.sa_flags = SA_ACK;
     38        if (sigaction(sig, &isa, &osa) != 0)
     39            return SIG_ERR;
     40        else
     41            return osa.sa_handler;
    4142    }
    4243}
  • trunk/src/emx/src/lib/sys/sigpending.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    66#include <emx/syscalls.h>
    77#include "syscalls.h"
     8#include <InnoTekLIBC/thread.h>
    89
    910int _STD(sigpending) (sigset_t *set)
    1011{
    11   thread_data *tp;
    12 
    13   /* TODO: Critical section */
    14   tp = SYS_THREAD;
    15   *set = tp->sig_blocked & tp->sig_pending;
    16   return 0;
     12    /* TODO: Critical section */
     13    __LIBC_PTHREAD  pThrd = __libc_threadCurrent();
     14    *set = pThrd->b.sys.sig_blocked & pThrd->b.sys.sig_pending;
     15    return 0;
    1716}
  • trunk/src/emx/src/lib/sys/sigprocmask.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    77#include <emx/syscalls.h>
    88#include "syscalls.h"
     9#include <InnoTekLIBC/thread.h>
    910
    10 int _STD(sigprocmask) (int how, const sigset_t *iset, sigset_t *oset)
     11int _STD(sigprocmask)(int how, const sigset_t *iset, sigset_t *oset)
    1112{
    12   thread_data *tp;
    13   sigset_t temp, output;
     13    __LIBC_PTHREAD  pThrd = __libc_threadCurrent();
     14    sigset_t temp, output;
    1415
    15   tp = SYS_THREAD;
    16   output = tp->sig_blocked;
    17   if (iset != NULL)
     16    output = pThrd->b.sys.sig_blocked;
     17    if (iset != NULL)
    1818    {
    19       switch (how)
     19        switch (how)
    2020        {
    21         case SIG_BLOCK:
    22           temp = tp->sig_blocked | *iset;
    23           break;
    24         case SIG_UNBLOCK:
    25           temp = tp->sig_blocked & ~*iset;
    26           break;
    27         case SIG_SETMASK:
    28           temp = *iset;
    29           break;
    30         default:
    31           errno = EINVAL;
    32           return -1;
     21            case SIG_BLOCK:
     22                temp = pThrd->b.sys.sig_blocked | *iset;
     23                break;
     24            case SIG_UNBLOCK:
     25                temp = pThrd->b.sys.sig_blocked & ~*iset;
     26                break;
     27            case SIG_SETMASK:
     28                temp = *iset;
     29                break;
     30            default:
     31                errno = EINVAL;
     32                return -1;
    3333        }
    34       SET_BLOCKED (tp, temp);
     34        SET_BLOCKED(&pThrd->b.sys, temp);
    3535    }
    3636
    37   if (oset != NULL)
    38     *oset = output;
     37    if (oset != NULL)
     38        *oset = output;
    3939
    40   _sys_deliver_pending_signals (tp);
    41   return 0;
     40    _sys_deliver_pending_signals(pThrd);
     41    return 0;
    4242}
  • trunk/src/emx/src/lib/sys/sigsuspend.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1286 r1287  
    77#include <emx/syscalls.h>
    88#include "syscalls.h"
     9#include <InnoTekLIBC/thread.h>
    910
    1011int _STD(sigsuspend) (const sigset_t *mask)
    1112{
    12   sigset_t old_blocked;
    13   thread_data *tp;
     13    /* TODO: Critical section */
     14    __LIBC_PTHREAD  pThrd = __libc_threadCurrent();
     15    sigset_t        old_blocked;
    1416
    15   /* TODO: Critical section */
    16   tp = SYS_THREAD;
    17   old_blocked = tp->sig_blocked;
    18   SET_BLOCKED (tp, *mask);
    19   pause ();
    20   tp->sig_blocked = old_blocked;
    21   errno = EINTR;
    22   return -1;
     17    old_blocked = pThrd->b.sys.sig_blocked;
     18    SET_BLOCKED(&pThrd->b.sys, *mask);
     19    pause();
     20    pThrd->b.sys.sig_blocked = old_blocked;
     21    errno = EINTR;
     22    return -1;
    2323}
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1286 r1287  
    66#include "libc-alias.h"
    77#include <sys/signal.h>
     8
     9#ifndef __LIBC_THREAD_DECLARED
     10#define __LIBC_THREAD_DECLARED
     11struct __libc_threadCurrentSlow;
     12typedef struct __libc_threadCurrentSlow *__LIBC_PTHREAD, **__LIBC_PPTHREAD;
     13#endif
    814
    915#if !defined (NULL)
     
    102108#define FDATEZEROP(x) (*(PUSHORT)&(x) == 0)
    103109
    104 /** Directory find data entry.
    105  * Used by __findfirst() and __findnext(). */
    106 struct find_data
    107 {
    108     /** Directory handle. HDIR_CREATE if no session opened. */
    109     HDIR        hdir;
    110     /** Type of buffer content. FIL_STANDARDL or FIL_STANDARD,
    111      * i.e. FILEFINDBUF3 or FILEFINDBUF3L. */
    112     ULONG       fType;
    113     /** Number of files left in the buffer. */
    114     ULONG       cFiles;
    115     /** Pointer to the next entry. Don't test on this, test on cFiles! */
    116     const char *pchNext;
    117     /** Buffer. */
    118     char        achBuffer[2048];
    119 };
    120 
    121 typedef struct
    122 {
    123   struct find_data fd;
    124   sigset_t sig_blocked;
    125   sigset_t sig_pending;
    126   struct sigaction signals[NSIG];
    127 } thread_data;
    128 
    129110#if defined (INCL_DOSEXCEPTIONS)
    130111EXTERN PEXCEPTIONREGISTRATIONRECORD _sys_xreg INIT (NULL);
    131 ULONG _sys_exception (PEXCEPTIONREPORTRECORD report,
     112ULONG _System _sys_exception (PEXCEPTIONREPORTRECORD report,
    132113    PEXCEPTIONREGISTRATIONRECORD registration, PCONTEXTRECORD context,
    133114    PVOID whatever);
     
    154135extern struct sig_descr const sig_info[NSIG];
    155136
    156 long _sys_p2t (FTIME t, FDATE d);
    157 void _sys_init_thread (thread_data *tp);
    158 void _sys_deliver_pending_signals (thread_data *tp);
    159 
    160 #define MAX_THREADS 1024
    161 
    162 EXTERN thread_data *_sys_thread_table[MAX_THREADS];
    163 
    164 thread_data *_sys_thread (void);
    165 #define SYS_THREAD (_sys_thread ())
     137long _sys_p2t(FTIME t, FDATE d);
     138void _sys_deliver_pending_signals(__LIBC_PTHREAD pThrd);
    166139
    167140#endif /* _OS2EMX_H */
  • trunk/src/emx/src/lib/time/asctime.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1286 r1287  
    44#include <string.h>
    55#include <time.h>
    6 #include <emx/thread.h>
     6#include <InnoTekLIBC/thread.h>
    77
    88static char const months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
     
    1313char *_STD(asctime) (const struct tm *t)
    1414{
    15   struct _thread *tp = _thread();
    16   return asctime_r(t, tp->_th_asctime_buf);
     15  __LIBC_PTHREAD pThrd = __libc_threadCurrent();
     16  return asctime_r(t, pThrd->szAscTimeAndCTimeBuf);
    1717}
    1818
  • trunk/src/emx/src/lib/time/gmtime.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1286 r1287  
    44#include <stdlib.h>
    55#include <time.h>
    6 #include <emx/thread.h>
     6#include <InnoTekLIBC/thread.h>
    77#include <emx/time.h>
    88
     
    6969struct tm *_STD(gmtime)(const time_t *t)
    7070{
    71     struct _thread *tp = _thread ();
    72     return gmtime_r (t, &tp->_th_gmtime_buf);
     71    __LIBC_PTHREAD pThrd = __libc_threadCurrent ();
     72    return gmtime_r (t, &pThrd->GmTimeAndLocalTimeBuf);
    7373}
  • trunk/src/emx/src/lib/time/localtim.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1286 r1287  
    33#include "libc-alias.h"
    44#include <time.h>
    5 #include <emx/thread.h>
     5#include <InnoTekLIBC/thread.h>
    66#include <emx/time.h>
    77
    88struct tm *_STD(localtime)(const time_t *t)
    99{
    10     struct _thread *tp = _thread();
    11     return localtime_r(t, &tp->_th_gmtime_buf);
     10    __LIBC_PTHREAD pThrd = __libc_threadCurrent();
     11    return localtime_r(t, &pThrd->GmTimeAndLocalTimeBuf);
    1212}
    1313
  • trunk/src/emx/testcase/loadthread2.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1286 r1287  
    1111    APIRET  rc;
    1212    szObj[0] = '\0';
    13     rc = DosLoadModule(szObj, sizeof(szObj), "LIBC05.DLL", &hmod);
     13    rc = DosLoadModule(szObj, sizeof(szObj), "LIBC06.DLL", &hmod);
    1414    if (rc)
    15         printf("DosLoadModule failed loading LIBC05.DLL. rc=%d szObj=%s\n", rc, szObj);
     15        printf("DosLoadModule failed loading LIBC06.DLL. rc=%d szObj=%s\n", rc, szObj);
    1616    else
    17         printf("Successfully loaded LIBC05.DLL\n");
     17        printf("Successfully loaded LIBC06.DLL\n");
    1818    grc = rc;
    1919}
  • trunk/src/emx/version.smak

    • Property cvs2svn:cvs-rev changed from 1.13 to 1.14
    r1286 r1287  
    44VH = 0
    55# Middle part of version number
    6 VM = 5
     6VM = 6
    77# Low part of version number
    88VL = 0
Note: See TracChangeset for help on using the changeset viewer.