1 /* |
1 /* |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
270 } |
270 } |
271 |
271 |
272 |
272 |
273 // open the pipe to the client |
273 // open the pipe to the client |
274 HANDLE Win32AttachOperation::open_pipe() { |
274 HANDLE Win32AttachOperation::open_pipe() { |
275 HANDLE hPipe; |
275 HANDLE hPipe = ::CreateFile( pipe(), // pipe name |
276 |
|
277 hPipe = ::CreateFile( pipe(), // pipe name |
|
278 GENERIC_WRITE, // write only |
276 GENERIC_WRITE, // write only |
279 0, // no sharing |
277 0, // no sharing |
280 NULL, // default security attributes |
278 NULL, // default security attributes |
281 OPEN_EXISTING, // opens existing pipe |
279 OPEN_EXISTING, // opens existing pipe |
282 0, // default attributes |
280 0, // default attributes |
283 NULL); // no template file |
281 NULL); // no template file |
284 |
|
285 if (hPipe != INVALID_HANDLE_VALUE) { |
|
286 // shouldn't happen as there is a pipe created per operation |
|
287 if (::GetLastError() == ERROR_PIPE_BUSY) { |
|
288 ::CloseHandle(hPipe); |
|
289 return INVALID_HANDLE_VALUE; |
|
290 } |
|
291 } |
|
292 return hPipe; |
282 return hPipe; |
293 } |
283 } |
294 |
284 |
295 // write to the pipe |
285 // write to the pipe |
296 BOOL Win32AttachOperation::write_pipe(HANDLE hPipe, char* buf, int len) { |
286 BOOL Win32AttachOperation::write_pipe(HANDLE hPipe, char* buf, int len) { |
324 thread->set_suspend_equivalent(); |
313 thread->set_suspend_equivalent(); |
325 // cleared by handle_special_suspend_equivalent_condition() or |
314 // cleared by handle_special_suspend_equivalent_condition() or |
326 // java_suspend_self() via check_and_wait_while_suspended() |
315 // java_suspend_self() via check_and_wait_while_suspended() |
327 |
316 |
328 HANDLE hPipe = open_pipe(); |
317 HANDLE hPipe = open_pipe(); |
|
318 int lastError = (int)::GetLastError(); |
329 if (hPipe != INVALID_HANDLE_VALUE) { |
319 if (hPipe != INVALID_HANDLE_VALUE) { |
330 BOOL fSuccess; |
320 BOOL fSuccess; |
331 |
321 |
332 char msg[32]; |
322 char msg[32]; |
333 _snprintf(msg, sizeof(msg), "%d\n", result); |
323 _snprintf(msg, sizeof(msg), "%d\n", result); |
335 |
325 |
336 fSuccess = write_pipe(hPipe, msg, (int)strlen(msg)); |
326 fSuccess = write_pipe(hPipe, msg, (int)strlen(msg)); |
337 if (fSuccess) { |
327 if (fSuccess) { |
338 fSuccess = write_pipe(hPipe, (char*)result_stream->base(), (int)(result_stream->size())); |
328 fSuccess = write_pipe(hPipe, (char*)result_stream->base(), (int)(result_stream->size())); |
339 } |
329 } |
|
330 lastError = (int)::GetLastError(); |
340 |
331 |
341 // Need to flush buffers |
332 // Need to flush buffers |
342 FlushFileBuffers(hPipe); |
333 FlushFileBuffers(hPipe); |
343 CloseHandle(hPipe); |
334 CloseHandle(hPipe); |
344 |
335 |
345 if (fSuccess) { |
336 if (fSuccess) { |
346 log_debug(attach)("wrote result of attach operation %s to pipe %s", name(), pipe()); |
337 log_debug(attach)("wrote result of attach operation %s to pipe %s", name(), pipe()); |
347 } else { |
338 } else { |
348 log_error(attach)("failure writing result of operation %s to pipe %s", name(), pipe()); |
339 log_error(attach)("failure (%d) writing result of operation %s to pipe %s", lastError, name(), pipe()); |
349 } |
340 } |
350 } else { |
341 } else { |
351 log_error(attach)("could not open pipe %s to send result of operation %s", pipe(), name()); |
342 log_error(attach)("could not open (%d) pipe %s to send result of operation %s", lastError, pipe(), name()); |
352 } |
343 } |
353 |
344 |
354 DWORD res = ::WaitForSingleObject(Win32AttachListener::mutex(), INFINITE); |
345 DWORD res = ::WaitForSingleObject(Win32AttachListener::mutex(), INFINITE); |
355 if (res == WAIT_OBJECT_0) { |
346 if (res == WAIT_OBJECT_0) { |
356 |
347 |