Skip to content

Instantly share code, notes, and snippets.

@paranlee
Last active December 2, 2021 09:45
Show Gist options
  • Select an option

  • Save paranlee/8d71c42b07aad5e5d03075fdd53a6f97 to your computer and use it in GitHub Desktop.

Select an option

Save paranlee/8d71c42b07aad5e5d03075fdd53a6f97 to your computer and use it in GitHub Desktop.
/* https://elixir.bootlin.com/linux/latest/source/tools/include/nolibc/nolibc.h#L2114 */
/* nolibc.h::open() */
static __attribute__((unused))
int open(const char *path, int flags, mode_t mode)
{
int ret = sys_open(path, flags, mode);
if (ret < 0) {
SET_ERRNO(-ret);
ret = -1;
}
return ret;
}
/* arch/arm64/include/asm/unistd32.h::__NR_open */
#define __NR_open 5
/* https://elixir.bootlin.com/linux/latest/source/tools/include/nolibc/nolibc.h#L1625 */
/* nolibc.h::sys_open() */
static __attribute__((unused))
int sys_open(const char *path, int flags, mode_t mode)
{
#ifdef __NR_openat
return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
#elif defined(__NR_open)
return my_syscall3(__NR_open, path, flags, mode);
#else
#error Neither __NR_openat nor __NR_open defined, cannot implement sys_open()
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment