JBoss Native SVN: r1120 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-17 09:49:36 -0400 (Wed, 17 Oct 2007)
New Revision: 1120
Modified:
trunk/sight/native/os/windows/scm.c
Log:
Bail out from the loop if interrupted
Modified: trunk/sight/native/os/windows/scm.c
===================================================================
--- trunk/sight/native/os/windows/scm.c 2007-10-17 13:46:31 UTC (rev 1119)
+++ trunk/sight/native/os/windows/scm.c 2007-10-17 13:49:36 UTC (rev 1120)
@@ -142,6 +142,11 @@
dwServiceState = SERVICE_INACTIVE;
SIGHT_LOCAL_TRY(no) {
do {
+ if (SIGHT_LOCAL_IRQ(no)) {
+ ea = NULL;
+ SIGHT_LOCAL_BRK(no);
+ goto cleanup;
+ }
rt = EnumServicesStatusExA(no->native,
SC_ENUM_PROCESS_INFO,
dwServiceType,
17 years, 2 months
JBoss Native SVN: r1119 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-17 09:46:31 -0400 (Wed, 17 Oct 2007)
New Revision: 1119
Modified:
trunk/sight/native/os/windows/scm.c
Log:
Tab police
Modified: trunk/sight/native/os/windows/scm.c
===================================================================
--- trunk/sight/native/os/windows/scm.c 2007-10-17 12:17:29 UTC (rev 1118)
+++ trunk/sight/native/os/windows/scm.c 2007-10-17 13:46:31 UTC (rev 1119)
@@ -117,14 +117,14 @@
jsize cnt = 0;
jint idx = 0;
DWORD rc;
- LPENUM_SERVICE_STATUS_PROCESSA lpService;
- DWORD dwSize = 0;
+ LPENUM_SERVICE_STATUS_PROCESSA lpService;
+ DWORD dwSize = 0;
DWORD dwNumServices = 0;
DWORD dwResumeHandle = 0;
DWORD dwServiceType;
DWORD dwServiceState = SERVICE_STATE_ALL;
- BOOL rt;
- void *lpBuffer = NULL;
+ BOOL rt;
+ void *lpBuffer = NULL;
svc_enum_t *head = NULL;
svc_enum_t *list = NULL;
@@ -146,12 +146,12 @@
SC_ENUM_PROCESS_INFO,
dwServiceType,
dwServiceState,
- (LPBYTE)lpBuffer,
- dwSize,
- &dwSize,
- &dwNumServices,
- &dwResumeHandle,
- NULL);
+ (LPBYTE)lpBuffer,
+ dwSize,
+ &dwSize,
+ &dwNumServices,
+ &dwResumeHandle,
+ NULL);
if (!rt && ((rc = GetLastError()) != ERROR_MORE_DATA)) {
throwAprException(_E, APR_FROM_OS_ERROR(rc));
ea = NULL;
17 years, 2 months
JBoss Native SVN: r1118 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-17 08:17:29 -0400 (Wed, 17 Oct 2007)
New Revision: 1118
Modified:
trunk/sight/native/os/solaris/tcpstat.c
Log:
sight_create_pool into sight_pool_create.
Modified: trunk/sight/native/os/solaris/tcpstat.c
===================================================================
--- trunk/sight/native/os/solaris/tcpstat.c 2007-10-17 12:01:46 UTC (rev 1117)
+++ trunk/sight/native/os/solaris/tcpstat.c 2007-10-17 12:17:29 UTC (rev 1118)
@@ -333,7 +333,7 @@
return 0;
}
- if ((rc = sight_create_pool(&e->pool, sight_temp_pool)) != APR_SUCCESS) {
+ if ((rc = sight_pool_create(&e->pool, NULL, sight_temp_pool, 0)) != APR_SUCCESS) {
throwAprMemoryException(_E, THROW_FMARK, rc);
return 0;
}
17 years, 2 months
JBoss Native SVN: r1117 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-17 08:01:46 -0400 (Wed, 17 Oct 2007)
New Revision: 1117
Modified:
trunk/sight/native/os/solaris/module.c
Log:
Oops. Forgotten trace.
Modified: trunk/sight/native/os/solaris/module.c
===================================================================
--- trunk/sight/native/os/solaris/module.c 2007-10-17 11:45:00 UTC (rev 1116)
+++ trunk/sight/native/os/solaris/module.c 2007-10-17 12:01:46 UTC (rev 1117)
@@ -269,7 +269,6 @@
return NULL;
}
current = module->first_module;
- printf("%d enum0 %d\n", current, module->nummodules);
for (j = 0; j < module->nummodules; j++) {
jobject m = new_module_class(_E, _O, pid, j);
if (!m || (*_E)->ExceptionCheck(_E)) {
17 years, 2 months
JBoss Native SVN: r1116 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-17 07:45:00 -0400 (Wed, 17 Oct 2007)
New Revision: 1116
Modified:
trunk/sight/native/os/solaris/module.c
Log:
fork() to collect own process information.
Modified: trunk/sight/native/os/solaris/module.c
===================================================================
--- trunk/sight/native/os/solaris/module.c 2007-10-16 16:55:48 UTC (rev 1115)
+++ trunk/sight/native/os/solaris/module.c 2007-10-17 11:45:00 UTC (rev 1116)
@@ -96,8 +96,8 @@
struct module {
char *name;
- int base;
- int size;
+ long base;
+ long size;
struct module *next;
};
@@ -140,6 +140,7 @@
current->next = apr_palloc(module->pool, sizeof(struct module));
current = current->next;
}
+ module->current = current;
current->next = NULL;
current->name = apr_pstrdup(module->pool, car);
current->base = map->pr_vaddr;
@@ -147,7 +148,48 @@
module->nummodules++;
return 0;
}
+/* Use a child process to read maps */
+static int proc_map_child(void *ptr, const prmap_t *map, const char *car)
+{
+ FILE *file = (FILE *)ptr;
+ fprintf(file, "%s\n", car);
+ fprintf(file, "%u\n", map->pr_vaddr);
+ fprintf(file, "%u\n", map->pr_size);
+ return 0;
+}
+static void proc_child(int fd, int pid)
+{
+ struct ps_prochandle *ph;
+ int ret;
+ FILE *file = fdopen(fd, "w");
+ ph = Pgrab(pid, 0, &ret);
+ if (ph == NULL)
+ return;
+ Pobject_iter(ph, proc_map_child, file);
+ Prelease(ph, 0);
+ return;
+}
+/* read information for the son process */
+static void Read_map_f(int fd, module_enum_t *module)
+{
+ FILE *file = fdopen(fd, "r");
+ char car[128];
+ char buf[128];
+ int addr, pr_size;
+ prmap_t map;
+ for (;;) {
+ if (fscanf(file, "%s", car)<0)
+ break;
+ fscanf(file, "%s", buf);
+ map.pr_vaddr = atoi(buf);
+ fscanf(file, "%s", buf);
+ map.pr_size = atoi(buf);
+ proc_map_f((void *)module, &map, car);
+ }
+}
+#define G_SELF 9
+
SIGHT_EXPORT_DECLARE(jobjectArray, Module, enum0)(SIGHT_STDARGS,
jint pid)
{
@@ -160,6 +202,7 @@
module_enum_t *module;
struct module *current;
jobjectArray mods = NULL;
+ int filedes[2];
UNREFERENCED_O;
if (pid >= 0)
@@ -171,16 +214,31 @@
}
ph = Pgrab(mpid, 0, &ret);
if (ph == NULL) {
- throwOSException(_E, Pgrab_error(ret));
- apr_pool_destroy(pool);
- return NULL;
+ if (ret != G_SELF) {
+ throwOSException(_E, Pgrab_error(ret));
+ apr_pool_destroy(pool);
+ return NULL;
+ } else {
+ /* fork and use a pipe to read self info */
+ pipe(filedes);
+ if (fork() == 0) {
+ close(filedes[0]);
+ proc_child(filedes[1], pid);
+ exit(0);
+ } else {
+ close(filedes[1]);
+ }
+ }
+ } else {
+ filedes[0] = -1;
}
/* Process all entries */
module = apr_palloc(pool, sizeof(module_enum_t));
if (module == NULL) {
throwAprMemoryException(_E, THROW_FMARK, apr_get_os_error());
- Prelease(ph, 0);
+ if (filedes[0] == -1)
+ Prelease(ph, 0);
apr_pool_destroy(pool);
return NULL;
}
@@ -188,23 +246,30 @@
module->nummodules = 0;
module->first_module = NULL;
module->current = NULL;
- Pobject_iter(ph, proc_map_f, module);
- if (ret<0) {
- throwOSException(_E, Pgrab_error(ret));
- apr_pool_destroy(pool);
- return NULL;
+ if (filedes[0] == -1) {
+ Pobject_iter(ph, proc_map_f, module);
+ if (ret<0) {
+ throwOSException(_E, Pgrab_error(ret));
+ Prelease(ph, 0);
+ apr_pool_destroy(pool);
+ return NULL;
+ }
+ /* Release the proc file system */
+ Prelease(ph, 0);
+ } else {
+ /* use pipe to read the information */
+ Read_map_f(filedes[0], module);
+ close(filedes[0]);
}
- /* Release the proc file system */
- Prelease(ph, 0);
-
/* Fill the java objects */
mods = (*_E)->NewObjectArray(_E, module->nummodules, _clazzn.a, NULL);
if (!mods || (*_E)->ExceptionCheck(_E)) {
apr_pool_destroy(pool);
return NULL;
}
- current = module->current;
+ current = module->first_module;
+ printf("%d enum0 %d\n", current, module->nummodules);
for (j = 0; j < module->nummodules; j++) {
jobject m = new_module_class(_E, _O, pid, j);
if (!m || (*_E)->ExceptionCheck(_E)) {
@@ -214,9 +279,10 @@
SET_IFIELD_S(0000, m, current->name);
SET_IFIELD_S(0001, m, current->name); /* should be basename */
SET_IFIELD_J(0002, m, current->base);
- SET_IFIELD_J(0002, m, current->size);
+ SET_IFIELD_J(0003, m, current->size);
(*_E)->SetObjectArrayElement(_E, mods, j, m);
(*_E)->DeleteLocalRef(_E, m);
+ current = current->next;
}
apr_pool_destroy(pool);
17 years, 2 months
JBoss Native SVN: r1115 - in trunk/sight: native/include/arch/windows and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-16 12:55:48 -0400 (Tue, 16 Oct 2007)
New Revision: 1115
Modified:
trunk/sight/examples/org/jboss/sight/ListProcesses.java
trunk/sight/native/include/arch/windows/sight_private.h
trunk/sight/native/os/windows/console.c
trunk/sight/native/os/windows/main.c
trunk/sight/native/os/windows/process.c
Log:
Use undocumented PEB structures instead directly reading memory.
Modified: trunk/sight/examples/org/jboss/sight/ListProcesses.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListProcesses.java 2007-10-15 11:05:10 UTC (rev 1114)
+++ trunk/sight/examples/org/jboss/sight/ListProcesses.java 2007-10-16 16:55:48 UTC (rev 1115)
@@ -42,19 +42,19 @@
for (Process p : Process.getProcesses()) {
User u = new User(p.UserId);
Group g = new Group(p.GroupId);
- if (p.Arguments==null)
- System.out.println("Process\t[" + p.Id + "] \t" +
- p.State + " : " + p.BaseName +
- " User(" + u.Name + ") Group(" +
- g.Name +")" + "\t " +
- p.CurrentWorkingDirectory);
- else
- System.out.println("Process\t[" + p.Id + "] \t" +
- p.State + " : " + p.BaseName +
- " User(" + u.Name + ") Group(" +
- g.Name +")" + "\t " +
- p.CurrentWorkingDirectory + "\t " +
- p.Arguments[0]);
+
+ System.out.print("Process\t[" + p.Id + "] \t" +
+ p.State + " : " + p.BaseName +
+ " User(" + u.Name + ") Group(" +
+ g.Name +")" + "\t " +
+ p.CurrentWorkingDirectory);
+ if (p.Arguments != null)
+ System.out.print("\t " + p.Arguments[0]);
+ if (p.Environment != null)
+ System.out.print("\t " + p.Environment[0]);
+
+ System.out.println();
+
}
} catch (Exception e) {
e.printStackTrace();
Modified: trunk/sight/native/include/arch/windows/sight_private.h
===================================================================
--- trunk/sight/native/include/arch/windows/sight_private.h 2007-10-15 11:05:10 UTC (rev 1114)
+++ trunk/sight/native/include/arch/windows/sight_private.h 2007-10-16 16:55:48 UTC (rev 1115)
@@ -72,6 +72,131 @@
SYSDLL_defined = 5 // must define as last idx_ + 1
} sight_dlltoken_e;
+/* Copied from http://source.winehq.org/source/include/winternl.h */
+
+typedef struct _CURDIR
+{
+ UNICODE_STRING DosPath;
+ PVOID Handle;
+} CURDIR, *PCURDIR;
+
+typedef struct RTL_DRIVE_LETTER_CURDIR
+{
+ USHORT Flags;
+ USHORT Length;
+ ULONG TimeStamp;
+ UNICODE_STRING DosPath;
+} RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
+
+typedef struct tagRTL_BITMAP {
+ ULONG SizeOfBitMap; /* Number of bits in the bitmap */
+ PULONG Buffer; /* Bitmap data, assumed sized to a DWORD boundary */
+} RTL_BITMAP, *PRTL_BITMAP;
+
+typedef struct _RTL_USER_PROCESS_PARAMETERS
+{
+ ULONG AllocationSize;
+ ULONG Size;
+ ULONG Flags;
+ ULONG DebugFlags;
+ HANDLE ConsoleHandle;
+ ULONG ConsoleFlags;
+ HANDLE hStdInput;
+ HANDLE hStdOutput;
+ HANDLE hStdError;
+ CURDIR CurrentDirectory;
+ UNICODE_STRING DllPath;
+ UNICODE_STRING ImagePathName;
+ UNICODE_STRING CommandLine;
+ PWSTR Environment;
+ ULONG dwX;
+ ULONG dwY;
+ ULONG dwXSize;
+ ULONG dwYSize;
+ ULONG dwXCountChars;
+ ULONG dwYCountChars;
+ ULONG dwFillAttribute;
+ ULONG dwFlags;
+ ULONG wShowWindow;
+ UNICODE_STRING WindowTitle;
+ UNICODE_STRING Desktop;
+ UNICODE_STRING ShellInfo;
+ UNICODE_STRING RuntimeInfo;
+ RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20];
+} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
+
+typedef struct _PEB_LDR_DATA
+{
+ ULONG Length;
+ BOOLEAN Initialized;
+ PVOID SsHandle;
+ LIST_ENTRY InLoadOrderModuleList;
+ LIST_ENTRY InMemoryOrderModuleList;
+ LIST_ENTRY InInitializationOrderModuleList;
+} PEB_LDR_DATA, *PPEB_LDR_DATA;
+
+/***********************************************************************
+ * PEB data structure (472 bytes)
+ */
+typedef struct _SIGHT_PEB
+{
+ BOOLEAN InheritedAddressSpace; /* 00 */
+ BOOLEAN ReadImageFileExecOptions; /* 01 */
+ BOOLEAN BeingDebugged; /* 02 */
+ BOOLEAN SpareBool; /* 03 */
+ HANDLE Mutant; /* 04 */
+ HMODULE ImageBaseAddress; /* 08 */
+ PPEB_LDR_DATA LdrData; /* 0c */
+ RTL_USER_PROCESS_PARAMETERS *ProcessParameters; /* 10 */
+ PVOID SubSystemData; /* 14 */
+ HANDLE ProcessHeap; /* 18 */
+ PRTL_CRITICAL_SECTION FastPebLock; /* 1c */
+ PVOID /*PPEBLOCKROUTINE*/ FastPebLockRoutine; /* 20 */
+ PVOID /*PPEBLOCKROUTINE*/ FastPebUnlockRoutine; /* 24 */
+ ULONG EnvironmentUpdateCount; /* 28 */
+ PVOID KernelCallbackTable; /* 2c */
+ PVOID EventLogSection; /* 30 */
+ PVOID EventLog; /* 34 */
+ PVOID /*PPEB_FREE_BLOCK*/ FreeList; /* 38 */
+ ULONG TlsExpansionCounter; /* 3c */
+ PRTL_BITMAP TlsBitmap; /* 40 */
+ ULONG TlsBitmapBits[2]; /* 44 */
+ PVOID ReadOnlySharedMemoryBase; /* 4c */
+ PVOID ReadOnlySharedMemoryHeap; /* 50 */
+ PVOID *ReadOnlyStaticServerData; /* 54 */
+ PVOID AnsiCodePageData; /* 58 */
+ PVOID OemCodePageData; /* 5c */
+ PVOID UnicodeCaseTableData; /* 60 */
+ ULONG NumberOfProcessors; /* 64 */
+ ULONG NtGlobalFlag; /* 68 */
+ BYTE Spare2[4]; /* 6c */
+ LARGE_INTEGER CriticalSectionTimeout; /* 70 */
+ ULONG HeapSegmentReserve; /* 78 */
+ ULONG HeapSegmentCommit; /* 7c */
+ ULONG HeapDeCommitTotalFreeThreshold; /* 80 */
+ ULONG HeapDeCommitFreeBlockThreshold; /* 84 */
+ ULONG NumberOfHeaps; /* 88 */
+ ULONG MaximumNumberOfHeaps; /* 8c */
+ PVOID *ProcessHeaps; /* 90 */
+ PVOID GdiSharedHandleTable; /* 94 */
+ PVOID ProcessStarterHelper; /* 98 */
+ PVOID GdiDCAttributeList; /* 9c */
+ PVOID LoaderLock; /* a0 */
+ ULONG OSMajorVersion; /* a4 */
+ ULONG OSMinorVersion; /* a8 */
+ ULONG OSBuildNumber; /* ac */
+ ULONG OSPlatformId; /* b0 */
+ ULONG ImageSubSystem; /* b4 */
+ ULONG ImageSubSystemMajorVersion; /* b8 */
+ ULONG ImageSubSystemMinorVersion; /* bc */
+ ULONG ImageProcessAffinityMask; /* c0 */
+ ULONG GdiHandleBuffer[34]; /* c4 */
+ ULONG PostProcessInitRoutine; /* 14c */
+ PRTL_BITMAP TlsExpansionBitmap; /* 150 */
+ ULONG TlsExpansionBitmapBits[32]; /* 154 */
+ ULONG SessionId; /* 1d4 */
+} SIGHT_PEB, *PSIGHT_PEB;
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -141,6 +266,17 @@
#undef NtQuerySystemInformation
#define NtQuerySystemInformation sight_late_NtQuerySystemInformation
+SIGHT_DECLARE_LATE_DLL_FUNC(SYSDLL_NTDLL, NTSTATUS, 1,
+ WINAPI, NtQueryInformationProcess, 0, (
+ IN HANDLE ProcessHandle,
+ IN PROCESSINFOCLASS ProcessInformationClass,
+ OUT PVOID ProcessInformation,
+ IN ULONG ProcessInformationLength,
+ OUT PULONG ReturnLength),
+ (ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength, ReturnLength));
+#undef NtQueryInformationProcess
+#define NtQueryInformationProcess sight_late_NtQueryInformationProcess
+
SIGHT_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
WINAPI, GetPerformanceInfo, 0, (
PPERFORMACE_INFORMATION pPerformanceInformation,
Modified: trunk/sight/native/os/windows/console.c
===================================================================
--- trunk/sight/native/os/windows/console.c 2007-10-15 11:05:10 UTC (rev 1114)
+++ trunk/sight/native/os/windows/console.c 2007-10-16 16:55:48 UTC (rev 1115)
@@ -282,7 +282,7 @@
if (wLen)
rv = ZSTR_TO_JSTRING(wBuf, wLen);
else
- rv = CSTR_TO_JSTRING(_E, "");
+ rv = CSTR_TO_JSTRING("");
}
cleanup:
Modified: trunk/sight/native/os/windows/main.c
===================================================================
--- trunk/sight/native/os/windows/main.c 2007-10-15 11:05:10 UTC (rev 1114)
+++ trunk/sight/native/os/windows/main.c 2007-10-16 16:55:48 UTC (rev 1115)
@@ -354,5 +354,6 @@
L"Failed setting SeDebugPrivilege",
GetLastError());
}
+
return APR_SUCCESS;
}
Modified: trunk/sight/native/os/windows/process.c
===================================================================
--- trunk/sight/native/os/windows/process.c 2007-10-15 11:05:10 UTC (rev 1114)
+++ trunk/sight/native/os/windows/process.c 2007-10-16 16:55:48 UTC (rev 1115)
@@ -230,52 +230,98 @@
goto cleanup;
}
(*_E)->SetIntArrayRegion(_E, rv, 0, pnum, parr);
+
cleanup:
free(parr);
return rv;
}
-#define PEB_ADDRESS(x) ((char *)0 + (0x00010000 * (1 + (x))))
+#define MAX_ENV_CHARS 2048
-static void read_proc_pages(DWORD pid, HANDLE hProcess,
- sight_str_t *pages, apr_pool_t *pool)
+static DWORD read_proc_peb(HANDLE hProcess, WCHAR **lpCwd,
+ WCHAR **lpCmdLine, WCHAR **lpEnv,
+ apr_pool_t *pool)
{
- int i;
- MEMORY_BASIC_INFORMATION mbi;
- SIZE_T nrd, rdd;
+ DWORD status;
+ PROCESS_BASIC_INFORMATION pbi;
+ SIGHT_PEB peb;
+ RTL_USER_PROCESS_PARAMETERS rtl;
+ DWORD dwSize;
- for (i = 0; i < 2; i++) {
- pages[i].len = 0;
- pages[i].str.w = NULL;
+ memset(&pbi, 0, sizeof(PROCESS_BASIC_INFORMATION));
+ memset(&peb, 0, sizeof(SIGHT_PEB));
+ memset(&rtl, 0, sizeof(RTL_USER_PROCESS_PARAMETERS));
+
+ if ((status = NtQueryInformationProcess(hProcess,
+ ProcessBasicInformation,
+ &pbi,
+ sizeof(PROCESS_BASIC_INFORMATION),
+ &dwSize)) != ERROR_SUCCESS) {
+ return status;
}
- for (i = 0; i < 2; i++) {
- if (!VirtualQueryEx(hProcess, PEB_ADDRESS(i), &mbi, sizeof(mbi)))
- continue;
- nrd = mbi.RegionSize;
- rdd = 0;
- if (nrd > 8192)
- continue;
- pages[i].str.w = apr_palloc(pool, nrd);
- if (!pages[i].str.w) {
- /* If we cannot alloc memory what's the point? */
- return;
+
+ if (!pbi.PebBaseAddress)
+ return EINVAL;
+ if (!ReadProcessMemory(hProcess,
+ pbi.PebBaseAddress,
+ &peb,
+ sizeof(SIGHT_PEB),
+ &dwSize)) {
+ return GetLastError();
+ }
+
+ if (!ReadProcessMemory(hProcess,
+ peb.ProcessParameters,
+ &rtl,
+ sizeof(RTL_USER_PROCESS_PARAMETERS),
+ &dwSize)) {
+ return GetLastError();
+ }
+ /* Read actual data */
+ if (rtl.CurrentDirectory.DosPath.Buffer &&
+ rtl.CurrentDirectory.DosPath.Length) {
+ *lpCwd = apr_pcalloc(pool,
+ rtl.CurrentDirectory.DosPath.Length + sizeof(WCHAR));
+ if (*lpCwd) {
+ if (!ReadProcessMemory(hProcess,
+ rtl.CurrentDirectory.DosPath.Buffer,
+ *lpCwd,
+ rtl.CurrentDirectory.DosPath.Length,
+ NULL))
+ *lpCwd = NULL;
}
- if (!ReadProcessMemory(hProcess,
- PEB_ADDRESS(i),
- pages[i].str.w,
- nrd,
- &rdd)) {
- pages[i].str.w = NULL;
- pages[i].len = 0;
+ }
+ if (rtl.CommandLine.Buffer &&
+ rtl.CommandLine.Length) {
+ *lpCmdLine = apr_pcalloc(pool,
+ rtl.CommandLine.Length + sizeof(WCHAR));
+ if (*lpCmdLine) {
+ if (!ReadProcessMemory(hProcess,
+ rtl.CommandLine.Buffer,
+ *lpCmdLine,
+ rtl.CommandLine.Length,
+ NULL))
+ *lpCmdLine = NULL;
}
- else {
- pages[i].len = (jsize)(rdd / 2);
- /* Make sure we always have double zero at the end */
- pages[i].str.w[pages[i].len - 1] = 0;
- pages[i].str.w[pages[i].len - 2] = 0;
+ }
+ if (rtl.Environment) {
+ MEMORY_BASIC_INFORMATION mbi;
+ if (VirtualQueryEx(hProcess, rtl.Environment, &mbi, sizeof(mbi)))
+ *lpEnv = apr_pcalloc(pool, mbi.RegionSize);
+ else
+ *lpEnv = NULL;
+ if (*lpEnv) {
+ if (!ReadProcessMemory(hProcess,
+ rtl.Environment,
+ *lpEnv,
+ mbi.RegionSize - 4,
+ NULL))
+ *lpEnv = NULL;
}
}
+
+ return ERROR_SUCCESS;
}
static BOOL find_pe32(DWORD pid, PROCESSENTRY32W *ppe32)
@@ -301,53 +347,6 @@
return rv;
}
-
-#define NT32_CWDOFF 164
-#define NT64_CWDOFF 252
-
-#define NT32_OFFSET 294
-#define NT64_OFFSET 382
-
-#define NT32_CWDIFF 130
-
-#define ALIGN_TO_DWORD(A) ((((LPBYTE)(A) - ((LPBYTE)0)) + 3) & ~3)
-
-
-static LPWSTR get_procc_base(LPWSTR mem, SIZE_T len, SIZE_T *off)
-{
- DWORD *base = (DWORD *)mem;
- DWORD *boff = NULL;
- SIZE_T cnt = len / sizeof(DWORD);
- SIZE_T roff = NT32_CWDOFF;
-
- while (!base[roff]) {
- if (roff++ > (cnt - sizeof(DWORD)))
- return NULL;
- }
- if (roff <= NT64_CWDOFF)
- boff = &base[roff];
- else
- roff = NT32_CWDOFF;
- *off = roff;
- return (LPWSTR)boff;
-}
-
-static LPWSTR get_procd_base(LPWSTR mem, SIZE_T len, SIZE_T off)
-{
- DWORD *base = (DWORD *)mem;
- DWORD *boff = NULL;
- SIZE_T cnt = len / sizeof(DWORD);
-
-
- off += NT32_CWDIFF;
- while (!base[off]) {
- if (off++ > (cnt - sizeof(DWORD)))
- return NULL;
- }
- boff = &base[off];
- return (LPWSTR)boff;
-}
-
static void proc_cleanup(int mode, sight_object_t *no)
{
if (no) {
@@ -368,15 +367,13 @@
jchar buf[SIGHT_STYPE_SIZ];
IO_COUNTERS ioc;
FILETIME ft[4];
- sight_str_t ppages[4];
- LPWSTR mproc = NULL;
- SIZE_T mpnrd = 0;
int ppid = -1, tcnt = 0;
PROCESSENTRY32W pe32;
jlong et = 0;
apr_uid_t uid;
apr_gid_t gid;
- int spage = 0;
+ LPWSTR *pargs;
+ int pargc = 0;
if (pid < 0)
return APR_SUCCESS;
@@ -386,6 +383,7 @@
#ifdef SIGHT_DO_STATS
no->clean = proc_cleanup;
#endif
+
SIGHT_LOCAL_TRY(no) {
if (!find_pe32(pid, &pe32)) {
/* System pids have low values */
@@ -448,35 +446,17 @@
/* XXX: Reading process memory is a hack.
*/
if (pid != (jint)GetCurrentProcessId()) {
- read_proc_pages(pid, hProcess, &ppages[0], no->pool);
- if (ppages[0].str.w && (*ppages[0].str.w > 0x003C && *ppages[0].str.w < 0x007F)) {
- SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, ppages[0].str.w));
- }
- if (ppages[1].str.w) {
- mproc = ppages[spage+1].str.w;
- mpnrd = ppages[spage+1].len;
- }
- if (mproc && mpnrd) {
- SIZE_T pO = NT32_CWDOFF;
- LPWSTR p1, p2, e1;
- int l1, l2;
- if ((p1 = (LPWSTR)get_procc_base(mproc, mpnrd, &pO))) {
- SET_IFIELD_W(0018, thiz, p1);
- }
- /* XXX Might not work on all Windows platforms */
- if ((p1 = (LPWSTR)get_procd_base(mproc, mpnrd, pO))) {
- LPWSTR *args;
- /* p1 Process PATH */
- l1 = lstrlenW(p1) + 1;
- p2 = (LPWSTR)ALIGN_TO_DWORD(p1 + l1);
- /* p2 Process Executable */
- l2 = lstrlenW(p2) + 1;
- e1 = (LPWSTR)ALIGN_TO_DWORD(p2 + l2);
- /* e1 Process Cmdline */
- args = (LPWSTR *)CommandLineToArgvW(e1, &l1);
- if (args) {
- SET_IFIELD_O(0003, thiz, sight_aw_to_sa(_E, args, l1));
- LocalFree(args);
+ WCHAR *lpCwd = NULL, *lpCmdLine = NULL, *lpEnv = NULL;
+ if (read_proc_peb(hProcess, &lpCwd, &lpCmdLine,
+ &lpEnv, no->pool) == ERROR_SUCCESS) {
+ SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, lpEnv));
+ SET_IFIELD_W(0018, thiz, lpCwd);
+ if (lpCmdLine) {
+ pargs = (LPWSTR *)CommandLineToArgvW(lpCmdLine,
+ &pargc);
+ if (pargs) {
+ SET_IFIELD_O(0003, thiz, sight_aw_to_sa(_E, pargs, pargc));
+ LocalFree(pargs);
}
}
}
@@ -484,8 +464,6 @@
else {
LPVOID env;
LPWSTR cmdl;
- int pargc;
- LPWSTR *pargs;
if ((env = GetEnvironmentStringsW())) {
SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, env));
17 years, 2 months
JBoss Native SVN: r1114 - trunk/sight/native/os/stubs.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-15 07:05:10 -0400 (Mon, 15 Oct 2007)
New Revision: 1114
Modified:
trunk/sight/native/os/stubs/console.c
Log:
Use macros for NewString JNI calls
Modified: trunk/sight/native/os/stubs/console.c
===================================================================
--- trunk/sight/native/os/stubs/console.c 2007-10-15 10:57:40 UTC (rev 1113)
+++ trunk/sight/native/os/stubs/console.c 2007-10-15 11:05:10 UTC (rev 1114)
@@ -80,7 +80,7 @@
SIGHT_EXPORT_DECLARE(jstring, Console, gtitle0)(SIGHT_STDARGS)
{
UNREFERENCED_O;
- return (*_E)->NewStringUTF(_E, "Unknown");
+ return CSTR_TO_JSTRING("Unknown");
}
SIGHT_EXPORT_DECLARE(void, Console, kill3)(SIGHT_STDARGS)
17 years, 2 months
JBoss Native SVN: r1113 - in trunk/sight/native: os/linux and 3 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-15 06:57:40 -0400 (Mon, 15 Oct 2007)
New Revision: 1113
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/os/linux/console.c
trunk/sight/native/os/linux/scm.c
trunk/sight/native/os/solaris/console.c
trunk/sight/native/os/solaris/process.c
trunk/sight/native/os/solaris/scm.c
trunk/sight/native/os/windows/console.c
trunk/sight/native/os/windows/registry.c
trunk/sight/native/os/windows/scm.c
trunk/sight/native/share/jnu.c
Log:
Use macros for NewString JNI calls
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/include/sight_local.h 2007-10-15 10:57:40 UTC (rev 1113)
@@ -83,8 +83,11 @@
#define POOL_CLEAR 2
-#define CSTR_TO_JSTRING(V) (*_E)->NewStringUTF((_E), (V))
+#define CSTR_TO_JSTRING(V) (*_E)->NewStringUTF(_E, (char *)(V))
+#define WSTR_TO_JSTRING(V) (*_E)->NewString(_E, (jchar *)(V), (jsize)wcslen((jchar *)(V)))
+#define ZSTR_TO_JSTRING(V, L) (*_E)->NewString(_E, (jchar *)(V), (L))
+
#define RETURN_JCSTR(V) \
if ((V)) return (*_E)->NewStringUTF((_E), (V)); \
else return NULL
Modified: trunk/sight/native/os/linux/console.c
===================================================================
--- trunk/sight/native/os/linux/console.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/linux/console.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -337,7 +337,7 @@
SIGHT_EXPORT_DECLARE(jstring, Console, gtitle0)(SIGHT_STDARGS)
{
UNREFERENCED_O;
- return (*_E)->NewStringUTF(_E, "Unknown");
+ return CSTR_TO_JSTRING("Unknown");
}
SIGHT_EXPORT_DECLARE(void, Console, kill3)(SIGHT_STDARGS)
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/linux/scm.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -201,7 +201,7 @@
return NULL;
}
for (i = 0; i < cnt; i++) {
- jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ jstring s = CSTR_TO_JSTRING(si->services->arr[i]);
if (s)
(*_E)->SetObjectArrayElement(_E, ea, idx++, s);
else
Modified: trunk/sight/native/os/solaris/console.c
===================================================================
--- trunk/sight/native/os/solaris/console.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/solaris/console.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -337,7 +337,7 @@
SIGHT_EXPORT_DECLARE(jstring, Console, gtitle0)(SIGHT_STDARGS)
{
UNREFERENCED_O;
- return (*_E)->NewStringUTF(_E, "Unknown");
+ return CSTR_TO_JSTRING("Unknown");
}
SIGHT_EXPORT_DECLARE(void, Console, kill3)(SIGHT_STDARGS)
Modified: trunk/sight/native/os/solaris/process.c
===================================================================
--- trunk/sight/native/os/solaris/process.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/solaris/process.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -362,7 +362,7 @@
jstring s;
if (lseek(fd, sa[n], SEEK_SET) != -1) {
if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = (*_E)->NewStringUTF((_E), pname);
+ s = CSTR_TO_JSTRING(pname);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -370,7 +370,7 @@
continue;
}
}
- s = (*_E)->NewStringUTF((_E), "");
+ s = CSTR_TO_JSTRING("");
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -412,7 +412,7 @@
jstring s;
if (lseek(fd, sa[n], SEEK_SET) != -1) {
if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = (*_E)->NewStringUTF((_E), pname);
+ s = CSTR_TO_JSTRING(pname);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -420,7 +420,7 @@
continue;
}
}
- s = (*_E)->NewStringUTF((_E), "");
+ s = CSTR_TO_JSTRING("");
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -455,7 +455,7 @@
memcpy(pr_name, &psinfo.pr_psargs[l], j-l);
j++;
l = j;
- s = (*_E)->NewStringUTF((_E), pr_name);
+ s = CSTR_TO_JSTRING(pr_name);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, k, s);
(*_E)->DeleteLocalRef(_E, s);
Modified: trunk/sight/native/os/solaris/scm.c
===================================================================
--- trunk/sight/native/os/solaris/scm.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/solaris/scm.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -199,7 +199,7 @@
return NULL;
}
for (i = 0; i < cnt; i++) {
- jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ jstring s = CSTR_TO_JSTRING(si->services->arr[i]);
if (s)
(*_E)->SetObjectArrayElement(_E, ea, idx++, s);
else
Modified: trunk/sight/native/os/windows/console.c
===================================================================
--- trunk/sight/native/os/windows/console.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/windows/console.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -226,7 +226,7 @@
UNREFERENCED_O;
if ((dwLen = GetConsoleTitleW(szBuf, SIGHT_HBUFFER_SIZ)) != 0) {
- return (*_E)->NewString(_E, (jchar *)&szBuf[0], dwLen);
+ return ZSTR_TO_JSTRING(&szBuf[0], dwLen);
}
else
return NULL;
@@ -269,10 +269,10 @@
/* set length of string and null terminate it */
if (wBuf[wLen] == L'\r') {
- rv = (*_E)->NewString(_E, wBuf, wLen - 2);
+ rv = ZSTR_TO_JSTRING(wBuf, wLen - 2);
}
else if ((wLen == MAX_CONSOLE_SIZE) && (wBuf[wLen - 1] == L'\r')) {
- rv = (*_E)->NewString(_E, wBuf, wLen - 1);
+ rv = ZSTR_TO_JSTRING(wBuf, wLen - 1);
}
else {
if (wLen > 0 && wBuf[wLen - 1] == L'\n')
@@ -280,9 +280,9 @@
if (wLen > 0 && wBuf[wLen - 1] == L'\r')
--wLen;
if (wLen)
- rv = (*_E)->NewString(_E, wBuf, wLen);
+ rv = ZSTR_TO_JSTRING(wBuf, wLen);
else
- rv = (*_E)->NewStringUTF(_E, "");
+ rv = CSTR_TO_JSTRING(_E, "");
}
cleanup:
Modified: trunk/sight/native/os/windows/registry.c
===================================================================
--- trunk/sight/native/os/windows/registry.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/windows/registry.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -450,7 +450,7 @@
free(vw);
goto cleanup;
}
- v = (*_E)->NewString(_E, vw, (jsize)wcslen(vw));
+ v = WSTR_TO_JSTRING(vw);
free(vw);
}
cleanup:
@@ -564,7 +564,7 @@
jchar *b = p;
while (*p)
p++;
- s = (*_E)->NewString(_E, b, (jsize)(p - b));
+ s = ZSTR_TO_JSTRING(b, (p - b));
if (s)
(*_E)->SetObjectArrayElement(_E, v, idx++, s);
else
@@ -824,7 +824,7 @@
NULL,
&ftLastWriteTime);
if (rc == (DWORD)ERROR_SUCCESS) {
- s = (*_E)->NewString(_E, achKey, (jsize)wcslen(achKey));
+ s = WSTR_TO_JSTRING(achKey);
if (s) {
(*_E)->SetObjectArrayElement(_E, v, idx, s);
if ((*_E)->ExceptionCheck(_E))
@@ -902,7 +902,7 @@
NULL, // &bData,
NULL); // &bcData
if (rc == (DWORD)ERROR_SUCCESS) {
- s = (*_E)->NewString(_E, achValue, (jsize)wcslen(achValue));
+ s = WSTR_TO_JSTRING(achValue);
if (s) {
(*_E)->SetObjectArrayElement(_E, v, idx, s);
if ((*_E)->ExceptionCheck(_E))
Modified: trunk/sight/native/os/windows/scm.c
===================================================================
--- trunk/sight/native/os/windows/scm.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/os/windows/scm.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -189,7 +189,7 @@
DWORD i;
lpService = (LPENUM_SERVICE_STATUS_PROCESSA)&head->data[0];
for (i = 0; i < head->size; i++) {
- jstring s = (*_E)->NewStringUTF(_E, lpService[i].lpServiceName);
+ jstring s = WSTR_TO_JSTRING(lpService[i].lpServiceName);
if (s)
(*_E)->SetObjectArrayElement(_E, ea, idx++, s);
else
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-10-15 07:36:46 UTC (rev 1112)
+++ trunk/sight/native/share/jnu.c 2007-10-15 10:57:40 UTC (rev 1113)
@@ -289,7 +289,7 @@
n = 0;
for (p = str; p && *p; p++) {
- jstring s = (*_E)->NewStringUTF((_E), p);
+ jstring s = CSTR_TO_JSTRING(p);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -321,7 +321,7 @@
while (*p)
p++;
len = (jsize)(p - ptr);
- s = (*_E)->NewString((_E), ptr, len);
+ s = ZSTR_TO_JSTRING(ptr, len);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, n, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -342,7 +342,7 @@
return NULL;
for (i = 0; i < n; i++) {
- jstring s = (*_E)->NewStringUTF((_E), str[i]);
+ jstring s = CSTR_TO_JSTRING(str[i]);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, i, s);
(*_E)->DeleteLocalRef(_E, s);
@@ -362,8 +362,7 @@
return NULL;
for (i = 0; i < n; i++) {
- jstring s = (*_E)->NewString((_E), str[i],
- sight_wcslen(str[i]));
+ jstring s = WSTR_TO_JSTRING(str[i]);
if (s) {
(*_E)->SetObjectArrayElement(_E, arr, i, s);
(*_E)->DeleteLocalRef(_E, s);
17 years, 2 months
JBoss Native SVN: r1112 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-15 03:36:46 -0400 (Mon, 15 Oct 2007)
New Revision: 1112
Modified:
trunk/sight/native/share/library.c
Log:
Oops. My JAVA code wasn't u to date. Sorry.
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-14 10:04:14 UTC (rev 1111)
+++ trunk/sight/native/share/library.c 2007-10-15 07:36:46 UTC (rev 1112)
@@ -156,7 +156,7 @@
}
}
-SIGHT_EXPORT_DECLARE(jboolean, Library, initialize)(SIGHT_STDARGS)
+SIGHT_EXPORT_DECLARE(jboolean, Library, initialize0)(SIGHT_STDARGS)
{
UNREFERENCED_STDARGS;
17 years, 2 months
JBoss Native SVN: r1111 - in trunk/sight/native: os/solaris and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-14 06:04:14 -0400 (Sun, 14 Oct 2007)
New Revision: 1111
Modified:
trunk/sight/native/configure.in
trunk/sight/native/os/solaris/module.c
trunk/sight/native/share/library.c
Log:
Get the solaris port running.
Modified: trunk/sight/native/configure.in
===================================================================
--- trunk/sight/native/configure.in 2007-10-14 08:23:17 UTC (rev 1110)
+++ trunk/sight/native/configure.in 2007-10-14 10:04:14 UTC (rev 1111)
@@ -171,6 +171,7 @@
case $host in
*-solaris2*)
APR_ADDTO(SIGHT_LIBS, -lkstat)
+ APR_ADDTO(SIGHT_LIBS, -lproc)
;;
*)
;;
Modified: trunk/sight/native/os/solaris/module.c
===================================================================
--- trunk/sight/native/os/solaris/module.c 2007-10-14 08:23:17 UTC (rev 1110)
+++ trunk/sight/native/os/solaris/module.c 2007-10-14 10:04:14 UTC (rev 1111)
@@ -165,11 +165,11 @@
if (pid >= 0)
mpid = pid;
- if ((rc = sight_create_pool(&pool, sight_temp_pool)) != APR_SUCCESS) {
+ if ((rc = sight_pool_create(&pool, NULL, sight_temp_pool, 0)) != APR_SUCCESS) {
throwAprMemoryException(_E, THROW_FMARK, rc);
return NULL;
}
- ph = Pgrab(pid, 0, &ret);
+ ph = Pgrab(mpid, 0, &ret);
if (ph == NULL) {
throwOSException(_E, Pgrab_error(ret));
apr_pool_destroy(pool);
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-14 08:23:17 UTC (rev 1110)
+++ trunk/sight/native/share/library.c 2007-10-14 10:04:14 UTC (rev 1111)
@@ -156,7 +156,7 @@
}
}
-SIGHT_EXPORT_DECLARE(jboolean, Library, initialize0)(SIGHT_STDARGS)
+SIGHT_EXPORT_DECLARE(jboolean, Library, initialize)(SIGHT_STDARGS)
{
UNREFERENCED_STDARGS;
17 years, 2 months