Merge pull request #3152 from Snektron/arm-support-improvement

Arm support improvement (part 1)
This commit is contained in:
Andrew Kelley 2019-09-04 14:39:36 -04:00 committed by GitHub
commit 090f2ffb82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 858 additions and 31 deletions

View File

@ -793,7 +793,7 @@ fn printLineInfo(
try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
}
} else |err| switch (err) {
error.EndOfFile => {},
error.EndOfFile, error.FileNotFound => {},
else => return err,
}
} else {
@ -1053,7 +1053,8 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
S.self_exe_file = try fs.openSelfExe();
errdefer S.self_exe_file.close();
const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size);
const self_exe_len = math.cast(usize, try S.self_exe_file.getEndPos()) catch return error.DebugInfoTooLarge;
const self_exe_mmap_len = mem.alignForward(self_exe_len, mem.page_size);
const self_exe_mmap = try os.mmap(
null,
self_exe_mmap_len,

View File

@ -261,9 +261,9 @@ pub const File = struct {
return Stat{
.size = @bitCast(u64, st.size),
.mode = st.mode,
.atime = atime.tv_sec * std.time.ns_per_s + atime.tv_nsec,
.mtime = mtime.tv_sec * std.time.ns_per_s + mtime.tv_nsec,
.ctime = ctime.tv_sec * std.time.ns_per_s + ctime.tv_nsec,
.atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
.mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
.ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
};
}

View File

@ -7,6 +7,7 @@ pub usingnamespace @import("linux/errno.zig");
pub usingnamespace switch (builtin.arch) {
.x86_64 => @import("linux/x86_64.zig"),
.aarch64 => @import("linux/arm64.zig"),
.arm => @import("linux/arm-eabi.zig"),
else => struct {},
};

View File

@ -0,0 +1,571 @@
// arm-eabi-specific declarations that are intended to be imported into the POSIX namespace.
const std = @import("../../std.zig");
const linux = std.os.linux;
const socklen_t = linux.socklen_t;
const iovec = linux.iovec;
const iovec_const = linux.iovec_const;
pub const SYS_restart_syscall = 0;
pub const SYS_exit = 1;
pub const SYS_fork = 2;
pub const SYS_read = 3;
pub const SYS_write = 4;
pub const SYS_open = 5;
pub const SYS_close = 6;
pub const SYS_creat = 8;
pub const SYS_link = 9;
pub const SYS_unlink = 10;
pub const SYS_execve = 11;
pub const SYS_chdir = 12;
pub const SYS_mknod = 14;
pub const SYS_chmod = 15;
pub const SYS_lchown = 16;
pub const SYS_lseek = 19;
pub const SYS_getpid = 20;
pub const SYS_mount = 21;
pub const SYS_setuid = 23;
pub const SYS_getuid = 24;
pub const SYS_ptrace = 26;
pub const SYS_pause = 29;
pub const SYS_access = 33;
pub const SYS_nice = 34;
pub const SYS_sync = 36;
pub const SYS_kill = 37;
pub const SYS_rename = 38;
pub const SYS_mkdir = 39;
pub const SYS_rmdir = 40;
pub const SYS_dup = 41;
pub const SYS_pipe = 42;
pub const SYS_times = 43;
pub const SYS_brk = 45;
pub const SYS_setgid = 46;
pub const SYS_getgid = 47;
pub const SYS_geteuid = 49;
pub const SYS_getegid = 50;
pub const SYS_acct = 51;
pub const SYS_umount2 = 52;
pub const SYS_ioctl = 54;
pub const SYS_fcntl = 55;
pub const SYS_setpgid = 57;
pub const SYS_umask = 60;
pub const SYS_chroot = 61;
pub const SYS_ustat = 62;
pub const SYS_dup2 = 63;
pub const SYS_getppid = 64;
pub const SYS_getpgrp = 65;
pub const SYS_setsid = 66;
pub const SYS_sigaction = 67;
pub const SYS_setreuid = 70;
pub const SYS_setregid = 71;
pub const SYS_sigsuspend = 72;
pub const SYS_sigpending = 73;
pub const SYS_sethostname = 74;
pub const SYS_setrlimit = 75;
pub const SYS_getrusage = 77;
pub const SYS_gettimeofday = 78;
pub const SYS_settimeofday = 79;
pub const SYS_getgroups = 80;
pub const SYS_setgroups = 81;
pub const SYS_symlink = 83;
pub const SYS_readlink = 85;
pub const SYS_uselib = 86;
pub const SYS_swapon = 87;
pub const SYS_reboot = 88;
pub const SYS_munmap = 91;
pub const SYS_truncate = 92;
pub const SYS_ftruncate = 93;
pub const SYS_fchmod = 94;
pub const SYS_fchown = 95;
pub const SYS_getpriority = 96;
pub const SYS_setpriority = 97;
pub const SYS_statfs = 99;
pub const SYS_fstatfs = 100;
pub const SYS_syslog = 103;
pub const SYS_setitimer = 104;
pub const SYS_getitimer = 105;
pub const SYS_stat = 106;
pub const SYS_lstat = 107;
pub const SYS_fstat = 108;
pub const SYS_vhangup = 111;
pub const SYS_wait4 = 114;
pub const SYS_swapoff = 115;
pub const SYS_sysinfo = 116;
pub const SYS_fsync = 118;
pub const SYS_sigreturn = 119;
pub const SYS_clone = 120;
pub const SYS_setdomainname = 121;
pub const SYS_uname = 122;
pub const SYS_adjtimex = 124;
pub const SYS_mprotect = 125;
pub const SYS_sigprocmask = 126;
pub const SYS_init_module = 128;
pub const SYS_delete_module = 129;
pub const SYS_quotactl = 131;
pub const SYS_getpgid = 132;
pub const SYS_fchdir = 133;
pub const SYS_bdflush = 134;
pub const SYS_sysfs = 135;
pub const SYS_personality = 136;
pub const SYS_setfsuid = 138;
pub const SYS_setfsgid = 139;
pub const SYS__llseek = 140;
pub const SYS_getdents = 141;
pub const SYS__newselect = 142;
pub const SYS_flock = 143;
pub const SYS_msync = 144;
pub const SYS_readv = 145;
pub const SYS_writev = 146;
pub const SYS_getsid = 147;
pub const SYS_fdatasync = 148;
pub const SYS__sysctl = 149;
pub const SYS_mlock = 150;
pub const SYS_munlock = 151;
pub const SYS_mlockall = 152;
pub const SYS_munlockall = 153;
pub const SYS_sched_setparam = 154;
pub const SYS_sched_getparam = 155;
pub const SYS_sched_setscheduler = 156;
pub const SYS_sched_getscheduler = 157;
pub const SYS_sched_yield = 158;
pub const SYS_sched_get_priority_max = 159;
pub const SYS_sched_get_priority_min = 160;
pub const SYS_sched_rr_get_interval = 161;
pub const SYS_nanosleep = 162;
pub const SYS_mremap = 163;
pub const SYS_setresuid = 164;
pub const SYS_getresuid = 165;
pub const SYS_poll = 168;
pub const SYS_nfsservctl = 169;
pub const SYS_setresgid = 170;
pub const SYS_getresgid = 171;
pub const SYS_prctl = 172;
pub const SYS_rt_sigreturn = 173;
pub const SYS_rt_sigaction = 174;
pub const SYS_rt_sigprocmask = 175;
pub const SYS_rt_sigpending = 176;
pub const SYS_rt_sigtimedwait = 177;
pub const SYS_rt_sigqueueinfo = 178;
pub const SYS_rt_sigsuspend = 179;
pub const SYS_pread64 = 180;
pub const SYS_pwrite64 = 181;
pub const SYS_chown = 182;
pub const SYS_getcwd = 183;
pub const SYS_capget = 184;
pub const SYS_capset = 185;
pub const SYS_sigaltstack = 186;
pub const SYS_sendfile = 187;
pub const SYS_vfork = 190;
pub const SYS_ugetrlimit = 191;
pub const SYS_mmap2 = 192;
pub const SYS_truncate64 = 193;
pub const SYS_ftruncate64 = 194;
pub const SYS_stat64 = 195;
pub const SYS_lstat64 = 196;
pub const SYS_fstat64 = 197;
pub const SYS_lchown32 = 198;
pub const SYS_getuid32 = 199;
pub const SYS_getgid32 = 200;
pub const SYS_geteuid32 = 201;
pub const SYS_getegid32 = 202;
pub const SYS_setreuid32 = 203;
pub const SYS_setregid32 = 204;
pub const SYS_getgroups32 = 205;
pub const SYS_setgroups32 = 206;
pub const SYS_fchown32 = 207;
pub const SYS_setresuid32 = 208;
pub const SYS_getresuid32 = 209;
pub const SYS_setresgid32 = 210;
pub const SYS_getresgid32 = 211;
pub const SYS_chown32 = 212;
pub const SYS_setuid32 = 213;
pub const SYS_setgid32 = 214;
pub const SYS_setfsuid32 = 215;
pub const SYS_setfsgid32 = 216;
pub const SYS_getdents64 = 217;
pub const SYS_pivot_root = 218;
pub const SYS_mincore = 219;
pub const SYS_madvise = 220;
pub const SYS_fcntl64 = 221;
pub const SYS_gettid = 224;
pub const SYS_readahead = 225;
pub const SYS_setxattr = 226;
pub const SYS_lsetxattr = 227;
pub const SYS_fsetxattr = 228;
pub const SYS_getxattr = 229;
pub const SYS_lgetxattr = 230;
pub const SYS_fgetxattr = 231;
pub const SYS_listxattr = 232;
pub const SYS_llistxattr = 233;
pub const SYS_flistxattr = 234;
pub const SYS_removexattr = 235;
pub const SYS_lremovexattr = 236;
pub const SYS_fremovexattr = 237;
pub const SYS_tkill = 238;
pub const SYS_sendfile64 = 239;
pub const SYS_futex = 240;
pub const SYS_sched_setaffinity = 241;
pub const SYS_sched_getaffinity = 242;
pub const SYS_io_setup = 243;
pub const SYS_io_destroy = 244;
pub const SYS_io_getevents = 245;
pub const SYS_io_submit = 246;
pub const SYS_io_cancel = 247;
pub const SYS_exit_group = 248;
pub const SYS_lookup_dcookie = 249;
pub const SYS_epoll_create = 250;
pub const SYS_epoll_ctl = 251;
pub const SYS_epoll_wait = 252;
pub const SYS_remap_file_pages = 253;
pub const SYS_set_tid_address = 256;
pub const SYS_timer_create = 257;
pub const SYS_timer_settime = 258;
pub const SYS_timer_gettime = 259;
pub const SYS_timer_getoverrun = 260;
pub const SYS_timer_delete = 261;
pub const SYS_clock_settime = 262;
pub const SYS_clock_gettime = 263;
pub const SYS_clock_getres = 264;
pub const SYS_clock_nanosleep = 265;
pub const SYS_statfs64 = 266;
pub const SYS_fstatfs64 = 267;
pub const SYS_tgkill = 268;
pub const SYS_utimes = 269;
pub const SYS_fadvise64_64 = 270;
pub const SYS_arm_fadvise64_64 = 270;
pub const SYS_pciconfig_iobase = 271;
pub const SYS_pciconfig_read = 272;
pub const SYS_pciconfig_write = 273;
pub const SYS_mq_open = 274;
pub const SYS_mq_unlink = 275;
pub const SYS_mq_timedsend = 276;
pub const SYS_mq_timedreceive = 277;
pub const SYS_mq_notify = 278;
pub const SYS_mq_getsetattr = 279;
pub const SYS_waitid = 280;
pub const SYS_socket = 281;
pub const SYS_bind = 282;
pub const SYS_connect = 283;
pub const SYS_listen = 284;
pub const SYS_accept = 285;
pub const SYS_getsockname = 286;
pub const SYS_getpeername = 287;
pub const SYS_socketpair = 288;
pub const SYS_send = 289;
pub const SYS_sendto = 290;
pub const SYS_recv = 291;
pub const SYS_recvfrom = 292;
pub const SYS_shutdown = 293;
pub const SYS_setsockopt = 294;
pub const SYS_getsockopt = 295;
pub const SYS_sendmsg = 296;
pub const SYS_recvmsg = 297;
pub const SYS_semop = 298;
pub const SYS_semget = 299;
pub const SYS_semctl = 300;
pub const SYS_msgsnd = 301;
pub const SYS_msgrcv = 302;
pub const SYS_msgget = 303;
pub const SYS_msgctl = 304;
pub const SYS_shmat = 305;
pub const SYS_shmdt = 306;
pub const SYS_shmget = 307;
pub const SYS_shmctl = 308;
pub const SYS_add_key = 309;
pub const SYS_request_key = 310;
pub const SYS_keyctl = 311;
pub const SYS_semtimedop = 312;
pub const SYS_vserver = 313;
pub const SYS_ioprio_set = 314;
pub const SYS_ioprio_get = 315;
pub const SYS_inotify_init = 316;
pub const SYS_inotify_add_watch = 317;
pub const SYS_inotify_rm_watch = 318;
pub const SYS_mbind = 319;
pub const SYS_get_mempolicy = 320;
pub const SYS_set_mempolicy = 321;
pub const SYS_openat = 322;
pub const SYS_mkdirat = 323;
pub const SYS_mknodat = 324;
pub const SYS_fchownat = 325;
pub const SYS_futimesat = 326;
pub const SYS_fstatat64 = 327;
pub const SYS_unlinkat = 328;
pub const SYS_renameat = 329;
pub const SYS_linkat = 330;
pub const SYS_symlinkat = 331;
pub const SYS_readlinkat = 332;
pub const SYS_fchmodat = 333;
pub const SYS_faccessat = 334;
pub const SYS_pselect6 = 335;
pub const SYS_ppoll = 336;
pub const SYS_unshare = 337;
pub const SYS_set_robust_list = 338;
pub const SYS_get_robust_list = 339;
pub const SYS_splice = 340;
pub const SYS_sync_file_range2 = 341;
pub const SYS_arm_sync_file_range = 341;
pub const SYS_tee = 342;
pub const SYS_vmsplice = 343;
pub const SYS_move_pages = 344;
pub const SYS_getcpu = 345;
pub const SYS_epoll_pwait = 346;
pub const SYS_kexec_load = 347;
pub const SYS_utimensat = 348;
pub const SYS_signalfd = 349;
pub const SYS_timerfd_create = 350;
pub const SYS_eventfd = 351;
pub const SYS_fallocate = 352;
pub const SYS_timerfd_settime = 353;
pub const SYS_timerfd_gettime = 354;
pub const SYS_signalfd4 = 355;
pub const SYS_eventfd2 = 356;
pub const SYS_epoll_create1 = 357;
pub const SYS_dup3 = 358;
pub const SYS_pipe2 = 359;
pub const SYS_inotify_init1 = 360;
pub const SYS_preadv = 361;
pub const SYS_pwritev = 362;
pub const SYS_rt_tgsigqueueinfo = 363;
pub const SYS_perf_event_open = 364;
pub const SYS_recvmmsg = 365;
pub const SYS_accept4 = 366;
pub const SYS_fanotify_init = 367;
pub const SYS_fanotify_mark = 368;
pub const SYS_prlimit64 = 369;
pub const SYS_name_to_handle_at = 370;
pub const SYS_open_by_handle_at = 371;
pub const SYS_clock_adjtime = 372;
pub const SYS_syncfs = 373;
pub const SYS_sendmmsg = 374;
pub const SYS_setns = 375;
pub const SYS_process_vm_readv = 376;
pub const SYS_process_vm_writev = 377;
pub const SYS_kcmp = 378;
pub const SYS_finit_module = 379;
pub const SYS_sched_setattr = 380;
pub const SYS_sched_getattr = 381;
pub const SYS_renameat2 = 382;
pub const SYS_seccomp = 383;
pub const SYS_getrandom = 384;
pub const SYS_memfd_create = 385;
pub const SYS_bpf = 386;
pub const SYS_execveat = 387;
pub const SYS_userfaultfd = 388;
pub const SYS_membarrier = 389;
pub const SYS_mlock2 = 390;
pub const SYS_copy_file_range = 391;
pub const SYS_preadv2 = 392;
pub const SYS_pwritev2 = 393;
pub const SYS_pkey_mprotect = 394;
pub const SYS_pkey_alloc = 395;
pub const SYS_pkey_free = 396;
pub const SYS_statx = 397;
pub const SYS_rseq = 398;
pub const SYS_io_pgetevents = 399;
pub const SYS_migrate_pages = 400;
pub const SYS_kexec_file_load = 401;
pub const SYS_clock_gettime64 = 403;
pub const SYS_clock_settime64 = 404;
pub const SYS_clock_adjtime64 = 405;
pub const SYS_clock_getres_time64 = 406;
pub const SYS_clock_nanosleep_time64 = 407;
pub const SYS_timer_gettime64 = 408;
pub const SYS_timer_settime64 = 409;
pub const SYS_timerfd_gettime64 = 410;
pub const SYS_timerfd_settime64 = 411;
pub const SYS_utimensat_time64 = 412;
pub const SYS_pselect6_time64 = 413;
pub const SYS_ppoll_time64 = 414;
pub const SYS_io_pgetevents_time64 = 416;
pub const SYS_recvmmsg_time64 = 417;
pub const SYS_mq_timedsend_time64 = 418;
pub const SYS_mq_timedreceive_time64 = 419;
pub const SYS_semtimedop_time64 = 420;
pub const SYS_rt_sigtimedwait_time64 = 421;
pub const SYS_futex_time64 = 422;
pub const SYS_sched_rr_get_interval_time64 = 423;
pub const SYS_pidfd_send_signal = 424;
pub const SYS_io_uring_setup = 425;
pub const SYS_io_uring_enter = 426;
pub const SYS_io_uring_register = 427;
pub const SYS_breakpoint = 0x0f0001;
pub const SYS_cacheflush = 0x0f0002;
pub const SYS_usr26 = 0x0f0003;
pub const SYS_usr32 = 0x0f0004;
pub const SYS_set_tls = 0x0f0005;
pub const SYS_get_tls = 0x0f0006;
pub const MMAP2_UNIT = 4096;
pub const O_CREAT = 0o100;
pub const O_EXCL = 0o200;
pub const O_NOCTTY = 0o400;
pub const O_TRUNC = 0o1000;
pub const O_APPEND = 0o2000;
pub const O_NONBLOCK = 0o4000;
pub const O_DSYNC = 0o10000;
pub const O_SYNC = 0o4010000;
pub const O_RSYNC = 0o4010000;
pub const O_DIRECTORY = 0o40000;
pub const O_NOFOLLOW = 0o100000;
pub const O_CLOEXEC = 0o2000000;
pub const O_ASYNC = 0o20000;
pub const O_DIRECT = 0o200000;
pub const O_LARGEFILE = 0o400000;
pub const O_NOATIME = 0o1000000;
pub const O_PATH = 0o10000000;
pub const O_TMPFILE = 0o20040000;
pub const O_NDELAY = O_NONBLOCK;
pub const F_DUPFD = 0;
pub const F_GETFD = 1;
pub const F_SETFD = 2;
pub const F_GETFL = 3;
pub const F_SETFL = 4;
pub const F_SETOWN = 8;
pub const F_GETOWN = 9;
pub const F_SETSIG = 10;
pub const F_GETSIG = 11;
pub const F_GETLK = 12;
pub const F_SETLK = 13;
pub const F_SETLKW = 14;
pub const F_SETOWN_EX = 15;
pub const F_GETOWN_EX = 16;
pub const F_GETOWNER_UIDS = 17;
/// stack-like segment
pub const MAP_GROWSDOWN = 0x0100;
/// ETXTBSY
pub const MAP_DENYWRITE = 0x0800;
/// mark it as an executable
pub const MAP_EXECUTABLE = 0x1000;
/// pages are locked
pub const MAP_LOCKED = 0x2000;
/// don't check for reservations
pub const MAP_NORESERVE = 0x4000;
/// populate (prefault) pagetables
pub const MAP_POPULATE = 0x8000;
/// do not block on IO
pub const MAP_NONBLOCK = 0x10000;
/// give out an address that is best suited for process/thread stacks
pub const MAP_STACK = 0x20000;
/// create a huge page mapping
pub const MAP_HUGETLB = 0x40000;
/// perform synchronous page faults for the mapping
pub const MAP_SYNC = 0x80000;
pub const VDSO_USEFUL = true;
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
pub const VDSO_CGT_VER = "LINUX_2.6";
pub const HWCAP_SWP = 1 << 0;
pub const HWCAP_HALF = 1 << 1;
pub const HWCAP_THUMB = 1 << 2;
pub const HWCAP_26BIT = 1 << 3;
pub const HWCAP_FAST_MULT = 1 << 4;
pub const HWCAP_FPA = 1 << 5;
pub const HWCAP_VFP = 1 << 6;
pub const HWCAP_EDSP = 1 << 7;
pub const HWCAP_JAVA = 1 << 8;
pub const HWCAP_IWMMXT = 1 << 9;
pub const HWCAP_CRUNCH = 1 << 10;
pub const HWCAP_THUMBEE = 1 << 11;
pub const HWCAP_NEON = 1 << 12;
pub const HWCAP_VFPv3 = 1 << 13;
pub const HWCAP_VFPv3D16 = 1 << 14;
pub const HWCAP_TLS = 1 << 15;
pub const HWCAP_VFPv4 = 1 << 16;
pub const HWCAP_IDIVA = 1 << 17;
pub const HWCAP_IDIVT = 1 << 18;
pub const HWCAP_VFPD32 = 1 << 19;
pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT;
pub const HWCAP_LPAE = 1 << 20;
pub const HWCAP_EVTSTRM = 1 << 21;
pub const msghdr = extern struct {
msg_name: ?*sockaddr,
msg_namelen: socklen_t,
msg_iov: [*]iovec,
msg_iovlen: i32,
msg_control: ?*c_void,
msg_controllen: socklen_t,
msg_flags: i32,
};
pub const msghdr_const = extern struct {
msg_name: ?*const sockaddr,
msg_namelen: socklen_t,
msg_iov: [*]iovec_const,
msg_iovlen: i32,
msg_control: ?*c_void,
msg_controllen: socklen_t,
msg_flags: i32,
};
/// Renamed to Stat to not conflict with the stat function.
/// atime, mtime, and ctime have functions to return `timespec`,
/// because although this is a POSIX API, the layout and names of
/// the structs are inconsistent across operating systems, and
/// in C, macros are used to hide the differences. Here we use
/// methods to accomplish this.
pub const Stat = extern struct {
dev: u64,
__dev_padding: u32,
__ino_truncated: u32,
mode: u32,
nlink: u32,
uid: u32,
gid: u32,
rdev: u64,
__rdev_padding: u32,
size: i64,
blksize: i32,
blocks: u64,
atim: timespec,
mtim: timespec,
ctim: timespec,
ino: u64,
pub fn atime(self: Stat) timespec {
return self.atim;
}
pub fn mtime(self: Stat) timespec {
return self.mtim;
}
pub fn ctime(self: Stat) timespec {
return self.ctim;
}
};
pub const timespec = extern struct {
tv_sec: i32,
tv_nsec: i32,
};
pub const timeval = extern struct {
tv_sec: i32,
tv_usec: i32,
};
pub const timezone = extern struct {
tz_minuteswest: i32,
tz_dsttime: i32,
};

View File

@ -17,6 +17,7 @@ pub const is_the_target = builtin.os == .linux;
pub usingnamespace switch (builtin.arch) {
.x86_64 => @import("linux/x86_64.zig"),
.aarch64 => @import("linux/arm64.zig"),
.arm => @import("linux/arm-eabi.zig"),
else => struct {},
};
pub usingnamespace @import("bits.zig");
@ -189,7 +190,11 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
}
pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
if (@hasDecl(@This(), "SYS_mmap2")) {
return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, @divTrunc(offset, MMAP2_UNIT)));
} else {
return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
}
}
pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {
@ -205,11 +210,26 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
}
pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
return syscall4(SYS_preadv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);
return syscall5(
SYS_preadv,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
@truncate(usize, offset),
@truncate(usize, offset >> 32),
);
}
pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
return syscall5(SYS_preadv2, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset, flags);
return syscall6(
SYS_preadv2,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
@truncate(usize, offset),
@truncate(usize, offset >> 32),
flags
);
}
pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
@ -221,11 +241,26 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
}
pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
return syscall4(SYS_pwritev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);
return syscall5(
SYS_pwritev,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
@truncate(usize, offset),
@truncate(usize, offset >> 32),
);
}
pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
return syscall5(SYS_pwritev2, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset, flags);
return syscall6(
SYS_pwritev2,
@bitCast(usize, isize(fd)),
@ptrToInt(iov),
count,
@truncate(usize, offset),
@truncate(usize, offset >> 32),
flags
);
}
// TODO https://github.com/ziglang/zig/issues/265
@ -481,67 +516,123 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
}
pub fn setuid(uid: u32) usize {
return syscall1(SYS_setuid, uid);
if (@hasDecl(@This(), "SYS_setuid32")) {
return syscall1(SYS_setuid32, uid);
} else {
return syscall1(SYS_setuid, uid);
}
}
pub fn setgid(gid: u32) usize {
return syscall1(SYS_setgid, gid);
if (@hasDecl(@This(), "SYS_setgid32")) {
return syscall1(SYS_setgid32, gid);
} else {
return syscall1(SYS_setgid, gid);
}
}
pub fn setreuid(ruid: u32, euid: u32) usize {
return syscall2(SYS_setreuid, ruid, euid);
if (@hasDecl(@This(), "SYS_setreuid32")) {
return syscall2(SYS_setreuid32, ruid, euid);
} else {
return syscall2(SYS_setreuid, ruid, euid);
}
}
pub fn setregid(rgid: u32, egid: u32) usize {
return syscall2(SYS_setregid, rgid, egid);
if (@hasDecl(@This(), "SYS_setregid32")) {
return syscall2(SYS_setregid32, rgid, egid);
} else {
return syscall2(SYS_setregid, rgid, egid);
}
}
pub fn getuid() u32 {
return u32(syscall0(SYS_getuid));
if (@hasDecl(@This(), "SYS_getuid32")) {
return u32(syscall0(SYS_getuid32));
} else {
return u32(syscall0(SYS_getuid));
}
}
pub fn getgid() u32 {
return u32(syscall0(SYS_getgid));
if (@hasDecl(@This(), "SYS_getgid32")) {
return u32(syscall0(SYS_getgid32));
} else {
return u32(syscall0(SYS_getgid));
}
}
pub fn geteuid() u32 {
return u32(syscall0(SYS_geteuid));
if (@hasDecl(@This(), "SYS_geteuid32")) {
return u32(syscall0(SYS_geteuid32));
} else {
return u32(syscall0(SYS_geteuid));
}
}
pub fn getegid() u32 {
return u32(syscall0(SYS_getegid));
if (@hasDecl(@This(), "SYS_getegid32")) {
return u32(syscall0(SYS_getegid32));
} else {
return u32(syscall0(SYS_getegid));
}
}
pub fn seteuid(euid: u32) usize {
return syscall1(SYS_seteuid, euid);
return setreuid(std.math.maxInt(u32), euid);
}
pub fn setegid(egid: u32) usize {
return syscall1(SYS_setegid, egid);
return setregid(std.math.maxInt(u32), egid);
}
pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize {
return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
if (@hasDecl(@This(), "SYS_getresuid32")) {
return syscall3(SYS_getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
} else {
return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
}
}
pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize {
return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
if (@hasDecl(@This(), "SYS_getresgid32")) {
return syscall3(SYS_getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
} else {
return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
}
}
pub fn setresuid(ruid: u32, euid: u32, suid: u32) usize {
return syscall3(SYS_setresuid, ruid, euid, suid);
if (@hasDecl(@This(), "SYS_setresuid32")) {
return syscall3(SYS_setresuid32, ruid, euid, suid);
} else {
return syscall3(SYS_setresuid, ruid, euid, suid);
}
}
pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {
return syscall3(SYS_setresgid, rgid, egid, sgid);
if (@hasDecl(@This(), "SYS_setresgid32")) {
return syscall3(SYS_setresgid32, rgid, egid, sgid);
} else {
return syscall3(SYS_setresgid, rgid, egid, sgid);
}
}
pub fn getgroups(size: usize, list: *u32) usize {
return syscall2(SYS_getgroups, size, @ptrToInt(list));
if (@hasDecl(@This(), "SYS_getgroups32")) {
return syscall2(SYS_getgroups32, size, @ptrToInt(list));
} else {
return syscall2(SYS_getgroups, size, @ptrToInt(list));
}
}
pub fn setgroups(size: usize, list: *const u32) usize {
return syscall2(SYS_setgroups, size, @ptrToInt(list));
if (@hasDecl(@This(), "SYS_setgroups32")) {
return syscall2(SYS_setgroups32, size, @ptrToInt(list));
} else {
return syscall2(SYS_setgroups, size, @ptrToInt(list));
}
}
pub fn getpid() i32 {
@ -708,22 +799,38 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags:
}
pub fn fstat(fd: i32, stat_buf: *Stat) usize {
return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
if (@hasDecl(@This(), "SYS_fstat64")) {
return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
} else {
return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
}
}
// TODO https://github.com/ziglang/zig/issues/265
pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
if (@hasDecl(@This(), "SYS_stat64")) {
return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
} else {
return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
}
}
// TODO https://github.com/ziglang/zig/issues/265
pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
if (@hasDecl(@This(), "SYS_lstat64")) {
return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
} else {
return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
}
}
// TODO https://github.com/ziglang/zig/issues/265
pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
if (@hasDecl(@This(), "SYS_fstatat64")) {
return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
} else {
return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
}
}
// TODO https://github.com/ziglang/zig/issues/265

96
std/os/linux/arm-eabi.zig Normal file
View File

@ -0,0 +1,96 @@
pub fn syscall0(number: usize) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number)
: "memory"
);
}
pub fn syscall1(number: usize, arg1: usize) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number),
[arg1] "{r0}" (arg1)
: "memory"
);
}
pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number),
[arg1] "{r0}" (arg1),
[arg2] "{r1}" (arg2)
: "memory"
);
}
pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number),
[arg1] "{r0}" (arg1),
[arg2] "{r1}" (arg2),
[arg3] "{r2}" (arg3)
: "memory"
);
}
pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number),
[arg1] "{r0}" (arg1),
[arg2] "{r1}" (arg2),
[arg3] "{r2}" (arg3),
[arg4] "{r3}" (arg4)
: "memory"
);
}
pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number),
[arg1] "{r0}" (arg1),
[arg2] "{r1}" (arg2),
[arg3] "{r2}" (arg3),
[arg4] "{r3}" (arg4),
[arg5] "{r4}" (arg5)
: "memory"
);
}
pub fn syscall6(
number: usize,
arg1: usize,
arg2: usize,
arg3: usize,
arg4: usize,
arg5: usize,
arg6: usize,
) usize {
return asm volatile ("svc #0"
: [ret] "={r0}" (-> usize)
: [number] "{r7}" (number),
[arg1] "{r0}" (arg1),
[arg2] "{r1}" (arg2),
[arg3] "{r2}" (arg3),
[arg4] "{r3}" (arg4),
[arg5] "{r4}" (arg5),
[arg6] "{r5}" (arg6)
: "memory"
);
}
/// This matches the libc clone function.
pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.
// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.
pub extern fn getThreadPointer() usize {
return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"
: [ret] "=r" (-> usize)
);
}

