--- sal/osl/unx/thread.c	2006-08-30 10:16:29.000000000 +0800
+++ sal/osl/unx/thread.c	2006-08-30 11:08:53.000000000 +0800
@@ -136,7 +136,7 @@ static void* osl_thread_start_Impl (void
 static void  osl_thread_cleanup_Impl (void * pData);
 
 static oslThread osl_thread_create_Impl (
-	oslWorkerFunction pWorker, void * pThreadData, short nFlags);
+	oslWorkerFunction pWorker, void * pThreadData, short nFlags, sal_Int32 nFrames );
 
 static void osl_thread_join_cleanup_Impl (void * opaque);
 static void osl_thread_wait_cleanup_Impl (void * opaque);
@@ -290,7 +290,8 @@ static void* osl_thread_start_Impl (void
 static oslThread osl_thread_create_Impl (
 	oslWorkerFunction pWorker,
 	void*             pThreadData,
-	short             nFlags)
+	short             nFlags,
+	sal_Int32         nFrames)
 {
 	Thread_Impl* pImpl;
     int nRet=0;
@@ -305,10 +306,24 @@ static oslThread osl_thread_create_Impl 
 
     pthread_mutex_lock (&(pImpl->m_Lock));
 
+	pthread_attr_t attr;
+	pthread_attr_init (&attr);
+
+#if defined (LINUX) || defined (SOLARIS)
+	if (nFrames > 0)
+	{
+	  size_t stack_size = sysconf (_SC_THREAD_STACK_MIN);
+	  if (nFrames * 128 > stack_size)
+		  stack_size = nFrames * 128;
+//	  if (!getenv ("DISABLE_SIZE"))
+		  pthread_attr_setstacksize (&attr, stack_size);
+//	  fprintf (stderr, "Set stack size %d\n", stack_size);
+	}
+#endif
+
 	if ((nRet = pthread_create (
 		&(pImpl->m_hThread),
-		PTHREAD_ATTR_DEFAULT,
-		osl_thread_start_Impl,
+		&attr, osl_thread_start_Impl,
 		(void*)(pImpl))) != 0)
 	{
 	    OSL_TRACE("osl_thread_create_Impl(): errno: %d, %s\n",
@@ -344,7 +359,21 @@ oslThread osl_createThread (
     return osl_thread_create_Impl (
 		pWorker,
 		pThreadData,
-		THREADIMPL_FLAGS_ATTACHED);
+		THREADIMPL_FLAGS_ATTACHED,
+		-1);
+}
+
+oslThread
+osl_createThreadWithStack(
+		oslWorkerFunction pWorker,
+		void *            pThreadData,
+		sal_Int32         nFrames)
+{
+    return osl_thread_create_Impl (
+		pWorker,
+		pThreadData,
+		THREADIMPL_FLAGS_ATTACHED,
+		nFrames);
 }
 
 /*****************************************************************************/
@@ -358,7 +387,21 @@ oslThread osl_createSuspendedThread (
 		pWorker,
 		pThreadData,
 		THREADIMPL_FLAGS_ATTACHED |
-		THREADIMPL_FLAGS_SUSPENDED );
+		THREADIMPL_FLAGS_SUSPENDED,
+		-1);
+}
+
+oslThread osl_createSuspendedThreadWithStack (
+	oslWorkerFunction pWorker,
+	void *            pThreadData,
+	sal_Int32         nFrames)
+{
+    return osl_thread_create_Impl (
+		pWorker,
+		pThreadData,
+		THREADIMPL_FLAGS_ATTACHED |
+		THREADIMPL_FLAGS_SUSPENDED,
+		nFrames);
 }
 
 /*****************************************************************************/
--- sal/osl/w32/thread.c	2006-08-30 11:10:04.000000000 +0800
+++ sal/osl/w32/thread.c	2006-08-30 11:08:53.000000000 +0800
@@ -58,7 +58,7 @@ typedef struct _osl_TThreadImpl 
 #define THREADIMPL_FLAGS_TERMINATE	0x0001
 
 static unsigned __stdcall oslWorkerWrapperFunction(void* pData);
