summaryrefslogtreecommitdiffhomepage
path: root/src/blitter/ntapi_blt_free.c
blob: 1d610595206b9818023bc3d61a585320f0633373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <ntapi/nt_status.h>
#include <ntapi/nt_blitter.h>
#include <ntapi/nt_sync.h>
#include <ntapi/ntapi.h>
#include "ntapi_blitter.h"
#include "ntapi_impl.h"

int32_t __fastcall __ntapi_blt_free(nt_blitter * blt_ctx)
{
	int32_t	status;
	void *	region_addr;
	size_t	region_size;

	/* validation */
	if (!blt_ctx) return NT_STATUS_INVALID_PARAMETER;

	/* free blt block */
	region_addr = blt_ctx->info.region_addr;
	region_size = blt_ctx->info.region_size;

	if (region_size && !blt_ctx->params.region) {
		status = __ntapi->zw_free_virtual_memory(
			NT_CURRENT_PROCESS_HANDLE,
			&region_addr,
			&region_size,
			NT_MEM_RELEASE);

		if (status) return status;
	}

	/* free blt control block */
	region_addr = blt_ctx->addr;
	region_size = blt_ctx->size;

	status = __ntapi->zw_free_virtual_memory(
		NT_CURRENT_PROCESS_HANDLE,
		&region_addr,
		&region_size,
		NT_MEM_RELEASE);

	return status;
}