View File

@ -2,6 +2,7 @@ pub fn syscall0(number: usize) usize {
return asm volatile ("svc #0"
: [ret] "={x0}" (-> usize)
: [number] "{x8}" (number)
: "memory", "cc"
);
}
@ -10,6 +11,7 @@ pub fn syscall1(number: usize, arg1: usize) usize {
: [ret] "={x0}" (-> usize)
: [number] "{x8}" (number),
[arg1] "{x0}" (arg1)
: "memory", "cc"
);
}
@ -19,6 +21,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
: [number] "{x8}" (number),
[arg1] "{x0}" (arg1),
[arg2] "{x1}" (arg2)
: "memory", "cc"
);
}
@ -29,6 +32,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
[arg1] "{x0}" (arg1),
[arg2] "{x1}" (arg2),
[arg3] "{x2}" (arg3)
: "memory", "cc"
);
}
@ -40,6 +44,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
[arg2] "{x1}" (arg2),
[arg3] "{x2}" (arg3),
[arg4] "{x3}" (arg4)
: "memory", "cc"
);
}
@ -52,6 +57,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
[arg3] "{x2}" (arg3),
[arg4] "{x3}" (arg4),
[arg5] "{x4}" (arg5)
: "memory", "cc"
);
}
@ -73,6 +79,7 @@ pub fn syscall6(
[arg4] "{x3}" (arg4),
[arg5] "{x4}" (arg5),
[arg6] "{x5}" (arg6)
: "memory", "cc"
);
}

