From 0d23db8a0e27375695b639883db86e28395efe6c Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Fri, 28 Aug 2026 09:15:06 +0200 Subject: [PATCH] cleanup: change _zos to _mtk --- programs/lib/libc/libc.c | 230 +++++++++++++++++++-------------------- 1 file changed, 115 insertions(+), 115 deletions(-) diff --git a/programs/lib/libc/libc.c b/programs/lib/libc/libc.c index a92d6dc..ff110da 100644 --- a/programs/lib/libc/libc.c +++ b/programs/lib/libc/libc.c @@ -30,14 +30,14 @@ Raw syscall wrappers (C versions matching kernel ABI) ======================================================================== */ -static inline long _zos_syscall0(long nr) { +static inline long _mtk_syscall0(long nr) { long ret; __asm__ volatile("syscall" : "=a"(ret) : "a"(nr) : "rcx", "r11", "rdi", "rsi", "rdx", "r8", "r9", "r10", "memory"); return ret; } -static inline long _zos_syscall1(long nr, long a1) { +static inline long _mtk_syscall1(long nr, long a1) { long ret; __asm__ volatile( "mov %[a1], %%rdi\n\t" @@ -48,7 +48,7 @@ static inline long _zos_syscall1(long nr, long a1) { return ret; } -static inline long _zos_syscall2(long nr, long a1, long a2) { +static inline long _mtk_syscall2(long nr, long a1, long a2) { long ret; __asm__ volatile( "mov %[a1], %%rdi\n\t" @@ -60,7 +60,7 @@ static inline long _zos_syscall2(long nr, long a1, long a2) { return ret; } -static inline long _zos_syscall3(long nr, long a1, long a2, long a3) { +static inline long _mtk_syscall3(long nr, long a1, long a2, long a3) { long ret; __asm__ volatile( "mov %[a1], %%rdi\n\t" @@ -73,7 +73,7 @@ static inline long _zos_syscall3(long nr, long a1, long a2, long a3) { return ret; } -static inline long _zos_syscall4(long nr, long a1, long a2, long a3, long a4) { +static inline long _mtk_syscall4(long nr, long a1, long a2, long a3, long a4) { long ret; __asm__ volatile( "mov %[a1], %%rdi\n\t" @@ -274,12 +274,12 @@ static void _tm_from_epoch(time_t epoch, struct tm *out) { } static int _get_tz_offset_minutes(void) { - return (int)_zos_syscall0(SYS_GETTZ); + return (int)_mtk_syscall0(SYS_GETTZ); } static time_t _current_time_epoch(void) { struct _mtk_datetime dt = {}; - _zos_syscall1(SYS_GETTIME, (long)&dt); + _mtk_syscall1(SYS_GETTIME, (long)&dt); return _epoch_from_datetime((int)dt.year, (int)dt.month, (int)dt.day, (int)dt.hour, (int)dt.minute, (int)dt.second) - (time_t)_get_tz_offset_minutes() * 60; @@ -320,7 +320,7 @@ static int _append_num(char *buf, size_t max, size_t *pos, int value, int width, static int _path_is_directory(const char *path) { const char *names[1]; - return (int)_zos_syscall3(SYS_READDIR, (long)path, (long)names, 1L) >= 0; + return (int)_mtk_syscall3(SYS_READDIR, (long)path, (long)names, 1L) >= 0; } static int _path_local_prefix(const char *path, char *buf, size_t size) { @@ -384,13 +384,13 @@ static int _sync_environ_to_kernel(void) { out += len; } blob[out++] = '\0'; - return _zos_syscall2(SYS_SETENVIRON, (long)blob, (long)out) < 0 ? -1 : 0; + return _mtk_syscall2(SYS_SETENVIRON, (long)blob, (long)out) < 0 ? -1 : 0; } static void _ensure_environ_initialized(void) { if (_environ_initialized) return; static char blob[4096]; - int len = (int)_zos_syscall2(SYS_GETENVIRON, (long)blob, (long)sizeof(blob)); + int len = (int)_mtk_syscall2(SYS_GETENVIRON, (long)blob, (long)sizeof(blob)); if (len > 0) __libc_init_environ(blob, (size_t)len); else @@ -706,7 +706,7 @@ static volatile uint32_t g_heapLock = 0; static void heap_lock(void) { while (__atomic_exchange_n(&g_heapLock, 1, __ATOMIC_ACQUIRE) != 0) - _zos_syscall0(SYS_YIELD); + _mtk_syscall0(SYS_YIELD); } static void heap_unlock(void) { @@ -805,11 +805,11 @@ static void heap_grow(uint64_t bytes) { uint64_t slab = (want > g_heap_slab) ? want : g_heap_slab; if (g_heap_slab < 4 * 1024 * 1024) g_heap_slab *= 2; - void *mem = (void *)_zos_syscall1(SYS_ALLOC, (long)slab); + void *mem = (void *)_mtk_syscall1(SYS_ALLOC, (long)slab); if (mem == NULL && slab > want) { /* Big slab refused (low memory): retry with the exact need. */ slab = want; - mem = (void *)_zos_syscall1(SYS_ALLOC, (long)slab); + mem = (void *)_mtk_syscall1(SYS_ALLOC, (long)slab); } if (mem != NULL) heap_insert_overflow(mem, slab); @@ -856,7 +856,7 @@ static void *heap_malloc_locked(size_t size) { if (needed > UINT64_MAX - 0xFFFULL) return NULL; uint64_t mapping_size = (needed + 0xFFFULL) & ~0xFFFULL; struct HeapHeader *hdr = (struct HeapHeader *) - _zos_syscall1(SYS_ALLOC, (long)mapping_size); + _mtk_syscall1(SYS_ALLOC, (long)mapping_size); if (hdr == NULL) return NULL; hdr->magic = DIRECT_MAGIC; hdr->requested_size = size; @@ -926,7 +926,7 @@ static void heap_free_locked(void *ptr) { hdr->magic = FREED_MAGIC; if (direct) { - _zos_syscall1(SYS_FREE, (long)hdr); + _mtk_syscall1(SYS_FREE, (long)hdr); return; } @@ -1226,13 +1226,13 @@ int atexit(void (*func)(void)) { void exit(int status) { for (int i = _atexit_count - 1; i >= 0; i--) _atexit_funcs[i](); - _zos_syscall1(SYS_EXIT, (long)status); + _mtk_syscall1(SYS_EXIT, (long)status); __builtin_unreachable(); } void abort(void) { - _zos_syscall1(SYS_PRINT, (long)"abort() called\n"); - _zos_syscall1(SYS_EXIT, 1); + _mtk_syscall1(SYS_PRINT, (long)"abort() called\n"); + _mtk_syscall1(SYS_EXIT, 1); __builtin_unreachable(); } @@ -1252,9 +1252,9 @@ static void _system_build_drive_path(int drive, const char *leaf, char *out, siz } static int _system_try_spawn(const char *path, const char *args) { - int pid = (int)_zos_syscall2(SYS_SPAWN, (long)path, (long)args); + int pid = (int)_mtk_syscall2(SYS_SPAWN, (long)path, (long)args); if (pid < 0) return -1; - _zos_syscall1(SYS_WAITPID, (long)pid); + _mtk_syscall1(SYS_WAITPID, (long)pid); return 0; } @@ -1611,18 +1611,18 @@ int printf(const char *fmt, ...) { va_start(ap, fmt); int ret = vsnprintf(_printbuf, sizeof(_printbuf), fmt, ap); va_end(ap); - _zos_syscall1(SYS_PRINT, (long)_printbuf); + _mtk_syscall1(SYS_PRINT, (long)_printbuf); return ret; } int puts(const char *s) { - _zos_syscall1(SYS_PRINT, (long)s); - _zos_syscall1(SYS_PUTCHAR, (long)'\n'); + _mtk_syscall1(SYS_PRINT, (long)s); + _mtk_syscall1(SYS_PUTCHAR, (long)'\n'); return 0; } int putchar(int c) { - _zos_syscall1(SYS_PUTCHAR, (long)c); + _mtk_syscall1(SYS_PUTCHAR, (long)c); return c; } @@ -1631,11 +1631,11 @@ int putchar(int c) { ======================================================================== */ void __assert_fail(const char *expr, const char *file, int line, const char *func) { - _zos_syscall1(SYS_PRINT, (long)"Assertion failed: "); - _zos_syscall1(SYS_PRINT, (long)expr); - _zos_syscall1(SYS_PRINT, (long)" at "); - _zos_syscall1(SYS_PRINT, (long)file); - _zos_syscall1(SYS_PRINT, (long)"\n"); + _mtk_syscall1(SYS_PRINT, (long)"Assertion failed: "); + _mtk_syscall1(SYS_PRINT, (long)expr); + _mtk_syscall1(SYS_PRINT, (long)" at "); + _mtk_syscall1(SYS_PRINT, (long)file); + _mtk_syscall1(SYS_PRINT, (long)"\n"); (void)line; (void)func; abort(); } @@ -1676,12 +1676,12 @@ static int _stdin_line_ready = 0; static void _stdin_echo_char(char c) { if (c == '\b') { - _zos_syscall1(SYS_PUTCHAR, '\b'); - _zos_syscall1(SYS_PUTCHAR, ' '); - _zos_syscall1(SYS_PUTCHAR, '\b'); + _mtk_syscall1(SYS_PUTCHAR, '\b'); + _mtk_syscall1(SYS_PUTCHAR, ' '); + _mtk_syscall1(SYS_PUTCHAR, '\b'); return; } - _zos_syscall1(SYS_PUTCHAR, (unsigned char)c); + _mtk_syscall1(SYS_PUTCHAR, (unsigned char)c); } /* Gather keystrokes into _stdin_linebuf. Returns 1 when a complete line is @@ -1697,8 +1697,8 @@ static int _stdin_pump(int block) { } for (;;) { - int c = block ? (int)_zos_syscall0(SYS_GETCHAR) - : (int)_zos_syscall0(SYS_GETCHAR_NB); + int c = block ? (int)_mtk_syscall0(SYS_GETCHAR) + : (int)_mtk_syscall0(SYS_GETCHAR_NB); if (c <= 0) { if (block) continue; return 0; @@ -1763,17 +1763,17 @@ FILE *fopen(const char *path, const char *mode) { want_write = 1; if (mode[1] == '+') want_read = 1; /* Truncate: delete then create */ - _zos_syscall1(SYS_FDELETE, (long)path); - handle = (int)_zos_syscall1(SYS_FCREATE, (long)path); + _mtk_syscall1(SYS_FDELETE, (long)path); + handle = (int)_mtk_syscall1(SYS_FCREATE, (long)path); if (handle < 0) return NULL; } else if (mode[0] == 'a') { want_write = 1; want_append = 1; if (mode[1] == '+') want_read = 1; /* Try open existing, create if not found */ - handle = (int)_zos_syscall1(SYS_OPEN, (long)path); + handle = (int)_mtk_syscall1(SYS_OPEN, (long)path); if (handle < 0) { - handle = (int)_zos_syscall1(SYS_FCREATE, (long)path); + handle = (int)_mtk_syscall1(SYS_FCREATE, (long)path); if (handle < 0) return NULL; } } else { @@ -1782,15 +1782,15 @@ FILE *fopen(const char *path, const char *mode) { /* For read and read+ modes, just open existing */ if (mode[0] == 'r') { - handle = (int)_zos_syscall1(SYS_OPEN, (long)path); + handle = (int)_mtk_syscall1(SYS_OPEN, (long)path); if (handle < 0) return NULL; } - unsigned long fileSize = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)handle); + unsigned long fileSize = (unsigned long)_mtk_syscall1(SYS_GETSIZE, (long)handle); FILE *f = (FILE *)malloc(sizeof(FILE)); if (f == NULL) { - _zos_syscall1(SYS_CLOSE, (long)handle); + _mtk_syscall1(SYS_CLOSE, (long)handle); return NULL; } @@ -1812,7 +1812,7 @@ int fclose(FILE *stream) { if (stream == NULL) return EOF; if (stream->is_std) return 0; - _zos_syscall1(SYS_CLOSE, (long)stream->handle); + _mtk_syscall1(SYS_CLOSE, (long)stream->handle); free(stream); return 0; } @@ -1843,7 +1843,7 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { } if (total == 0) return 0; - int ret = (int)_zos_syscall4(SYS_READ, (long)stream->handle, + int ret = (int)_mtk_syscall4(SYS_READ, (long)stream->handle, (long)ptr, (long)stream->pos, (long)total); if (ret < 0) { stream->error = 1; @@ -1862,12 +1862,12 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t total = size * nmemb; const char *src = (const char *)ptr; for (size_t i = 0; i < total; i++) - _zos_syscall1(SYS_PUTCHAR, (long)(unsigned char)src[i]); + _mtk_syscall1(SYS_PUTCHAR, (long)(unsigned char)src[i]); return nmemb; } size_t total = size * nmemb; - int ret = (int)_zos_syscall4(SYS_FWRITE, (long)stream->handle, + int ret = (int)_mtk_syscall4(SYS_FWRITE, (long)stream->handle, (long)ptr, (long)stream->pos, (long)total); if (ret < 0) { stream->error = 1; @@ -1916,7 +1916,7 @@ FILE *freopen(const char *path, const char *mode, FILE *stream) { if (fresh == NULL) return NULL; if (!stream->is_std) { - _zos_syscall1(SYS_CLOSE, (long)stream->handle); + _mtk_syscall1(SYS_CLOSE, (long)stream->handle); } *stream = *fresh; @@ -1974,7 +1974,7 @@ int fgetc(FILE *stream) { } unsigned char c; - int ret = (int)_zos_syscall4(SYS_READ, (long)stream->handle, + int ret = (int)_mtk_syscall4(SYS_READ, (long)stream->handle, (long)&c, (long)stream->pos, 1L); if (ret <= 0) { stream->eof = 1; @@ -2035,7 +2035,7 @@ int fprintf(FILE *stream, const char *fmt, ...) { va_end(ap); if (stream == NULL || stream->is_std) { - _zos_syscall1(SYS_PRINT, (long)buf); + _mtk_syscall1(SYS_PRINT, (long)buf); } else { fwrite(buf, 1, (size_t)(n > 0 ? n : 0), stream); } @@ -2047,7 +2047,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list ap) { int n = vsnprintf(buf, sizeof(buf), fmt, ap); if (stream == NULL || stream->is_std) { - _zos_syscall1(SYS_PRINT, (long)buf); + _mtk_syscall1(SYS_PRINT, (long)buf); } else { fwrite(buf, 1, (size_t)(n > 0 ? n : 0), stream); } @@ -2064,20 +2064,20 @@ int vsprintf(char *str, const char *fmt, va_list ap) { int remove(const char *path) { if (path == NULL) return -1; - return (int)_zos_syscall1(SYS_FDELETE, (long)path); + return (int)_mtk_syscall1(SYS_FDELETE, (long)path); } int rename(const char *oldpath, const char *newpath) { if (oldpath == NULL || newpath == NULL) return -1; - return (int)_zos_syscall2(SYS_FRENAME, (long)oldpath, (long)newpath); + return (int)_mtk_syscall2(SYS_FRENAME, (long)oldpath, (long)newpath); } void perror(const char *s) { if (s != NULL && s[0] != '\0') { - _zos_syscall1(SYS_PRINT, (long)s); - _zos_syscall1(SYS_PRINT, (long)": "); + _mtk_syscall1(SYS_PRINT, (long)s); + _mtk_syscall1(SYS_PRINT, (long)": "); } - _zos_syscall1(SYS_PRINT, (long)"error\n"); + _mtk_syscall1(SYS_PRINT, (long)"error\n"); } FILE *tmpfile(void) { @@ -2091,9 +2091,9 @@ char *tmpnam(char *s) { static unsigned long counter = 0; char *out = (s != NULL) ? s : internal; - _zos_syscall1(SYS_FMKDIR, (long)"0:/tmp"); + _mtk_syscall1(SYS_FMKDIR, (long)"0:/tmp"); snprintf(out, L_tmpnam, "0:/tmp/tmp%lu.tmp", - (unsigned long)_zos_syscall0(SYS_GETMILLISECONDS) + counter++); + (unsigned long)_mtk_syscall0(SYS_GETMILLISECONDS) + counter++); return out; } @@ -2213,9 +2213,9 @@ int access(const char *path, int mode) { (void)mode; - int h = (int)_zos_syscall1(SYS_OPEN, (long)path); + int h = (int)_mtk_syscall1(SYS_OPEN, (long)path); if (h >= 0) { - _zos_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); return 0; } @@ -2233,33 +2233,33 @@ int open(const char *path, int flags, ...) { return -1; } - int h = (int)_zos_syscall1(SYS_OPEN, (long)path); + int h = (int)_mtk_syscall1(SYS_OPEN, (long)path); int wants_create = (flags & O_CREAT) != 0; int wants_trunc = (flags & O_TRUNC) != 0; if (h < 0) { if (wants_create) { - h = (int)_zos_syscall1(SYS_FCREATE, (long)path); + h = (int)_mtk_syscall1(SYS_FCREATE, (long)path); } } else if (wants_create && (flags & O_EXCL)) { - _zos_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); errno = EEXIST; return -1; } else if (wants_trunc) { - _zos_syscall1(SYS_CLOSE, (long)h); - _zos_syscall1(SYS_FDELETE, (long)path); - h = (int)_zos_syscall1(SYS_FCREATE, (long)path); + _mtk_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_FDELETE, (long)path); + h = (int)_mtk_syscall1(SYS_FCREATE, (long)path); } if (h >= _FD_POS_MAX) { - _zos_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); errno = EMFILE; return -1; } if (h >= 0) { _fd_pos[h] = 0; if (flags & O_APPEND) { - _fd_pos[h] = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)h); + _fd_pos[h] = (unsigned long)_mtk_syscall1(SYS_GETSIZE, (long)h); } } if (h < 0) { @@ -2303,7 +2303,7 @@ int read(int fd, void *buf, size_t count) { } unsigned long pos = _fd_pos[fd]; - int ret = (int)_zos_syscall4(SYS_READ, (long)fd, (long)buf, (long)pos, (long)count); + int ret = (int)_mtk_syscall4(SYS_READ, (long)fd, (long)buf, (long)pos, (long)count); if (ret > 0) _fd_pos[fd] += (unsigned long)ret; return ret; @@ -2315,7 +2315,7 @@ int write(int fd, const void *buf, size_t count) { if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { const char *src = (const char *)buf; for (size_t i = 0; i < count; i++) - _zos_syscall1(SYS_PUTCHAR, (long)(unsigned char)src[i]); + _mtk_syscall1(SYS_PUTCHAR, (long)(unsigned char)src[i]); return (int)count; } @@ -2325,7 +2325,7 @@ int write(int fd, const void *buf, size_t count) { } unsigned long pos = _fd_pos[fd]; - int ret = (int)_zos_syscall4(SYS_FWRITE, (long)fd, (long)buf, (long)pos, (long)count); + int ret = (int)_mtk_syscall4(SYS_FWRITE, (long)fd, (long)buf, (long)pos, (long)count); if (ret > 0) _fd_pos[fd] += (unsigned long)ret; return ret; @@ -2348,7 +2348,7 @@ int ftruncate(int fd, long length) { return -1; } - size = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)fd); + size = (unsigned long)_mtk_syscall1(SYS_GETSIZE, (long)fd); if ((unsigned long)length == size) return 0; @@ -2362,7 +2362,7 @@ int ftruncate(int fd, long length) { unsigned long chunk = (unsigned long)length - size; int written; if (chunk > sizeof(zeros)) chunk = sizeof(zeros); - written = (int)_zos_syscall4(SYS_FWRITE, (long)fd, (long)zeros, + written = (int)_mtk_syscall4(SYS_FWRITE, (long)fd, (long)zeros, (long)size, (long)chunk); if (written <= 0) { errno = EIO; @@ -2389,7 +2389,7 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset) { errno = EINVAL; return -1; } - return (ssize_t)_zos_syscall4(SYS_READ, (long)fd, (long)buf, + return (ssize_t)_mtk_syscall4(SYS_READ, (long)fd, (long)buf, (long)offset, (long)count); } @@ -2402,7 +2402,7 @@ ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) { errno = EINVAL; return -1; } - return (ssize_t)_zos_syscall4(SYS_FWRITE, (long)fd, (long)buf, + return (ssize_t)_mtk_syscall4(SYS_FWRITE, (long)fd, (long)buf, (long)offset, (long)count); } @@ -2412,7 +2412,7 @@ int close(int fd) { return -1; } _fd_pos[fd] = 0; - if ((int)_zos_syscall1(SYS_CLOSE, (long)fd) < 0) { + if ((int)_mtk_syscall1(SYS_CLOSE, (long)fd) < 0) { errno = EBADF; return -1; } @@ -2435,7 +2435,7 @@ long lseek(int fd, long offset, int whence) { newpos = pos + (unsigned long)offset; break; case 2: /* SEEK_END */ - newpos = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)fd) + (unsigned long)offset; + newpos = (unsigned long)_mtk_syscall1(SYS_GETSIZE, (long)fd) + (unsigned long)offset; break; default: errno = EINVAL; @@ -2450,7 +2450,7 @@ int chdir(const char *path) { errno = EINVAL; return -1; } - if ((int)_zos_syscall1(SYS_CHDIR, (long)path) < 0) { + if ((int)_mtk_syscall1(SYS_CHDIR, (long)path) < 0) { errno = ENOENT; return -1; } @@ -2462,7 +2462,7 @@ char *getcwd(char *buf, size_t size) { errno = EINVAL; return NULL; } - int result = (int)_zos_syscall2(SYS_GETCWD, (long)buf, (long)size); + int result = (int)_mtk_syscall2(SYS_GETCWD, (long)buf, (long)size); if (result < 0) { errno = result == -2 ? ERANGE : EIO; return NULL; @@ -2473,7 +2473,7 @@ char *getcwd(char *buf, size_t size) { int isatty(int fd) { if (fd < STDIN_FILENO || fd > STDERR_FILENO) return 0; - return _zos_syscall0(SYS_TERMINAL_ATTACHED) != 0; + return _mtk_syscall0(SYS_TERMINAL_ATTACHED) != 0; } /* ======================================================================== @@ -2483,7 +2483,7 @@ int isatty(int fd) { int mkdir(const char *path, unsigned int mode) { (void)mode; if (path == NULL) return -1; - return (int)_zos_syscall1(SYS_FMKDIR, (long)path); + return (int)_mtk_syscall1(SYS_FMKDIR, (long)path); } /* The VFS exposes no inode numbers, so derive a stable id from the path and @@ -2512,7 +2512,7 @@ int stat(const char *path, struct stat *buf) { /* Preferred path: real metadata from the filesystem driver. */ struct _mtk_filestat st; - if (_zos_syscall2(SYS_STAT, (long)path, (long)&st) == 0) { + if (_mtk_syscall2(SYS_STAT, (long)path, (long)&st) == 0) { buf->st_mode = (mode_t)st.mode; /* A driver that reports no type bits still tells us whether the entry is a directory; without this S_ISREG/S_ISDIR both fail. */ @@ -2530,11 +2530,11 @@ int stat(const char *path, struct stat *buf) { /* Fallback for a filesystem whose driver has no Stat entry point: probe with open/readdir as before. Size is recoverable this way, timestamps and permissions are not. */ - int h = (int)_zos_syscall1(SYS_OPEN, (long)path); + int h = (int)_mtk_syscall1(SYS_OPEN, (long)path); if (h >= 0) { buf->st_mode = S_IFREG; - buf->st_size = (off_t)_zos_syscall1(SYS_GETSIZE, (long)h); - _zos_syscall1(SYS_CLOSE, (long)h); + buf->st_size = (off_t)_mtk_syscall1(SYS_GETSIZE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); buf->st_blocks = (blkcnt_t)((buf->st_size + 511) / 512); return 0; } @@ -2559,7 +2559,7 @@ int fstat(int fd, struct stat *buf) { cannot report real timestamps or permissions the way stat() does. Callers needing those must stat the path instead. */ buf->st_mode = S_IFREG; - buf->st_size = (off_t)_zos_syscall1(SYS_GETSIZE, (long)fd); + buf->st_size = (off_t)_mtk_syscall1(SYS_GETSIZE, (long)fd); /* Handles do not map back to paths, so fake a per-handle inode in a range disjoint from the path hashes used by stat(). */ buf->st_ino = 0x4000000000000000UL + (unsigned long)fd; @@ -2586,7 +2586,7 @@ DIR *opendir(const char *name) { } const char *raw_names[256]; - int count = (int)_zos_syscall3(SYS_READDIR, (long)name, (long)raw_names, 256L); + int count = (int)_mtk_syscall3(SYS_READDIR, (long)name, (long)raw_names, 256L); if (count < 0) { free(dir); errno = ENOTDIR; @@ -3219,7 +3219,7 @@ int raise(int sig) { ======================================================================== */ clock_t clock(void) { - return (clock_t)_zos_syscall0(SYS_GETMILLISECONDS); + return (clock_t)_mtk_syscall0(SYS_GETMILLISECONDS); } time_t time(time_t *tloc) { @@ -3426,7 +3426,7 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) { } int gettimeofday(struct timeval *tv, struct timezone *tz) { - long ms = (long)_zos_syscall0(SYS_GETMILLISECONDS); + long ms = (long)_mtk_syscall0(SYS_GETMILLISECONDS); if (tv != NULL) { tv->tv_sec = (long)time(NULL); @@ -3447,7 +3447,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) { ======================================================================== */ unsigned int sleep(unsigned int seconds) { - _zos_syscall1(SYS_SLEEP_MS, (long)seconds * 1000L); + _mtk_syscall1(SYS_SLEEP_MS, (long)seconds * 1000L); return 0; } @@ -3460,7 +3460,7 @@ int usleep(unsigned long usec) { unsigned long ms = usec / 1000UL; if (ms == 0 && usec != 0) ms = 1; - _zos_syscall1(SYS_SLEEP_MS, (long)ms); + _mtk_syscall1(SYS_SLEEP_MS, (long)ms); return 0; } @@ -3549,7 +3549,7 @@ int utime(const char *path, const struct utimbuf *times) { return -1; } - long result = _zos_syscall4(SYS_UTIME, (long)path, + long result = _mtk_syscall4(SYS_UTIME, (long)path, times != NULL ? (long)times->actime : 0, times != NULL ? (long)times->modtime : 0, times == NULL); @@ -3925,7 +3925,7 @@ int unlink(const char *path) { errno = EINVAL; return -1; } - if ((int)_zos_syscall1(SYS_FDELETE, (long)path) < 0) { + if ((int)_mtk_syscall1(SYS_FDELETE, (long)path) < 0) { errno = ENOENT; return -1; } @@ -3943,12 +3943,12 @@ int fcntl(int fd, int cmd, ...) { switch (cmd) { case F_GETFD: case F_GETFL: { - int probe = (int)_zos_syscall1(SYS_DUPHANDLE, (long)fd); + int probe = (int)_mtk_syscall1(SYS_DUPHANDLE, (long)fd); if (probe < 0) { errno = EBADF; return -1; } - _zos_syscall1(SYS_CLOSE, (long)probe); + _mtk_syscall1(SYS_CLOSE, (long)probe); return (cmd == F_GETFL) ? O_RDWR : 0; } case F_SETFD: @@ -3963,7 +3963,7 @@ int fcntl(int fd, int cmd, ...) { } pid_t getpid(void) { - return (pid_t)_zos_syscall0(SYS_GETPID); + return (pid_t)_mtk_syscall0(SYS_GETPID); } /* True dup2 needs kernel support for duplicating into a chosen slot. @@ -3976,22 +3976,22 @@ int dup2(int oldfd, int newfd) { return -1; } if (oldfd == newfd) { - int probe = (int)_zos_syscall1(SYS_DUPHANDLE, (long)oldfd); + int probe = (int)_mtk_syscall1(SYS_DUPHANDLE, (long)oldfd); if (probe < 0) { errno = EBADF; return -1; } - _zos_syscall1(SYS_CLOSE, (long)probe); + _mtk_syscall1(SYS_CLOSE, (long)probe); return newfd; } - _zos_syscall1(SYS_CLOSE, (long)newfd); - int h = (int)_zos_syscall1(SYS_DUPHANDLE, (long)oldfd); + _mtk_syscall1(SYS_CLOSE, (long)newfd); + int h = (int)_mtk_syscall1(SYS_DUPHANDLE, (long)oldfd); if (h < 0) { errno = EBADF; return -1; } if (h != newfd) { - _zos_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); errno = EBUSY; return -1; } @@ -4007,7 +4007,7 @@ pid_t waitpid(pid_t pid, int *status, int options) { errno = ECHILD; /* no process groups / wait-any support */ return -1; } - long code = _zos_syscall1(SYS_WAITPID, (long)pid); + long code = _mtk_syscall1(SYS_WAITPID, (long)pid); if (status != NULL) { if (code >= 256) { *status = (int)((code - 256) & 0x7F); /* signaled */ @@ -4019,7 +4019,7 @@ pid_t waitpid(pid_t pid, int *status, int options) { } void _exit(int status) { - _zos_syscall1(SYS_EXIT, (long)status); + _mtk_syscall1(SYS_EXIT, (long)status); __builtin_unreachable(); } @@ -4027,7 +4027,7 @@ void _exit(int status) { accepted for API shape but not delivered as a handler. */ int kill(pid_t pid, int sig) { (void)sig; - if ((int)_zos_syscall1(SYS_KILL, (long)pid) < 0) { + if ((int)_mtk_syscall1(SYS_KILL, (long)pid) < 0) { errno = ESRCH; return -1; } @@ -4071,7 +4071,7 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, errno = EINVAL; return MAP_FAILED; } - void *p = (void *)_zos_syscall2(SYS_MMAP_ANON, (long)length, (long)prot); + void *p = (void *)_mtk_syscall2(SYS_MMAP_ANON, (long)length, (long)prot); if (p == NULL) { errno = ENOMEM; return MAP_FAILED; @@ -4085,7 +4085,7 @@ int munmap(void *addr, size_t length) { errno = EINVAL; return -1; } - if (_zos_syscall2(SYS_MUNMAP, (long)addr, (long)length) < 0) { + if (_mtk_syscall2(SYS_MUNMAP, (long)addr, (long)length) < 0) { errno = EINVAL; return -1; } @@ -4100,7 +4100,7 @@ int mprotect(void *addr, size_t length, int prot) { errno = EINVAL; return -1; } - if (_zos_syscall3(SYS_MPROTECT, (long)addr, (long)length, (long)prot) < 0) { + if (_mtk_syscall3(SYS_MPROTECT, (long)addr, (long)length, (long)prot) < 0) { errno = EINVAL; return -1; } @@ -4225,7 +4225,7 @@ int posix_spawn(pid_t *pid, const char *path, long child; if (envp == NULL) { - child = _zos_syscall2(SYS_SPAWN, (long)path, (long)argsbuf); + child = _mtk_syscall2(SYS_SPAWN, (long)path, (long)argsbuf); } else { static char envbuf[4096]; size_t envlen = 0; @@ -4238,7 +4238,7 @@ int posix_spawn(pid_t *pid, const char *path, envlen += len; } envbuf[envlen++] = '\0'; - child = _zos_syscall4(SYS_SPAWN_ENV, (long)path, (long)argsbuf, + child = _mtk_syscall4(SYS_SPAWN_ENV, (long)path, (long)argsbuf, (long)envbuf, (long)envlen); } if (child < 0) { @@ -4362,13 +4362,13 @@ int dup(int fd) { errno = EBADF; return -1; } - int h = (int)_zos_syscall1(SYS_DUPHANDLE, (long)fd); + int h = (int)_mtk_syscall1(SYS_DUPHANDLE, (long)fd); if (h < 0) { errno = EBADF; return -1; } if (!_fd_pos_valid(h)) { - _zos_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); errno = EMFILE; return -1; } @@ -4399,7 +4399,7 @@ FILE *fdopen(int fd, const char *mode) { } f->handle = fd; f->pos = _fd_pos[fd]; - f->size = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)fd); + f->size = (unsigned long)_mtk_syscall1(SYS_GETSIZE, (long)fd); f->eof = 0; f->error = 0; f->is_std = 0; @@ -4458,7 +4458,7 @@ char *mktemp(char *template_) { } static const char cs[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - unsigned long seed = (unsigned long)_zos_syscall0(SYS_GETMILLISECONDS) + unsigned long seed = (unsigned long)_mtk_syscall0(SYS_GETMILLISECONDS) ^ ((unsigned long)getpid() << 16); for (int attempt = 0; attempt < 128; attempt++) { unsigned long v = seed + (unsigned long)attempt * 7919UL; @@ -4466,11 +4466,11 @@ char *mktemp(char *template_) { template_[len - 6 + i] = cs[v % (sizeof(cs) - 1)]; v /= sizeof(cs) - 1; } - int h = (int)_zos_syscall1(SYS_OPEN, (long)template_); + int h = (int)_mtk_syscall1(SYS_OPEN, (long)template_); if (h < 0) { return template_; /* name is free */ } - _zos_syscall1(SYS_CLOSE, (long)h); + _mtk_syscall1(SYS_CLOSE, (long)h); } template_[0] = '\0'; errno = EEXIST; @@ -4489,7 +4489,7 @@ int mkstemp(char *template_) { } static const char cs[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - unsigned long seed = (unsigned long)_zos_syscall0(SYS_GETMILLISECONDS) + unsigned long seed = (unsigned long)_mtk_syscall0(SYS_GETMILLISECONDS) ^ ((unsigned long)getpid() << 16); for (int attempt = 0; attempt < 128; attempt++) { unsigned long v = seed + (unsigned long)attempt * 7919UL;