* [Qemu-devel] [PATCH 1.0] Replace WriteFileEx with WriteFile in qemu_create_pidfile
@ 2011-11-07 14:36 Fabien Chouteau
2011-11-07 14:42 ` Paolo Bonzini
2011-11-09 19:44 ` Anthony Liguori
0 siblings, 2 replies; 3+ messages in thread
From: Fabien Chouteau @ 2011-11-07 14:36 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, weil, aliguori, jan.kiszka, pbonzini
The function that writes pidfile for win32 uses WriteFileEx which is an
asynchronous IO function. The arguments given to WriteFileEx are allocated on
the stack and one of them is "in out". When the IO operation is actually
executed the calling function has already returned, so the arguments are no
longer allocated or allocated to another frame.
Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
---
os-win32.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/os-win32.c b/os-win32.c
index 7909401..8ad5fa1 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -130,14 +130,15 @@ int qemu_create_pidfile(const char *filename)
memset(&overlap, 0, sizeof(overlap));
file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file == INVALID_HANDLE_VALUE) {
return -1;
}
len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
- ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
- &overlap, NULL);
+ ret = WriteFile(file, (LPCVOID)buffer, (DWORD)len,
+ NULL, &overlap);
+ CloseHandle(file);
if (ret == 0) {
return -1;
}
--
1.7.5.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 1.0] Replace WriteFileEx with WriteFile in qemu_create_pidfile
2011-11-07 14:36 [Qemu-devel] [PATCH 1.0] Replace WriteFileEx with WriteFile in qemu_create_pidfile Fabien Chouteau
@ 2011-11-07 14:42 ` Paolo Bonzini
2011-11-09 19:44 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2011-11-07 14:42 UTC (permalink / raw)
To: Fabien Chouteau; +Cc: blauwirbel, weil, aliguori, qemu-devel, jan.kiszka
On 11/07/2011 03:36 PM, Fabien Chouteau wrote:
> The function that writes pidfile for win32 uses WriteFileEx which is an
> asynchronous IO function. The arguments given to WriteFileEx are allocated on
> the stack and one of them is "in out". When the IO operation is actually
> executed the calling function has already returned, so the arguments are no
> longer allocated or allocated to another frame.
>
> Signed-off-by: Fabien Chouteau<chouteau@adacore.com>
> ---
> os-win32.c | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/os-win32.c b/os-win32.c
> index 7909401..8ad5fa1 100644
> --- a/os-win32.c
> +++ b/os-win32.c
> @@ -130,14 +130,15 @@ int qemu_create_pidfile(const char *filename)
> memset(&overlap, 0, sizeof(overlap));
>
> file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
> - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
> + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
This is s/tab/space/, unrelated but fine.
> if (file == INVALID_HANDLE_VALUE) {
> return -1;
> }
> len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
> - ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
> - &overlap, NULL);
> + ret = WriteFile(file, (LPCVOID)buffer, (DWORD)len,
> + NULL,&overlap);
> + CloseHandle(file);
> if (ret == 0) {
> return -1;
> }
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 1.0] Replace WriteFileEx with WriteFile in qemu_create_pidfile
2011-11-07 14:36 [Qemu-devel] [PATCH 1.0] Replace WriteFileEx with WriteFile in qemu_create_pidfile Fabien Chouteau
2011-11-07 14:42 ` Paolo Bonzini
@ 2011-11-09 19:44 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2011-11-09 19:44 UTC (permalink / raw)
To: Fabien Chouteau; +Cc: blauwirbel, weil, pbonzini, qemu-devel, jan.kiszka
On 11/07/2011 08:36 AM, Fabien Chouteau wrote:
> The function that writes pidfile for win32 uses WriteFileEx which is an
> asynchronous IO function. The arguments given to WriteFileEx are allocated on
> the stack and one of them is "in out". When the IO operation is actually
> executed the calling function has already returned, so the arguments are no
> longer allocated or allocated to another frame.
>
> Signed-off-by: Fabien Chouteau<chouteau@adacore.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
> os-win32.c | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/os-win32.c b/os-win32.c
> index 7909401..8ad5fa1 100644
> --- a/os-win32.c
> +++ b/os-win32.c
> @@ -130,14 +130,15 @@ int qemu_create_pidfile(const char *filename)
> memset(&overlap, 0, sizeof(overlap));
>
> file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
> - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
> + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
>
> if (file == INVALID_HANDLE_VALUE) {
> return -1;
> }
> len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
> - ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
> - &overlap, NULL);
> + ret = WriteFile(file, (LPCVOID)buffer, (DWORD)len,
> + NULL,&overlap);
> + CloseHandle(file);
> if (ret == 0) {
> return -1;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-09 19:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-07 14:36 [Qemu-devel] [PATCH 1.0] Replace WriteFileEx with WriteFile in qemu_create_pidfile Fabien Chouteau
2011-11-07 14:42 ` Paolo Bonzini
2011-11-09 19:44 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).