View File

@ -118,6 +118,9 @@ pub fn setThreadPointer(addr: usize) void {
: [addr] "r" (addr)
);
},
.arm => |arm| {
_ = std.os.linux.syscall1(std.os.linux.SYS_set_tls, addr);
},
else => @compileError("Unsupported architecture"),
}
}
@ -130,6 +133,7 @@ pub fn initTLS() void {
var at_phent: usize = undefined;
var at_phnum: usize = undefined;
var at_phdr: usize = undefined;
var at_hwcap: usize = undefined;
var i: usize = 0;
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
@ -137,6 +141,7 @@ pub fn initTLS() void {
elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,
elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,
elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,
elf.AT_HWCAP => at_phdr = auxv[i].a_un.a_val,
else => continue,
}
}
@ -156,6 +161,14 @@ pub fn initTLS() void {
}
if (tls_phdr) |phdr| {
// If the cpu is arm-based, check if it supports the TLS register
if (builtin.arch == builtin.Arch.arm and hwcap & std.os.linux.HWCAP_TLS == 0) {
// If the CPU does not support TLS via a coprocessor register,
// a kernel helper function can be used instead on certain linux kernels.
// See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.
@panic("TODO: Implement ARM fallback TLS functionality");
}
// Offsets into the allocated TLS area
var tcb_offset: usize = undefined;
var dtv_offset: usize = undefined;

View File

@ -25,6 +25,8 @@ comptime {
@export("strncmp", strncmp, .Strong);
@export("strerror", strerror, .Strong);
@export("strlen", strlen, .Strong);
} else if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) {
@export("__aeabi_read_tp", std.os.linux.getThreadPointer, .Strong);
}
}
@ -238,6 +240,35 @@ nakedcc fn clone() void {
\\ mov x8,#93 // SYS_exit
\\ svc #0
);
} else if (builtin.arch == builtin.Arch.arm) {
asm volatile (
\\ stmfd sp!,{r4,r5,r6,r7}
\\ mov r7,#120
\\ mov r6,r3
\\ mov r5,r0
\\ mov r0,r2
\\ and r1,r1,#-16
\\ ldr r2,[sp,#16]
\\ ldr r3,[sp,#20]
\\ ldr r4,[sp,#24]
\\ svc 0
\\ tst r0,r0
\\ beq 1f
\\ ldmfd sp!,{r4,r5,r6,r7}
\\ bx lr
\\
\\1: mov r0,r6
\\ tst r5,#1
\\ bne 1f
\\ mov lr,pc
\\ mov pc,r5
\\2: mov r7,#1
\\ svc 0
\\
\\1: mov lr,pc
\\ bx r5
\\ b 2b
);
} else {
@compileError("Implement clone() for this arch.");
}

View File

@ -44,7 +44,7 @@ nakedcc fn _start() noreturn {
: [argc] "={esp}" (-> [*]usize)
);
},
.aarch64, .aarch64_be => {
.aarch64, .aarch64_be, .arm => {
argc_ptr = asm ("mov %[argc], sp"
: [argc] "=r" (-> [*]usize)
);