diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index f24a4149862..c03840ef6ab 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -1,4 +1,4 @@ -EXTRADEFS = -D_KERNEL32_ -DBINDIR="\"$(bindir)\"" +EXTRADEFS = -D_KERNEL32_ -DBINDIR="\"$(bindir)\"" -DETCDIR="\"$(sysconfdir)\"" TOPSRCDIR = @top_srcdir@ TOPOBJDIR = ../.. SRCDIR = @srcdir@ @@ -20,7 +20,23 @@ SPEC_SRCS16 = \ windebug.spec C_SRCS = \ + $(TOPOBJDIR)/files/directory.c \ + $(TOPOBJDIR)/files/dos_fs.c \ + $(TOPOBJDIR)/files/drive.c \ + $(TOPOBJDIR)/files/file.c \ + $(TOPOBJDIR)/files/smb.c \ + $(TOPOBJDIR)/loader/module.c \ + $(TOPOBJDIR)/memory/codepage.c \ + $(TOPOBJDIR)/memory/environ.c \ + $(TOPOBJDIR)/memory/virtual.c \ + $(TOPOBJDIR)/misc/cpu.c \ + $(TOPOBJDIR)/misc/options.c \ + $(TOPOBJDIR)/misc/registry.c \ + $(TOPOBJDIR)/msdos/dpmi.c \ $(TOPOBJDIR)/msdos/int21.c \ + $(TOPOBJDIR)/scheduler/handle.c \ + $(TOPOBJDIR)/win32/device.c \ + $(TOPOBJDIR)/win32/newfns.c \ atom.c \ change.c \ comm.c \ @@ -86,7 +102,16 @@ MC_SRCS = \ EXTRA_OBJS = $(ASM_SRCS:.s=.o) SUBDIRS = tests -EXTRASUBDIRS = messages nls +EXTRASUBDIRS = \ + $(TOPOBJDIR)/files \ + $(TOPOBJDIR)/loader \ + $(TOPOBJDIR)/memory \ + $(TOPOBJDIR)/misc \ + $(TOPOBJDIR)/msdos \ + $(TOPOBJDIR)/scheduler \ + $(TOPOBJDIR)/win32 \ + messages \ + nls @MAKE_DLL_RULES@ diff --git a/dlls/kernel/global16.c b/dlls/kernel/global16.c index 4c106f797ae..a21c7c2f061 100644 --- a/dlls/kernel/global16.c +++ b/dlls/kernel/global16.c @@ -70,8 +70,8 @@ typedef struct #define GA_DOSMEM 0x20 /* Arena array (FIXME) */ -extern GLOBALARENA *pGlobalArena; -extern int globalArenaSize; +static GLOBALARENA *pGlobalArena; +static int globalArenaSize; #define GLOBAL_MAX_ALLOC_SIZE 0x00ff0000 /* Largest allocation is 16M - 64K */ diff --git a/dlls/kernel/heap.c b/dlls/kernel/heap.c index 9675e77c6b8..21072102c93 100644 --- a/dlls/kernel/heap.c +++ b/dlls/kernel/heap.c @@ -46,6 +46,7 @@ #include "winreg.h" #include "winternl.h" #include "excpt.h" +#include "thread.h" #include "wine/exception.h" #include "wine/debug.h" @@ -222,6 +223,45 @@ BOOL WINAPI HeapWalk( } +/*********************************************************************** + * HeapLock (KERNEL32.@) + * Attempts to acquire the critical section object for a specified heap. + * + * RETURNS + * TRUE: Success + * FALSE: Failure + */ +BOOL WINAPI HeapLock( + HANDLE heap /* [in] Handle of heap to lock for exclusive access */ +) { + return RtlLockHeap( heap ); +} + + +/*********************************************************************** + * HeapUnlock (KERNEL32.@) + * Releases ownership of the critical section object. + * + * RETURNS + * TRUE: Success + * FALSE: Failure + */ +BOOL WINAPI HeapUnlock( + HANDLE heap /* [in] Handle to the heap to unlock */ +) { + return RtlUnlockHeap( heap ); +} + + +/*********************************************************************** + * GetProcessHeap (KERNEL32.@) + */ +HANDLE WINAPI GetProcessHeap(void) +{ + return NtCurrentTeb()->Peb->ProcessHeap; +} + + /*********************************************************************** * GetProcessHeaps (KERNEL32.@) */ @@ -231,6 +271,28 @@ DWORD WINAPI GetProcessHeaps( DWORD count, HANDLE *heaps ) } +/* These are needed so that we can call the functions from inside kernel itself */ + +LPVOID WINAPI HeapAlloc( HANDLE heap, DWORD flags, SIZE_T size ) +{ + return RtlAllocateHeap( heap, flags, size ); +} + +BOOL WINAPI HeapFree( HANDLE heap, DWORD flags, LPVOID ptr ) +{ + return RtlFreeHeap( heap, flags, ptr ); +} + +LPVOID WINAPI HeapReAlloc( HANDLE heap, DWORD flags, LPVOID ptr, SIZE_T size ) +{ + return RtlReAllocateHeap( heap, flags, ptr, size ); +} + +SIZE_T WINAPI HeapSize( HANDLE heap, DWORD flags, LPVOID ptr ) +{ + return RtlSizeHeap( heap, flags, ptr ); +} + /* * Win32 Global heap functions (GlobalXXX). * These functions included in Win32 for compatibility with 16 bit Windows diff --git a/dlls/kernel/ne_module.c b/dlls/kernel/ne_module.c index 459bfb4bf4a..151dc15a763 100644 --- a/dlls/kernel/ne_module.c +++ b/dlls/kernel/ne_module.c @@ -213,6 +213,15 @@ void __wine_unregister_dll_16( const BUILTIN16_DESCRIPTOR *descr ) } +/*********************************************************************** + * NE_GetPtr + */ +NE_MODULE *NE_GetPtr( HMODULE16 hModule ) +{ + return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) ); +} + + /********************************************************************** * NE_RegisterModule */ @@ -1717,6 +1726,32 @@ BOOL16 WINAPI GetModuleName16( HINSTANCE16 hinst, LPSTR buf, INT16 count ) } +/********************************************************************** + * GetModuleFileName (KERNEL.49) + * + * Comment: see GetModuleFileNameA + * + * Even if invoked by second instance of a program, + * it still returns path of first one. + */ +INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName, + INT16 nSize ) +{ + NE_MODULE *pModule; + + /* Win95 does not query hModule if set to 0 ! + * Is this wrong or maybe Win3.1 only ? */ + if (!hModule) hModule = GetCurrentTask(); + + if (!(pModule = NE_GetPtr( hModule ))) return 0; + lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize ); + if (pModule->expected_version >= 0x400) + GetLongPathNameA(NE_MODULE_NAME(pModule), lpFileName, nSize); + TRACE("%04x -> '%s'\n", hModule, lpFileName ); + return strlen(lpFileName); +} + + /********************************************************************** * GetModuleUsage (KERNEL.48) */ diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index dc52e3672a1..f5074abd7a0 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -106,7 +106,7 @@ static DWORD shutdown_priority = 0x280; static DWORD process_dword; static BOOL oem_file_apis; -extern unsigned int server_startticks; +static unsigned int server_startticks; int main_create_flags = 0; /* Process flags */ @@ -1735,6 +1735,24 @@ BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code ) } +/*********************************************************************** + * ExitProcess (KERNEL32.@) + */ +void WINAPI ExitProcess( DWORD status ) +{ + LdrShutdownProcess(); + SERVER_START_REQ( terminate_process ) + { + /* send the exit code to the server */ + req->handle = GetCurrentProcess(); + req->exit_code = status; + wine_server_call( req ); + } + SERVER_END_REQ; + exit( status ); +} + + /*********************************************************************** * GetExitCodeProcess [KERNEL32.@] * @@ -2342,6 +2360,20 @@ BOOL WINAPI AreFileApisANSI(void) } +/*********************************************************************** + * GetTickCount (KERNEL32.@) + * + * Returns the number of milliseconds, modulo 2^32, since the start + * of the wineserver. + */ +DWORD WINAPI GetTickCount(void) +{ + struct timeval t; + gettimeofday( &t, NULL ); + return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks; +} + + /*********************************************************************** * GetCurrentProcess (KERNEL32.@) */ diff --git a/dlls/kernel/string.c b/dlls/kernel/string.c index f2fe97e5785..71aef12fdba 100644 --- a/dlls/kernel/string.c +++ b/dlls/kernel/string.c @@ -279,6 +279,75 @@ SEGPTR WINAPI lstrcpyn16( SEGPTR dst, LPCSTR src, INT16 n ) } +/*********************************************************************** + * lstrcpyn (KERNEL32.@) + * lstrcpynA (KERNEL32.@) + * + * Note: this function differs from the UNIX strncpy, it _always_ writes + * a terminating \0. + * + * Note: n is an INT but Windows treats it as unsigned, and will happily + * copy a gazillion chars if n is negative. + */ +LPSTR WINAPI lstrcpynA( LPSTR dst, LPCSTR src, INT n ) +{ + __TRY + { + LPSTR d = dst; + LPCSTR s = src; + UINT count = n; + + while ((count > 1) && *s) + { + count--; + *d++ = *s++; + } + if (count) *d = 0; + } + __EXCEPT(page_fault) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + __ENDTRY + return dst; +} + + +/*********************************************************************** + * lstrcpynW (KERNEL32.@) + * + * Note: this function differs from the UNIX strncpy, it _always_ writes + * a terminating \0 + * + * Note: n is an INT but Windows treats it as unsigned, and will happily + * copy a gazillion chars if n is negative. + */ +LPWSTR WINAPI lstrcpynW( LPWSTR dst, LPCWSTR src, INT n ) +{ + __TRY + { + LPWSTR d = dst; + LPCWSTR s = src; + UINT count = n; + + while ((count > 1) && *s) + { + count--; + *d++ = *s++; + } + if (count) *d = 0; + } + __EXCEPT(page_fault) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + __ENDTRY + return dst; +} + + /*********************************************************************** * lstrlen (KERNEL.90) */ diff --git a/dlls/kernel/task.c b/dlls/kernel/task.c index 2fb01f34b2f..ad9fa2b7016 100644 --- a/dlls/kernel/task.c +++ b/dlls/kernel/task.c @@ -61,6 +61,7 @@ WINE_DECLARE_DEBUG_CHANNEL(toolhelp); #define MIN_THUNKS 32 static THHOOK DefaultThhook; +THHOOK *pThhook = &DefaultThhook; #define hFirstTask (pThhook->HeadTDB) #define hLockedTask (pThhook->LockTDB) diff --git a/dlls/kernel/thread.c b/dlls/kernel/thread.c index c1f19a3b442..fe1b7554c72 100644 --- a/dlls/kernel/thread.c +++ b/dlls/kernel/thread.c @@ -694,3 +694,86 @@ HANDLE WINAPI GetCurrentThread(void) { return (HANDLE)0xfffffffe; } + + +#ifdef __i386__ + +/*********************************************************************** + * SetLastError (KERNEL.147) + * SetLastError (KERNEL32.@) + */ +/* void WINAPI SetLastError( DWORD error ); */ +__ASM_GLOBAL_FUNC( SetLastError, + "movl 4(%esp),%eax\n\t" + ".byte 0x64\n\t" + "movl %eax,0x60\n\t" + "ret $4" ); + +/*********************************************************************** + * GetLastError (KERNEL.148) + * GetLastError (KERNEL32.@) + */ +/* DWORD WINAPI GetLastError(void); */ +__ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" ); + +/*********************************************************************** + * GetCurrentProcessId (KERNEL.471) + * GetCurrentProcessId (KERNEL32.@) + */ +/* DWORD WINAPI GetCurrentProcessId(void) */ +__ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" ); + +/*********************************************************************** + * GetCurrentThreadId (KERNEL.462) + * GetCurrentThreadId (KERNEL32.@) + */ +/* DWORD WINAPI GetCurrentThreadId(void) */ +__ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" ); + +#else /* __i386__ */ + +/********************************************************************** + * SetLastError (KERNEL.147) + * SetLastError (KERNEL32.@) + * + * Sets the last-error code. + */ +void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */ +{ + NtCurrentTeb()->last_error = error; +} + +/********************************************************************** + * GetLastError (KERNEL.148) + * GetLastError (KERNEL32.@) + * + * Returns last-error code. + */ +DWORD WINAPI GetLastError(void) +{ + return NtCurrentTeb()->last_error; +} + +/*********************************************************************** + * GetCurrentProcessId (KERNEL.471) + * GetCurrentProcessId (KERNEL32.@) + * + * Returns process identifier. + */ +DWORD WINAPI GetCurrentProcessId(void) +{ + return (DWORD)NtCurrentTeb()->ClientId.UniqueProcess; +} + +/*********************************************************************** + * GetCurrentThreadId (KERNEL.462) + * GetCurrentThreadId (KERNEL32.@) + * + * Returns thread identifier. + */ +DWORD WINAPI GetCurrentThreadId(void) +{ + return (DWORD)NtCurrentTeb()->ClientId.UniqueThread; +} + +#endif /* __i386__ */ diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index c2e39ef971f..59ff4174a5d 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -1,4 +1,4 @@ -EXTRADEFS = -D_NTSYSTEM_ -DBINDIR="\"$(bindir)\"" -DETCDIR="\"$(sysconfdir)\"" +EXTRADEFS = -D_NTSYSTEM_ -DBINDIR="\"$(bindir)\"" TOPSRCDIR = @top_srcdir@ TOPOBJDIR = ../.. SRCDIR = @srcdir@ @@ -7,30 +7,7 @@ MODULE = ntdll.dll EXTRALIBS = $(LIBUNICODE) @LIBPTHREAD@ C_SRCS = \ - $(TOPOBJDIR)/files/directory.c \ - $(TOPOBJDIR)/files/dos_fs.c \ - $(TOPOBJDIR)/files/drive.c \ - $(TOPOBJDIR)/files/file.c \ - $(TOPOBJDIR)/files/smb.c \ - $(TOPOBJDIR)/loader/module.c \ - $(TOPOBJDIR)/loader/task.c \ - $(TOPOBJDIR)/loader/ne/module.c \ - $(TOPOBJDIR)/memory/codepage.c \ - $(TOPOBJDIR)/memory/environ.c \ - $(TOPOBJDIR)/memory/global.c \ - $(TOPOBJDIR)/memory/heap.c \ - $(TOPOBJDIR)/memory/string.c \ - $(TOPOBJDIR)/memory/virtual.c \ - $(TOPOBJDIR)/misc/cpu.c \ - $(TOPOBJDIR)/misc/options.c \ - $(TOPOBJDIR)/misc/registry.c \ - $(TOPOBJDIR)/msdos/dpmi.c \ - $(TOPOBJDIR)/scheduler/handle.c \ - $(TOPOBJDIR)/scheduler/process.c \ $(TOPOBJDIR)/scheduler/pthread.c \ - $(TOPOBJDIR)/scheduler/thread.c \ - $(TOPOBJDIR)/win32/device.c \ - $(TOPOBJDIR)/win32/newfns.c \ cdrom.c \ critsection.c \ debugtools.c \ @@ -73,16 +50,6 @@ EXTRA_OBJS = $(ASM_SRCS:.s=.o) SUBDIRS = tests -EXTRASUBDIRS = \ - $(TOPOBJDIR)/files \ - $(TOPOBJDIR)/loader \ - $(TOPOBJDIR)/loader/ne \ - $(TOPOBJDIR)/memory \ - $(TOPOBJDIR)/misc \ - $(TOPOBJDIR)/msdos \ - $(TOPOBJDIR)/scheduler \ - $(TOPOBJDIR)/win32 - @MAKE_DLL_RULES@ relay32.s: $(WINEBUILD) diff --git a/loader/ne/module.c b/loader/ne/module.c deleted file mode 100644 index 2b7556e0496..00000000000 --- a/loader/ne/module.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * NE modules - * - * Copyright 1995 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif -#include - -#include "windef.h" -#include "winbase.h" -#include "wine/winbase16.h" -#include "wine/library.h" -#include "winerror.h" -#include "module.h" -#include "toolhelp.h" -#include "file.h" -#include "task.h" -#include "builtin16.h" -#include "stackframe.h" -#include "excpt.h" -#include "wine/exception.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(module); -WINE_DECLARE_DEBUG_CHANNEL(loaddll); - -#define hFirstModule (pThhook->hExeHead) - - -/*********************************************************************** - * NE_GetPtr - */ -NE_MODULE *NE_GetPtr( HMODULE16 hModule ) -{ - return (NE_MODULE *)GlobalLock16( GetExePtr(hModule) ); -} - - -/********************************************************************** - * GetModuleFileName (KERNEL.49) - * - * Comment: see GetModuleFileNameA - * - * Even if invoked by second instance of a program, - * it still returns path of first one. - */ -INT16 WINAPI GetModuleFileName16( HINSTANCE16 hModule, LPSTR lpFileName, - INT16 nSize ) -{ - NE_MODULE *pModule; - - /* Win95 does not query hModule if set to 0 ! - * Is this wrong or maybe Win3.1 only ? */ - if (!hModule) hModule = GetCurrentTask(); - - if (!(pModule = NE_GetPtr( hModule ))) return 0; - lstrcpynA( lpFileName, NE_MODULE_NAME(pModule), nSize ); - if (pModule->expected_version >= 0x400) - GetLongPathNameA(NE_MODULE_NAME(pModule), lpFileName, nSize); - TRACE("%04x -> '%s'\n", hModule, lpFileName ); - return strlen(lpFileName); -} diff --git a/loader/task.c b/loader/task.c deleted file mode 100644 index c457039edc8..00000000000 --- a/loader/task.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Task functions - * - * Copyright 1995 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winnt.h" -#include "winuser.h" - -#include "wine/winbase16.h" -#include "drive.h" -#include "file.h" -#include "global.h" -#include "instance.h" -#include "module.h" -#include "winternl.h" -#include "selectors.h" -#include "wine/server.h" -#include "stackframe.h" -#include "task.h" -#include "thread.h" -#include "toolhelp.h" - -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(task); - -static THHOOK DefaultThhook; -THHOOK *pThhook = &DefaultThhook; - -#define hFirstTask (pThhook->HeadTDB) - -/*********************************************************************** - * TASK_GetPtr - */ -static TDB *TASK_GetPtr( HTASK16 hTask ) -{ - return GlobalLock16( hTask ); -} - - -/*********************************************************************** - * GetCurrentTask (KERNEL32.@) - */ -HTASK16 WINAPI GetCurrentTask(void) -{ - return NtCurrentTeb()->htask16; -} - -/*********************************************************************** - * GetExePtrHelper - */ -static inline HMODULE16 GetExePtrHelper( HANDLE16 handle, HTASK16 *hTask ) -{ - char *ptr; - HANDLE16 owner; - - /* Check for module handle */ - - if (!(ptr = GlobalLock16( handle ))) return 0; - if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return handle; - - /* Search for this handle inside all tasks */ - - *hTask = hFirstTask; - while (*hTask) - { - TDB *pTask = TASK_GetPtr( *hTask ); - if ((*hTask == handle) || - (pTask->hInstance == handle) || - (pTask->hQueue == handle) || - (pTask->hPDB == handle)) return pTask->hModule; - *hTask = pTask->hNext; - } - - /* Check the owner for module handle */ - - owner = FarGetOwner16( handle ); - if (!(ptr = GlobalLock16( owner ))) return 0; - if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return owner; - - /* Search for the owner inside all tasks */ - - *hTask = hFirstTask; - while (*hTask) - { - TDB *pTask = TASK_GetPtr( *hTask ); - if ((*hTask == owner) || - (pTask->hInstance == owner) || - (pTask->hQueue == owner) || - (pTask->hPDB == owner)) return pTask->hModule; - *hTask = pTask->hNext; - } - - return 0; -} - -/*********************************************************************** - * K228 (KERNEL.228) - */ -HMODULE16 WINAPI GetExePtr( HANDLE16 handle ) -{ - HTASK16 hTask = 0; - return GetExePtrHelper( handle, &hTask ); -} diff --git a/memory/global.c b/memory/global.c deleted file mode 100644 index 7d2a95e15ea..00000000000 --- a/memory/global.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Global heap functions - * - * Copyright 1995 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* 0xffff sometimes seems to mean: CURRENT_DS */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif -#include -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#ifdef HAVE_SYS_SYSCTL_H -#include -#endif - -#include "wine/winbase16.h" -#include "ntstatus.h" -#include "global.h" -#include "toolhelp.h" -#include "selectors.h" -#include "miscemu.h" -#include "stackframe.h" -#include "wine/debug.h" -#include "winerror.h" - -WINE_DEFAULT_DEBUG_CHANNEL(global); - - /* Global arena block */ -typedef struct -{ - DWORD base; /* Base address (0 if discarded) */ - DWORD size; /* Size in bytes (0 indicates a free block) */ - HGLOBAL16 handle; /* Handle for this block */ - HGLOBAL16 hOwner; /* Owner of this block */ - BYTE lockCount; /* Count of GlobalFix() calls */ - BYTE pageLockCount; /* Count of GlobalPageLock() calls */ - BYTE flags; /* Allocation flags */ - BYTE selCount; /* Number of selectors allocated for this block */ -} GLOBALARENA; - - /* Arena array */ -/*static*/ GLOBALARENA *pGlobalArena = NULL; -/*static*/ int globalArenaSize = 0; - -#define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)> __AHSHIFT)) - - -/*********************************************************************** - * GlobalLock16 (KERNEL32.25) - * - * This is the GlobalLock16() function used by 32-bit code. - * - * RETURNS - * Pointer to first byte of memory block - * NULL: Failure - */ -LPVOID WINAPI GlobalLock16( - HGLOBAL16 handle /* [in] Handle of global memory object */ -) { - if (!handle) return 0; - if (!VALID_HANDLE(handle)) - return 0; - GET_ARENA_PTR(handle)->lockCount++; - return (LPVOID)GET_ARENA_PTR(handle)->base; -} - - -/*********************************************************************** - * FarGetOwner (KERNEL.404) - */ -HANDLE16 WINAPI FarGetOwner16( HGLOBAL16 handle ) -{ - if (!VALID_HANDLE(handle)) { - WARN("Invalid handle 0x%04x passed to FarGetOwner!\n",handle); - return 0; - } - return GET_ARENA_PTR(handle)->hOwner; -} diff --git a/memory/heap.c b/memory/heap.c deleted file mode 100644 index 4e71b1322ba..00000000000 --- a/memory/heap.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Win32 heap functions - * - * Copyright 1996 Alexandre Julliard - * Copyright 1998 Ulrich Weigand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "winnt.h" -#include "winreg.h" -#include "winternl.h" -#include "wine/unicode.h" -#include "thread.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(heap); - -/*********************************************************************** - * HeapLock (KERNEL32.@) - * Attempts to acquire the critical section object for a specified heap. - * - * RETURNS - * TRUE: Success - * FALSE: Failure - */ -BOOL WINAPI HeapLock( - HANDLE heap /* [in] Handle of heap to lock for exclusive access */ -) { - return RtlLockHeap( heap ); -} - - -/*********************************************************************** - * HeapUnlock (KERNEL32.@) - * Releases ownership of the critical section object. - * - * RETURNS - * TRUE: Success - * FALSE: Failure - */ -BOOL WINAPI HeapUnlock( - HANDLE heap /* [in] Handle to the heap to unlock */ -) { - return RtlUnlockHeap( heap ); -} - - -/*********************************************************************** - * GetProcessHeap (KERNEL32.@) - */ -HANDLE WINAPI GetProcessHeap(void) -{ - return NtCurrentTeb()->Peb->ProcessHeap; -} - - -/* FIXME: these functions are needed for dlls that aren't properly separated yet */ - -LPVOID WINAPI HeapAlloc( HANDLE heap, DWORD flags, SIZE_T size ) -{ - return RtlAllocateHeap( heap, flags, size ); -} - -BOOL WINAPI HeapFree( HANDLE heap, DWORD flags, LPVOID ptr ) -{ - return RtlFreeHeap( heap, flags, ptr ); -} - -LPVOID WINAPI HeapReAlloc( HANDLE heap, DWORD flags, LPVOID ptr, SIZE_T size ) -{ - return RtlReAllocateHeap( heap, flags, ptr, size ); -} - -SIZE_T WINAPI HeapSize( HANDLE heap, DWORD flags, LPVOID ptr ) -{ - return RtlSizeHeap( heap, flags, ptr ); -} diff --git a/memory/string.c b/memory/string.c deleted file mode 100644 index 7102e604d72..00000000000 --- a/memory/string.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * String functions - * - * Copyright 1993 Yngvi Sigurjonsson - * Copyright 1996 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include - -#include "ntstatus.h" -#include "windef.h" -#include "winbase.h" -#include "wine/winbase16.h" -#include "wine/exception.h" -#include "wine/unicode.h" -#include "winerror.h" -#include "winnls.h" -#include "excpt.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(string); - -/*********************************************************************** - * lstrcpyn (KERNEL32.@) - * lstrcpynA (KERNEL32.@) - * - * Note: this function differs from the UNIX strncpy, it _always_ writes - * a terminating \0. - * - * Note: n is an INT but Windows treats it as unsigned, and will happily - * copy a gazillion chars if n is negative. - */ -LPSTR WINAPI lstrcpynA( LPSTR dst, LPCSTR src, INT n ) -{ - LPSTR p = dst; - UINT count = n; - - TRACE("(%p, %s, %i)\n", dst, debugstr_a(src), n); - - /* In real windows the whole function is protected by an exception handler - * that returns ERROR_INVALID_PARAMETER on faulty parameters - * We currently just check for NULL. - */ - if (!dst || !src) { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - while ((count > 1) && *src) - { - count--; - *p++ = *src++; - } - if (count) *p = 0; - return dst; -} - - -/*********************************************************************** - * lstrcpynW (KERNEL32.@) - * - * Note: this function differs from the UNIX strncpy, it _always_ writes - * a terminating \0 - * - * Note: n is an INT but Windows treats it as unsigned, and will happily - * copy a gazillion chars if n is negative. - */ -LPWSTR WINAPI lstrcpynW( LPWSTR dst, LPCWSTR src, INT n ) -{ - LPWSTR p = dst; - UINT count = n; - - TRACE("(%p, %s, %i)\n", dst, debugstr_w(src), n); - - /* In real windows the whole function is protected by an exception handler - * that returns ERROR_INVALID_PARAMETER on faulty parameters - * We currently just check for NULL. - */ - if (!dst || !src) { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - while ((count > 1) && *src) - { - count--; - *p++ = *src++; - } - if (count) *p = 0; - return dst; -} diff --git a/scheduler/process.c b/scheduler/process.c deleted file mode 100644 index 1ff115cb56b..00000000000 --- a/scheduler/process.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Win32 processes - * - * Copyright 1996, 1998 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif -#include "wine/library.h" -#include "file.h" -#include "wine/server.h" - -unsigned int server_startticks; - -/*********************************************************************** - * ExitProcess (KERNEL32.@) - */ -void WINAPI ExitProcess( DWORD status ) -{ - LdrShutdownProcess(); - SERVER_START_REQ( terminate_process ) - { - /* send the exit code to the server */ - req->handle = GetCurrentProcess(); - req->exit_code = status; - wine_server_call( req ); - } - SERVER_END_REQ; - exit( status ); -} - - -/*********************************************************************** - * GetTickCount (KERNEL32.@) - * - * Returns the number of milliseconds, modulo 2^32, since the start - * of the wineserver. - */ -DWORD WINAPI GetTickCount(void) -{ - struct timeval t; - gettimeofday( &t, NULL ); - return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks; -} diff --git a/scheduler/thread.c b/scheduler/thread.c deleted file mode 100644 index c874e33bcfd..00000000000 --- a/scheduler/thread.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Win32 threads - * - * Copyright 1996 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include -#ifdef HAVE_SYS_MMAN_H -#include -#endif -#ifdef HAVE_SYS_TIMES_H -#include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif -#include "wine/winbase16.h" -#include "ntstatus.h" -#include "thread.h" -#include "winerror.h" -#include "winnt.h" -#include "wine/server.h" -#include "wine/debug.h" -#include "winnls.h" - -WINE_DEFAULT_DEBUG_CHANNEL(thread); - - -#ifdef __i386__ - -/*********************************************************************** - * SetLastError (KERNEL.147) - * SetLastError (KERNEL32.@) - */ -/* void WINAPI SetLastError( DWORD error ); */ -__ASM_GLOBAL_FUNC( SetLastError, - "movl 4(%esp),%eax\n\t" - ".byte 0x64\n\t" - "movl %eax,0x60\n\t" - "ret $4" ); - -/*********************************************************************** - * GetLastError (KERNEL.148) - * GetLastError (KERNEL32.@) - */ -/* DWORD WINAPI GetLastError(void); */ -__ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" ); - -/*********************************************************************** - * GetCurrentProcessId (KERNEL.471) - * GetCurrentProcessId (KERNEL32.@) - */ -/* DWORD WINAPI GetCurrentProcessId(void) */ -__ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" ); - -/*********************************************************************** - * GetCurrentThreadId (KERNEL.462) - * GetCurrentThreadId (KERNEL32.@) - */ -/* DWORD WINAPI GetCurrentThreadId(void) */ -__ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" ); - -#else /* __i386__ */ - -/********************************************************************** - * SetLastError (KERNEL.147) - * SetLastError (KERNEL32.@) - * - * Sets the last-error code. - */ -void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */ -{ - NtCurrentTeb()->last_error = error; -} - -/********************************************************************** - * GetLastError (KERNEL.148) - * GetLastError (KERNEL32.@) - * - * Returns last-error code. - */ -DWORD WINAPI GetLastError(void) -{ - return NtCurrentTeb()->last_error; -} - -/*********************************************************************** - * GetCurrentProcessId (KERNEL.471) - * GetCurrentProcessId (KERNEL32.@) - * - * Returns process identifier. - */ -DWORD WINAPI GetCurrentProcessId(void) -{ - return (DWORD)NtCurrentTeb()->ClientId.UniqueProcess; -} - -/*********************************************************************** - * GetCurrentThreadId (KERNEL.462) - * GetCurrentThreadId (KERNEL32.@) - * - * Returns thread identifier. - */ -DWORD WINAPI GetCurrentThreadId(void) -{ - return (DWORD)NtCurrentTeb()->ClientId.UniqueThread; -} - -#endif /* __i386__ */