From 752b16ce359bb46948b8aa2bc88f7c32bf2cc95b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 7 Mar 2008 11:24:51 +0000 Subject: * Makefile.in (DLL_OFILES): Add tls_pbuf.o. * autoload.cc (CreateDesktopW): Replace CreateDesktopA. (CreateWindowStationW): Replace CreateWindowStationA. (GetUserObjectInformationW): Replace GetUserObjectInformationA. * cygheap.h (cwdstuff::get): Assume default buffer size NT_MAX_PATH. * cygtls.cc (_cygtls::remove): Free temporary TLS path buffers. * cygtls.h (TP_NUM_C_BUFS): Define. (TP_NUM_W_BUFS): Define. (class tls_pathbuf): New class to store pointers to thread local temporary path buffers. (_local_storage::pathbufs): New member. * environ.cc (win_env::add_cache): Use temporary TLS path buffer instead of stack based buffer. (posify): Get temporary outenv buffer from calling function. (environ_init): Create temporary TLS path buffer for posify. (build_env): Create Windows environment block as WCHAR buffer. * environ.h (build_env): Change declaration accordingly. * external.cc (sync_winenv): Accommodate build_env change. * fhandler_console.cc (fhandler_console::need_invisible): Use GetUserObjectInformationW and CreateWindowStationW. * fhandler_process.cc (format_process_maps): Use temporary TLS path buffer instead of stack based buffer. * fork.cc (frok::parent): Convert to use CreateProcessW. * path.cc: Throughout use temporary TLS path buffers instead of stack based buffer. Replace checks for CYG_MAX_PATH by checks for NT_MAX_PATH. (getfileattr): New function to replace GetFileAttributesA. (normalize_win32_path): Remove Win32 and NT long path prefixes. (getwd): Assume PATH_MAX + 1 buffer per SUSv3. * path.h (class path_conv): Set path buffer to size NT_MAX_PATH. (iswdrive): Define. * pinfo.cc (commune_process): Use temporary TLS path buffer instead of stack based buffer. * registry.cc (get_registry_hive_path): Ditto. (load_registry_hive): Ditto. * spawn.cc (spawn_guts): Convert to use CreateProcessW and CreateProcessAsUserW. (av::fixup): Open/close file using NtOpenFile/NtClose. * syscalls.cc (mknod_worker): Allow PATH_MAX file name. (mknod32): Ditto. (getusershell): Ditto. * tls_pbuf.cc: New file implementing tls_pathbuf and tmp_pathbuf methods. * tls_pbuf.h: New header for files using tmp_pathbuf. * tlsoffsets.h: Regenerate. * winsup.h (NT_MAX_PATH): Define as 32767 to avoid USHORT overflow. --- winsup/cygwin/tls_pbuf.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 winsup/cygwin/tls_pbuf.cc (limited to 'winsup/cygwin/tls_pbuf.cc') diff --git a/winsup/cygwin/tls_pbuf.cc b/winsup/cygwin/tls_pbuf.cc new file mode 100644 index 000000000..704f3bfc9 --- /dev/null +++ b/winsup/cygwin/tls_pbuf.cc @@ -0,0 +1,60 @@ +/* tls_pbuf.cc + + Copyright 2008 Red Hat, Inc. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#include +#include +#include "thread.h" +#include "cygtls.h" +#include "tls_pbuf.h" + +#define tls_pbuf _my_tls.locals.pathbufs + +void +tls_pathbuf::destroy () +{ + for (int i = 0; i < TP_NUM_C_BUFS; ++i) + if (c_buf[i]) + free (c_buf[i]); + for (int i = 0; i < TP_NUM_W_BUFS; ++i) + if (w_buf[i]) + free (w_buf[i]); +} + +tmp_pathbuf::tmp_pathbuf () +: c_buf_old (tls_pbuf.c_cnt), + w_buf_old (tls_pbuf.w_cnt) +{} + +tmp_pathbuf::~tmp_pathbuf () +{ + tls_pbuf.c_cnt = c_buf_old; + tls_pbuf.w_cnt = w_buf_old; +} + +char * +tmp_pathbuf::c_get () +{ + if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS) + api_fatal ("Internal error: TP_NUM_C_BUFS too small."); + if (!tls_pbuf.c_buf[tls_pbuf.c_cnt] + && !(tls_pbuf.c_buf[tls_pbuf.c_cnt] = (char *) malloc (NT_MAX_PATH))) + api_fatal ("Internal error: Out of memory for new path buf."); + return tls_pbuf.c_buf[tls_pbuf.c_cnt++]; +} + +PWCHAR +tmp_pathbuf::w_get () +{ + if (tls_pbuf.w_cnt >= TP_NUM_W_BUFS) + api_fatal ("Internal error: TP_NUM_W_BUFS too small."); + if (!tls_pbuf.w_buf[tls_pbuf.w_cnt] + && !(tls_pbuf.w_buf[tls_pbuf.w_cnt] + = (PWCHAR) malloc (NT_MAX_PATH * sizeof (WCHAR)))) + api_fatal ("Internal error: Out of memory for new wide path buf."); + return tls_pbuf.w_buf[tls_pbuf.w_cnt++]; +} -- cgit v1.2.3