2001-09-11 22:01:02 +02:00
|
|
|
/* init.cc
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-11-28 21:55:59 +01:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2000-08-02 18:28:18 +02:00
|
|
|
#include <stdlib.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "thread.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "perprocess.h"
|
2003-12-14 08:09:22 +01:00
|
|
|
#include "cygthread.h"
|
2003-11-28 21:55:59 +01:00
|
|
|
#include "cygtls.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
int NO_COPY dynamically_loaded;
|
|
|
|
|
2003-12-14 08:09:22 +01:00
|
|
|
static void WINAPI
|
|
|
|
threadfunc_fe (VOID *arg)
|
|
|
|
{
|
|
|
|
_threadinfo::call ((DWORD (*) (void *, void *)) (((char **) _tlsbase)[-1]), arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
munge_threadfunc (HANDLE cygwin_hmodule)
|
|
|
|
{
|
|
|
|
char **ebp = (char **) __builtin_frame_address (0);
|
|
|
|
static unsigned threadfunc_ix;
|
|
|
|
if (!threadfunc_ix)
|
|
|
|
{
|
|
|
|
for (char **peb = ebp; peb < (char **) _tlsbase; peb++)
|
|
|
|
if (*peb == (char *) cygthread::stub)
|
|
|
|
{
|
|
|
|
threadfunc_ix = peb - ebp;
|
|
|
|
goto foundit;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foundit:
|
|
|
|
char *threadfunc = ebp[threadfunc_ix];
|
|
|
|
ebp[threadfunc_ix] = (char *) threadfunc_fe;
|
|
|
|
((char **) _tlsbase)[-1] = threadfunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int WINAPI
|
|
|
|
dll_entry (HANDLE h, DWORD reason, void *static_load)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2003-11-28 21:55:59 +01:00
|
|
|
_my_tls.stackptr = _my_tls.stack;
|
2000-02-17 20:38:33 +01:00
|
|
|
dynamically_loaded = (static_load == NULL);
|
|
|
|
break;
|
2002-10-07 06:12:54 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
case DLL_THREAD_ATTACH:
|
2002-11-24 14:54:14 +01:00
|
|
|
if (MT_INTERFACE->reent_key.set (&MT_INTERFACE->reents))
|
2002-10-07 06:12:54 +02:00
|
|
|
api_fatal ("thread initialization failed");
|
2003-12-14 08:09:22 +01:00
|
|
|
munge_threadfunc (h);
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|