1570af302Sopenharmony_ci#define _GNU_SOURCE
2570af302Sopenharmony_ci#include <unistd.h>
3570af302Sopenharmony_ci#include <sys/mman.h>
4570af302Sopenharmony_ci#include <errno.h>
5570af302Sopenharmony_ci#include <stdint.h>
6570af302Sopenharmony_ci#include <stdarg.h>
7570af302Sopenharmony_ci#include "syscall.h"
8570af302Sopenharmony_ci
9570af302Sopenharmony_cistatic void dummy(void) { }
10570af302Sopenharmony_ciweak_alias(dummy, __vm_wait);
11570af302Sopenharmony_ci
12570af302Sopenharmony_civoid *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
13570af302Sopenharmony_ci{
14570af302Sopenharmony_ci	va_list ap;
15570af302Sopenharmony_ci	void *new_addr = 0;
16570af302Sopenharmony_ci
17570af302Sopenharmony_ci	if (new_len >= PTRDIFF_MAX) {
18570af302Sopenharmony_ci		errno = ENOMEM;
19570af302Sopenharmony_ci		return MAP_FAILED;
20570af302Sopenharmony_ci	}
21570af302Sopenharmony_ci
22570af302Sopenharmony_ci	if (flags & MREMAP_FIXED) {
23570af302Sopenharmony_ci		__vm_wait();
24570af302Sopenharmony_ci		va_start(ap, flags);
25570af302Sopenharmony_ci		new_addr = va_arg(ap, void *);
26570af302Sopenharmony_ci		va_end(ap);
27570af302Sopenharmony_ci	}
28570af302Sopenharmony_ci
29570af302Sopenharmony_ci	return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
30570af302Sopenharmony_ci}
31570af302Sopenharmony_ci
32570af302Sopenharmony_ciweak_alias(__mremap, mremap);
33