1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
452
453 if (GetProcessTimes(handle, &CreationTime, &ExitTime, &KernelTime, &UserTime)) {
454 userTime = jlong_from(UserTime.dwHighDateTime, UserTime.dwLowDateTime);
455 totalTime = jlong_from( KernelTime.dwHighDateTime, KernelTime.dwLowDateTime);
456 totalTime = (totalTime + userTime) * 100; // convert sum to nano-seconds
457
458 startTime = jlong_from(CreationTime.dwHighDateTime,
459 CreationTime.dwLowDateTime) / 10000;
460 startTime -= 11644473600000L; // Rebase Epoch from 1601 to 1970
461
462 (*env)->SetLongField(env, jinfo,
463 ProcessHandleImpl_Info_totalTimeID, totalTime);
464 JNU_CHECK_EXCEPTION(env);
465 (*env)->SetLongField(env, jinfo,
466 ProcessHandleImpl_Info_startTimeID, startTime);
467 JNU_CHECK_EXCEPTION(env);
468 }
469 }
470
471 static void getCmdlineInfo(JNIEnv *env, HANDLE handle, jobject jinfo) {
472 char exeName[1024];
473 int bufsize = sizeof exeName;
474 jstring commandObj;
475
476 if (QueryFullProcessImageName(handle, 0, exeName, &bufsize)) {
477 commandObj = (*env)->NewStringUTF(env, exeName);
478 CHECK_NULL(commandObj);
479 (*env)->SetObjectField(env, jinfo,
480 ProcessHandleImpl_Info_commandID, commandObj);
481 }
482 }
483
484 static void procToUser(JNIEnv *env, HANDLE handle, jobject jinfo) {
485 #define TOKEN_LEN 256
486 DWORD token_len = TOKEN_LEN;
487 char token_buf[TOKEN_LEN];
488 TOKEN_USER *token_user = (TOKEN_USER*)token_buf;
489 HANDLE tokenHandle;
490 WCHAR domain[255 + 1 + 255 + 1]; // large enough to concat with '/' and name
491 WCHAR name[255 + 1];
492 DWORD domainLen = sizeof(domain) - sizeof(name);
493 DWORD nameLen = sizeof(name);
494 SID_NAME_USE use;
495 jstring s;
496 int ret;
497
498 if (!OpenProcessToken(handle, TOKEN_READ, &tokenHandle)) {
499 return;
500 }
501
|
1 /*
2 * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
452
453 if (GetProcessTimes(handle, &CreationTime, &ExitTime, &KernelTime, &UserTime)) {
454 userTime = jlong_from(UserTime.dwHighDateTime, UserTime.dwLowDateTime);
455 totalTime = jlong_from( KernelTime.dwHighDateTime, KernelTime.dwLowDateTime);
456 totalTime = (totalTime + userTime) * 100; // convert sum to nano-seconds
457
458 startTime = jlong_from(CreationTime.dwHighDateTime,
459 CreationTime.dwLowDateTime) / 10000;
460 startTime -= 11644473600000L; // Rebase Epoch from 1601 to 1970
461
462 (*env)->SetLongField(env, jinfo,
463 ProcessHandleImpl_Info_totalTimeID, totalTime);
464 JNU_CHECK_EXCEPTION(env);
465 (*env)->SetLongField(env, jinfo,
466 ProcessHandleImpl_Info_startTimeID, startTime);
467 JNU_CHECK_EXCEPTION(env);
468 }
469 }
470
471 static void getCmdlineInfo(JNIEnv *env, HANDLE handle, jobject jinfo) {
472 WCHAR exeName[1024];
473 WCHAR *longPath;
474 DWORD bufsize = sizeof(exeName)/sizeof(WCHAR);
475 jstring commandObj = NULL;
476
477 if (QueryFullProcessImageNameW(handle, 0, exeName, &bufsize)) {
478 commandObj = (*env)->NewString(env, (const jchar *)exeName,
479 (jsize)wcslen(exeName));
480 } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
481 bufsize = 32768;
482 longPath = (WCHAR*)malloc(bufsize * sizeof(WCHAR));
483 if (longPath != NULL) {
484 if (QueryFullProcessImageNameW(handle, 0, longPath, &bufsize)) {
485 commandObj = (*env)->NewString(env, (const jchar *)longPath,
486 (jsize)wcslen(longPath));
487 }
488 free(longPath);
489 }
490 }
491 CHECK_NULL(commandObj);
492 (*env)->SetObjectField(env, jinfo,
493 ProcessHandleImpl_Info_commandID, commandObj);
494 }
495
496 static void procToUser(JNIEnv *env, HANDLE handle, jobject jinfo) {
497 #define TOKEN_LEN 256
498 DWORD token_len = TOKEN_LEN;
499 char token_buf[TOKEN_LEN];
500 TOKEN_USER *token_user = (TOKEN_USER*)token_buf;
501 HANDLE tokenHandle;
502 WCHAR domain[255 + 1 + 255 + 1]; // large enough to concat with '/' and name
503 WCHAR name[255 + 1];
504 DWORD domainLen = sizeof(domain) - sizeof(name);
505 DWORD nameLen = sizeof(name);
506 SID_NAME_USE use;
507 jstring s;
508 int ret;
509
510 if (!OpenProcessToken(handle, TOKEN_READ, &tokenHandle)) {
511 return;
512 }
513
|