-static oslThread oslCreateThread(oslWorkerFunction pWorker, void* pThreadData, sal_uInt32 nFlags);
+static oslThread oslCreateThread(oslWorkerFunction pWorker, void* pThreadData, sal_uInt32 nFlags, sal_Int32 nFrames);
 static HRESULT WINAPI osl_CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit);
 
 typedef HRESULT (WINAPI *CoInitializeEx_PROC)(LPVOID pvReserved, DWORD dwCoInit);
@@ -90,10 +90,17 @@ static unsigned __stdcall oslWorkerWrapp
 /*****************************************************************************/
 static oslThread oslCreateThread(oslWorkerFunction pWorker,
                                  void* pThreadData,
-                                 sal_uInt32 nFlags)
+                                 sal_uInt32 nFlags,
+                                 sal_Int32 nFrames)
 {
+       SIZE_T stacksize;
 	osl_TThreadImpl* pThreadImpl;
 
+	if (nFrames < 0)
+		stacksize = 0;
+	else
+		stacksize = nFrames * 128;
+
 	/* alloc mem. for our internal data structure */
 	pThreadImpl= malloc(sizeof(osl_TThreadImpl));
 
@@ -110,7 +117,7 @@ static oslThread oslCreateThread(oslWork
 
 	pThreadImpl->m_hThread= 
 		(HANDLE)_beginthreadex(NULL,						/* no security */
-							   0,							/* default stack-size */
+						   stacksize,
 							   oslWorkerWrapperFunction,	/* worker-function */
 							   pThreadImpl,					/* provide worker-function with data */
 							   nFlags,						/* start thread immediately or suspended */
@@ -142,7 +149,17 @@ static HRESULT WINAPI osl_CoInitializeEx
 oslThread SAL_CALL osl_createThread(oslWorkerFunction pWorker,
                                     void* pThreadData)
 {
-    return oslCreateThread(pWorker, pThreadData, 0);
+    return oslCreateThread(pWorker, pThreadData, 0, -1);
+}
+
+/*****************************************************************************/
+/* osl_createThreadWithStack */
+/*****************************************************************************/
+oslThread SAL_CALL osl_createThreadWithStack(oslWorkerFunction pWorker,
+                                             void *pThreadData,
+                                             sal_Int32 nFrames)
+{
+    return oslCreateThread(pWorker, pThreadData, 0, nFrames);
 }
 
 /*****************************************************************************/
@@ -151,7 +168,17 @@ oslThread SAL_CALL osl_createThread(oslW
 oslThread SAL_CALL osl_createSuspendedThread(oslWorkerFunction pWorker,
                                              void* pThreadData) 
 {
-    return oslCreateThread(pWorker, pThreadData, CREATE_SUSPENDED);
+    return oslCreateThread(pWorker, pThreadData, CREATE_SUSPENDED, -1);
+}
+
+/*****************************************************************************/
+/* osl_createSuspendedThreadWithStack */
+/*****************************************************************************/
+oslThread SAL_CALL osl_createSuspendedThreadWithStack(oslWorkerFunction pWorker,
+                                             void* pThreadData, 
+                                             sal_Int32 nFrames)
+{
+    return oslCreateThread(pWorker, pThreadData, CREATE_SUSPENDED, nFrames);
 }
 
 /*****************************************************************************/
--- sal/inc/osl/thread.h	2006-08-30 10:16:29.000000000 +0800
+++ sal/inc/osl/thread.h	2006-08-30 11:08:53.000000000 +0800
@@ -87,6 +87,7 @@ typedef sal_uInt32 oslThreadKey;
 	@return 0 if creation failed, otherwise a handle to the thread
 */
 oslThread SAL_CALL osl_createThread(oslWorkerFunction pWorker, void* pThreadData);
+oslThread SAL_CALL osl_createThreadWithStack(oslWorkerFunction pWorker, void* pThreadData, sal_Int32 nFrames);
 
 /** Create the thread, using the function-ptr pWorker as
 	its main (worker) function. This functions receives in
@@ -96,6 +97,7 @@ oslThread SAL_CALL osl_createThread(oslW
 	@return 0 if creation failed, otherwise a handle to the thread
 */
 oslThread SAL_CALL osl_createSuspendedThread(oslWorkerFunction pWorker, void* pThreadData);
+oslThread SAL_CALL osl_createSuspendedThreadWithStack(oslWorkerFunction pWorker, void* pThreadData, sal_Int32 nFrames);
 
 /** Get the identifier for the specified thread or if parameter
     Thread is NULL of the current active thread.
--- desktop/source/app/officeipcthread.cxx	2006-08-30 10:16:29.000000000 +0800
+++ desktop/source/app/officeipcthread.cxx	2006-08-30 11:08:53.000000000 +0800
@@ -404,7 +404,7 @@ OfficeIPCThread::Status OfficeIPCThread:
 	{
 		// Seems we are the one and only, so start listening thread
 		pGlobalOfficeIPCThread = pThread;
-		pThread->create(); // starts thread
+		pThread->createWithStack( 1024 ); // starts thread
 	}
 	else
 	{
--- vcl/unx/source/app/sm.cxx	2006-08-30 10:17:13.000000000 +0800
+++ vcl/unx/source/app/sm.cxx	2006-08-30 11:08:53.000000000 +0800
@@ -723,7 +723,7 @@ void ICEConnectionObserver::ICEWatchProc
                     flags |= O_NONBLOCK;
                     fcntl (nWakeupFiles[1], F_SETFL, flags);
                 }
-                ICEThread = osl_createSuspendedThread( ICEConnectionWorker, NULL );
+                ICEThread = osl_createSuspendedThreadWithStack( ICEConnectionWorker, NULL, 1024 );
                 osl_resumeThread( ICEThread );
             }
         }
--- vos/inc/vos/thread.hxx	2006-08-30 10:16:29.000000000 +0800
+++ vos/inc/vos/thread.hxx	2006-08-30 11:08:53.000000000 +0800
@@ -119,11 +119,23 @@ public:
 	*/
 	sal_Bool SAL_CALL create();
 
+	/** Create running instance of a thread,
+		with a given stack size, or -1 for system default.
+		@returns True if thread could be created.
+	*/
+	sal_Bool SAL_CALL createWithStack(sal_Int32 nFrames);
+
 	/** Create suspended instance of a thread.
 		@returns True if thread could be created.
 	*/
 	sal_Bool SAL_CALL createSuspended();
 
+	/** Create suspended instance of a thread.
+		with a given stack size, or -1 for system default.
+		@returns True if thread could be created.
+	*/
+	sal_Bool SAL_CALL createSuspendedWithStack( sal_Int32 nFrames );
+
 	/// Suspend a runnng thread
 	void SAL_CALL suspend();
 
--- vos/source/thread.cxx	2006-08-30 10:16:29.000000000 +0800
+++ vos/source/thread.cxx	2006-08-30 11:08:53.000000000 +0800
@@ -84,26 +84,34 @@ OThread::~OThread() 
     osl_destroyCondition( m_aCondition );
 }
 
-sal_Bool OThread::create() 
+sal_Bool OThread::createWithStack(sal_Int32 nFrames)
 {
 	VOS_ASSERT(m_hThread == 0);	// only one running thread per instance
 
-    m_hThread = osl_createSuspendedThread(
-        threadWorkerFunction_impl, (void*)this);
-	if (m_hThread)
-		osl_resumeThread(m_hThread);							             
+    m_hThread = osl_createThreadWithStack(
+        threadWorkerFunction_impl, (void*)this, nFrames);
 
 	return m_hThread != 0;
 }
 
-sal_Bool OThread::createSuspended() 
+sal_Bool OThread::create() 
+{
+	return createWithStack(-1);
+}
+
+sal_Bool OThread::createSuspendedWithStack( sal_Int32 nFrames ) 
 {
 	VOS_ASSERT(m_hThread == 0);	// only one running thread per instance
 
-	m_hThread= osl_createSuspendedThread(threadWorkerFunction_impl, (void*)this);
+	m_hThread= osl_createSuspendedThreadWithStack(threadWorkerFunction_impl, (void*)this, nFrames);
 	return m_hThread != 0;
 }
 
+sal_Bool OThread::createSuspended() 
+{
+	return createSuspendedWithStack( -1 );
+}
+
 void OThread::suspend() 
 {
 	VOS_ASSERT(m_hThread != 0);	// use only on running thread
--- dtrans/source/X11/X11_selection.cxx	2006-08-30 10:16:29.000000000 +0800
+++ dtrans/source/X11/X11_selection.cxx	2006-08-30 11:08:53.000000000 +0800
@@ -464,9 +464,9 @@ void SelectionManager::initialize( const
 				m_xDropTransferable = new X11Transferable( *this, static_cast< OWeakObject* >(this), m_nXdndSelection );
 				registerHandler( m_nXdndSelection, *this );
 
-				m_aThread = osl_createSuspendedThread( call_SelectionManager_run, this );
-    			if( m_aThread )
-        			osl_resumeThread( m_aThread );
+               m_aThread = osl_createSuspendedThreadWithStack( call_SelectionManager_run, this,1024 );
+               if( m_aThread )
+                   osl_resumeThread( m_aThread );
 #if OSL_DEBUG_LEVEL > 1
 				else
 					fprintf( stderr, "SelectionManager::initialize: creation of dispatch thread failed !\n" );
--- sal/rtl/source/alloc_cache.c	2006-08-30 10:16:29.000000000 +0800
+++ sal/rtl/source/alloc_cache.c	2006-08-30 11:08:53.000000000 +0800
@@ -1376,11 +1376,26 @@ rtl_cache_wsupdate_all (void * arg);
 static void
 rtl_cache_wsupdate_init (void)
 {
+	pthread_attr_t attr;
+
 	RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock));
 	g_cache_list.m_update_done = 0;
 	(void) pthread_cond_init (&(g_cache_list.m_update_cond), NULL);
+
+	pthread_attr_init (&attr);
+#if defined (LINUX) || defined (SOLARIS)
+	{
+		const size_t nBytes = 64 * 1024;
+		size_t stack_size = sysconf (_SC_THREAD_STACK_MIN);
+		if (nBytes > stack_size)
+			stack_size = nBytes;
+//		if (!getenv ("DISABLE_SIZE"))
+			pthread_attr_setstacksize (&attr, stack_size);
+//		fprintf (stderr, "Sal set size to %d\n", stack_size);
+	}
+#endif
 	if (pthread_create (
-			&(g_cache_list.m_update_thread), NULL, rtl_cache_wsupdate_all, (void*)(10)) != 0)
+			&(g_cache_list.m_update_thread), &attr, rtl_cache_wsupdate_all, (void*)(10)) != 0)
 	{
 		/* failure */
 		g_cache_list.m_update_thread = (pthread_t)(0);
--- sal/util/sal.map	2006-08-30 10:16:29.000000000 +0800
+++ sal/util/sal.map	2006-08-30 11:08:53.000000000 +0800
@@ -32,8 +32,10 @@ UDK_3_0_0 {
         osl_createSocket;
         osl_createSocketSet;
         osl_createSuspendedThread;
+        osl_createSuspendedThreadWithStack;
         osl_createThread;
         osl_createThreadKey;
+        osl_createThreadWithStack;
         osl_decrementInterlockedCount;
         osl_demultiplexSocketEvents;
         osl_destroyCondition;
