implement proper IRQL, DPCs, kernel and user APCs, alertable waits, async file I/O with cancellation, trap frames, selftests, a real driver/device model, native async FAT32, VFAT dotfile fixes, syscall ABI cleanup, async_apc and async_cancel tests, POSIX multi-volume paths, and pimp the readme.
This commit is contained in:
1 parent
f5fd7bdd75
commit
529f816166
75 files changed
+9969
-5675
No files matched your search
@@ -0,0 +1,108 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
|
||||
#define EVENT_AUTO_RESET 0u
|
||||
|
||||
static void print(const char* s) {
|
||||
SysWriteConsole(s, strlen(s));
|
||||
}
|
||||
|
||||
static void print_u64(uint64_t v) {
|
||||
char buf[32];
|
||||
int i = 0;
|
||||
if (v == 0) {
|
||||
print("0");
|
||||
return;
|
||||
}
|
||||
while (v && i < (int)sizeof(buf)) {
|
||||
buf[i++] = (char)('0' + (v % 10));
|
||||
v /= 10;
|
||||
}
|
||||
while (i--) {
|
||||
char c = buf[i];
|
||||
SysWriteConsole(&c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
print("async_cancel: start\n");
|
||||
|
||||
uint32_t file = 0;
|
||||
uint32_t event = 0;
|
||||
uint32_t request = 0;
|
||||
|
||||
uint32_t s = SysOpenFile("system/init.exe", &file);
|
||||
if (s != SYS_STATUS_SUCCESS) {
|
||||
print("async_cancel: open failed status="); print_u64(s); print("\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
s = SysEventCreate(EVENT_AUTO_RESET, 0, &event);
|
||||
if (s != SYS_STATUS_SUCCESS) {
|
||||
print("async_cancel: event create failed status="); print_u64(s); print("\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
uint8_t* buffer = (uint8_t*)SysAlloc(512);
|
||||
if (!buffer) {
|
||||
print("async_cancel: alloc failed\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
memset(buffer, 0, 512);
|
||||
|
||||
SYS_IO_STATUS_BLOCK iosb;
|
||||
iosb.Status = 0;
|
||||
iosb.Information = 0;
|
||||
|
||||
SYS_ASYNC_FILE_REQUEST req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.FileHandle = file;
|
||||
req.EventHandle = event;
|
||||
req.Offset = 0;
|
||||
req.Buffer = buffer;
|
||||
req.Size = 512;
|
||||
req.Iosb = &iosb;
|
||||
req.RequestHandleOut = &request;
|
||||
|
||||
s = SysReadFileAsync(&req);
|
||||
if (s != SYS_STATUS_PENDING || request == 0) {
|
||||
print("async_cancel: submit failed status="); print_u64(s);
|
||||
print(" request="); print_u64(request); print("\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
uint32_t cs = SysCancelIo(request);
|
||||
print("async_cancel: cancel returned "); print_u64(cs); print("\n");
|
||||
|
||||
while (iosb.Status == SYS_STATUS_PENDING) {
|
||||
s = SysEventWait(event, 1);
|
||||
print("async_cancel: wait returned "); print_u64(s); print("\n");
|
||||
if (s != SYS_STATUS_SUCCESS && s != SYS_STATUS_KERNEL_APC && s != SYS_STATUS_USER_APC && s != SYS_STATUS_ALERTED)
|
||||
break;
|
||||
}
|
||||
|
||||
print("async_cancel: iosb status="); print_u64(iosb.Status);
|
||||
print(" info="); print_u64(iosb.Information); print("\n");
|
||||
|
||||
// If the worker had already started, cancellation is best-effort and the
|
||||
// request may complete successfully. If it was still queued, it must report
|
||||
// SYS_STATUS_CANCELLED. Both outcomes are valid; SYS_STATUS_PENDING is not.
|
||||
uint32_t ok = (iosb.Status == SYS_STATUS_CANCELLED) ||
|
||||
(iosb.Status == SYS_STATUS_SUCCESS && iosb.Information == 512);
|
||||
|
||||
SysCloseHandle(request);
|
||||
SysCloseHandle(event);
|
||||
SysCloseHandle(file);
|
||||
SysFree(buffer);
|
||||
|
||||
if (!ok) {
|
||||
print("async_cancel: FAIL\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
print("async_cancel: PASS\n");
|
||||
SysExitProcess(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user