github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/executor/executor_windows.h (about)

     1  // Copyright 2017 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  #include <io.h>
     5  #include <windows.h>
     6  
     7  #include "nocover.h"
     8  
     9  #define read read_win
    10  #define write write_win
    11  
    12  static void os_init(int argc, char** argv, void* data, size_t data_size)
    13  {
    14  	if (VirtualAlloc(data, data_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE) != data)
    15  		fail("mmap of data segment failed");
    16  }
    17  
    18  static intptr_t execute_syscall(const call_t* c, intptr_t a[kMaxArgs])
    19  {
    20  	__try {
    21  		return c->call(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
    22  	} __except (EXCEPTION_EXECUTE_HANDLER) {
    23  		return -1;
    24  	}
    25  }
    26  
    27  static __inline int read_win(int pipe_id, void* input_data, int data_size)
    28  {
    29  	DWORD dwBytesRead = 0;
    30  	ReadFile((HANDLE)_get_osfhandle(pipe_id), input_data, data_size, &dwBytesRead, NULL);
    31  
    32  	return (int)dwBytesRead;
    33  }
    34  
    35  static __inline int write_win(int pipe_id, void* input_data, int data_size)
    36  {
    37  	DWORD dwBytesWritten = 0;
    38  	WriteFile((HANDLE)_get_osfhandle(pipe_id), input_data, data_size, &dwBytesWritten, NULL);
    39  	return (int)dwBytesWritten;
    40  }