authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-04 14:39:36-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-09-04 14:39:36-04:00
log090f2ffb820ab10773322636d3c940bbfd6028be
tree7a36bef3a48854cb08cb9bbc6a727212f0ff7858
parente540e5b8ec1d90b86d6f41814507e6ae4ae5edd8
parentdf06976e73e37a36009fb5f43c2310ad610a4a2e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

Arm support improvement (part 1)

10 files changed, 858 insertions(+), 31 deletions(-)

std/debug.zig+3-2
......@@ -793,7 +793,7 @@ fn printLineInfo(
793793 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
794794 }
795795 } else |err| switch (err) {
796 error.EndOfFile => {},
796 error.EndOfFile, error.FileNotFound => {},
797797 else => return err,
798798 }
799799 } else {
......@@ -1053,7 +1053,8 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
10531053 S.self_exe_file = try fs.openSelfExe();
10541054 errdefer S.self_exe_file.close();
10551055
1056 const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size);
1056 const self_exe_len = math.cast(usize, try S.self_exe_file.getEndPos()) catch return error.DebugInfoTooLarge;
1057 const self_exe_mmap_len = mem.alignForward(self_exe_len, mem.page_size);
10571058 const self_exe_mmap = try os.mmap(
10581059 null,
10591060 self_exe_mmap_len,
std/fs/file.zig+3-3
......@@ -261,9 +261,9 @@ pub const File = struct {
261261 return Stat{
262262 .size = @bitCast(u64, st.size),
263263 .mode = st.mode,
264 .atime = atime.tv_sec * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = mtime.tv_sec * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = ctime.tv_sec * std.time.ns_per_s + ctime.tv_nsec,
264 .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
267267 };
268268 }
269269
std/os/bits/linux.zig+1
......@@ -7,6 +7,7 @@ pub usingnamespace @import("linux/errno.zig");
77pub usingnamespace switch (builtin.arch) {
88 .x86_64 => @import("linux/x86_64.zig"),
99 .aarch64 => @import("linux/arm64.zig"),
10 .arm => @import("linux/arm-eabi.zig"),
1011 else => struct {},
1112};
1213
std/os/bits/linux/arm-eabi.zig created+571
......@@ -0,0 +1,571 @@
1// arm-eabi-specific declarations that are intended to be imported into the POSIX namespace.
2
3const std = @import("../../std.zig");
4const linux = std.os.linux;
5const socklen_t = linux.socklen_t;
6const iovec = linux.iovec;
7const iovec_const = linux.iovec_const;
8
9pub const SYS_restart_syscall = 0;
10pub const SYS_exit = 1;
11pub const SYS_fork = 2;
12pub const SYS_read = 3;
13pub const SYS_write = 4;
14pub const SYS_open = 5;
15pub const SYS_close = 6;
16pub const SYS_creat = 8;
17pub const SYS_link = 9;
18pub const SYS_unlink = 10;
19pub const SYS_execve = 11;
20pub const SYS_chdir = 12;
21pub const SYS_mknod = 14;
22pub const SYS_chmod = 15;
23pub const SYS_lchown = 16;
24pub const SYS_lseek = 19;
25pub const SYS_getpid = 20;
26pub const SYS_mount = 21;
27pub const SYS_setuid = 23;
28pub const SYS_getuid = 24;
29pub const SYS_ptrace = 26;
30pub const SYS_pause = 29;
31pub const SYS_access = 33;
32pub const SYS_nice = 34;
33pub const SYS_sync = 36;
34pub const SYS_kill = 37;
35pub const SYS_rename = 38;
36pub const SYS_mkdir = 39;
37pub const SYS_rmdir = 40;
38pub const SYS_dup = 41;
39pub const SYS_pipe = 42;
40pub const SYS_times = 43;
41pub const SYS_brk = 45;
42pub const SYS_setgid = 46;
43pub const SYS_getgid = 47;
44pub const SYS_geteuid = 49;
45pub const SYS_getegid = 50;
46pub const SYS_acct = 51;
47pub const SYS_umount2 = 52;
48pub const SYS_ioctl = 54;
49pub const SYS_fcntl = 55;
50pub const SYS_setpgid = 57;
51pub const SYS_umask = 60;
52pub const SYS_chroot = 61;
53pub const SYS_ustat = 62;
54pub const SYS_dup2 = 63;
55pub const SYS_getppid = 64;
56pub const SYS_getpgrp = 65;
57pub const SYS_setsid = 66;
58pub const SYS_sigaction = 67;
59pub const SYS_setreuid = 70;
60pub const SYS_setregid = 71;
61pub const SYS_sigsuspend = 72;
62pub const SYS_sigpending = 73;
63pub const SYS_sethostname = 74;
64pub const SYS_setrlimit = 75;
65pub const SYS_getrusage = 77;
66pub const SYS_gettimeofday = 78;
67pub const SYS_settimeofday = 79;
68pub const SYS_getgroups = 80;
69pub const SYS_setgroups = 81;
70pub const SYS_symlink = 83;
71pub const SYS_readlink = 85;
72pub const SYS_uselib = 86;
73pub const SYS_swapon = 87;
74pub const SYS_reboot = 88;
75pub const SYS_munmap = 91;
76pub const SYS_truncate = 92;
77pub const SYS_ftruncate = 93;
78pub const SYS_fchmod = 94;
79pub const SYS_fchown = 95;
80pub const SYS_getpriority = 96;
81pub const SYS_setpriority = 97;
82pub const SYS_statfs = 99;
83pub const SYS_fstatfs = 100;
84pub const SYS_syslog = 103;
85pub const SYS_setitimer = 104;
86pub const SYS_getitimer = 105;
87pub const SYS_stat = 106;
88pub const SYS_lstat = 107;
89pub const SYS_fstat = 108;
90pub const SYS_vhangup = 111;
91pub const SYS_wait4 = 114;
92pub const SYS_swapoff = 115;
93pub const SYS_sysinfo = 116;
94pub const SYS_fsync = 118;
95pub const SYS_sigreturn = 119;
96pub const SYS_clone = 120;
97pub const SYS_setdomainname = 121;
98pub const SYS_uname = 122;
99pub const SYS_adjtimex = 124;
100pub const SYS_mprotect = 125;
101pub const SYS_sigprocmask = 126;
102pub const SYS_init_module = 128;
103pub const SYS_delete_module = 129;
104pub const SYS_quotactl = 131;
105pub const SYS_getpgid = 132;
106pub const SYS_fchdir = 133;
107pub const SYS_bdflush = 134;
108pub const SYS_sysfs = 135;
109pub const SYS_personality = 136;
110pub const SYS_setfsuid = 138;
111pub const SYS_setfsgid = 139;
112pub const SYS__llseek = 140;
113pub const SYS_getdents = 141;
114pub const SYS__newselect = 142;
115pub const SYS_flock = 143;
116pub const SYS_msync = 144;
117pub const SYS_readv = 145;
118pub const SYS_writev = 146;
119pub const SYS_getsid = 147;
120pub const SYS_fdatasync = 148;
121pub const SYS__sysctl = 149;
122pub const SYS_mlock = 150;
123pub const SYS_munlock = 151;
124pub const SYS_mlockall = 152;
125pub const SYS_munlockall = 153;
126pub const SYS_sched_setparam = 154;
127pub const SYS_sched_getparam = 155;
128pub const SYS_sched_setscheduler = 156;
129pub const SYS_sched_getscheduler = 157;
130pub const SYS_sched_yield = 158;
131pub const SYS_sched_get_priority_max = 159;
132pub const SYS_sched_get_priority_min = 160;
133pub const SYS_sched_rr_get_interval = 161;
134pub const SYS_nanosleep = 162;
135pub const SYS_mremap = 163;
136pub const SYS_setresuid = 164;
137pub const SYS_getresuid = 165;
138pub const SYS_poll = 168;
139pub const SYS_nfsservctl = 169;
140pub const SYS_setresgid = 170;
141pub const SYS_getresgid = 171;
142pub const SYS_prctl = 172;
143pub const SYS_rt_sigreturn = 173;
144pub const SYS_rt_sigaction = 174;
145pub const SYS_rt_sigprocmask = 175;
146pub const SYS_rt_sigpending = 176;
147pub const SYS_rt_sigtimedwait = 177;
148pub const SYS_rt_sigqueueinfo = 178;
149pub const SYS_rt_sigsuspend = 179;
150pub const SYS_pread64 = 180;
151pub const SYS_pwrite64 = 181;
152pub const SYS_chown = 182;
153pub const SYS_getcwd = 183;
154pub const SYS_capget = 184;
155pub const SYS_capset = 185;
156pub const SYS_sigaltstack = 186;
157pub const SYS_sendfile = 187;
158pub const SYS_vfork = 190;
159pub const SYS_ugetrlimit = 191;
160pub const SYS_mmap2 = 192;
161pub const SYS_truncate64 = 193;
162pub const SYS_ftruncate64 = 194;
163pub const SYS_stat64 = 195;
164pub const SYS_lstat64 = 196;
165pub const SYS_fstat64 = 197;
166pub const SYS_lchown32 = 198;
167pub const SYS_getuid32 = 199;
168pub const SYS_getgid32 = 200;
169pub const SYS_geteuid32 = 201;
170pub const SYS_getegid32 = 202;
171pub const SYS_setreuid32 = 203;
172pub const SYS_setregid32 = 204;
173pub const SYS_getgroups32 = 205;
174pub const SYS_setgroups32 = 206;
175pub const SYS_fchown32 = 207;
176pub const SYS_setresuid32 = 208;
177pub const SYS_getresuid32 = 209;
178pub const SYS_setresgid32 = 210;
179pub const SYS_getresgid32 = 211;
180pub const SYS_chown32 = 212;
181pub const SYS_setuid32 = 213;
182pub const SYS_setgid32 = 214;
183pub const SYS_setfsuid32 = 215;
184pub const SYS_setfsgid32 = 216;
185pub const SYS_getdents64 = 217;
186pub const SYS_pivot_root = 218;
187pub const SYS_mincore = 219;
188pub const SYS_madvise = 220;
189pub const SYS_fcntl64 = 221;
190pub const SYS_gettid = 224;
191pub const SYS_readahead = 225;
192pub const SYS_setxattr = 226;
193pub const SYS_lsetxattr = 227;
194pub const SYS_fsetxattr = 228;
195pub const SYS_getxattr = 229;
196pub const SYS_lgetxattr = 230;
197pub const SYS_fgetxattr = 231;
198pub const SYS_listxattr = 232;
199pub const SYS_llistxattr = 233;
200pub const SYS_flistxattr = 234;
201pub const SYS_removexattr = 235;
202pub const SYS_lremovexattr = 236;
203pub const SYS_fremovexattr = 237;
204pub const SYS_tkill = 238;
205pub const SYS_sendfile64 = 239;
206pub const SYS_futex = 240;
207pub const SYS_sched_setaffinity = 241;
208pub const SYS_sched_getaffinity = 242;
209pub const SYS_io_setup = 243;
210pub const SYS_io_destroy = 244;
211pub const SYS_io_getevents = 245;
212pub const SYS_io_submit = 246;
213pub const SYS_io_cancel = 247;
214pub const SYS_exit_group = 248;
215pub const SYS_lookup_dcookie = 249;
216pub const SYS_epoll_create = 250;
217pub const SYS_epoll_ctl = 251;
218pub const SYS_epoll_wait = 252;
219pub const SYS_remap_file_pages = 253;
220pub const SYS_set_tid_address = 256;
221pub const SYS_timer_create = 257;
222pub const SYS_timer_settime = 258;
223pub const SYS_timer_gettime = 259;
224pub const SYS_timer_getoverrun = 260;
225pub const SYS_timer_delete = 261;
226pub const SYS_clock_settime = 262;
227pub const SYS_clock_gettime = 263;
228pub const SYS_clock_getres = 264;
229pub const SYS_clock_nanosleep = 265;
230pub const SYS_statfs64 = 266;
231pub const SYS_fstatfs64 = 267;
232pub const SYS_tgkill = 268;
233pub const SYS_utimes = 269;
234pub const SYS_fadvise64_64 = 270;
235pub const SYS_arm_fadvise64_64 = 270;
236pub const SYS_pciconfig_iobase = 271;
237pub const SYS_pciconfig_read = 272;
238pub const SYS_pciconfig_write = 273;
239pub const SYS_mq_open = 274;
240pub const SYS_mq_unlink = 275;
241pub const SYS_mq_timedsend = 276;
242pub const SYS_mq_timedreceive = 277;
243pub const SYS_mq_notify = 278;
244pub const SYS_mq_getsetattr = 279;
245pub const SYS_waitid = 280;
246pub const SYS_socket = 281;
247pub const SYS_bind = 282;
248pub const SYS_connect = 283;
249pub const SYS_listen = 284;
250pub const SYS_accept = 285;
251pub const SYS_getsockname = 286;
252pub const SYS_getpeername = 287;
253pub const SYS_socketpair = 288;
254pub const SYS_send = 289;
255pub const SYS_sendto = 290;
256pub const SYS_recv = 291;
257pub const SYS_recvfrom = 292;
258pub const SYS_shutdown = 293;
259pub const SYS_setsockopt = 294;
260pub const SYS_getsockopt = 295;
261pub const SYS_sendmsg = 296;
262pub const SYS_recvmsg = 297;
263pub const SYS_semop = 298;
264pub const SYS_semget = 299;
265pub const SYS_semctl = 300;
266pub const SYS_msgsnd = 301;
267pub const SYS_msgrcv = 302;
268pub const SYS_msgget = 303;
269pub const SYS_msgctl = 304;
270pub const SYS_shmat = 305;
271pub const SYS_shmdt = 306;
272pub const SYS_shmget = 307;
273pub const SYS_shmctl = 308;
274pub const SYS_add_key = 309;
275pub const SYS_request_key = 310;
276pub const SYS_keyctl = 311;
277pub const SYS_semtimedop = 312;
278pub const SYS_vserver = 313;
279pub const SYS_ioprio_set = 314;
280pub const SYS_ioprio_get = 315;
281pub const SYS_inotify_init = 316;
282pub const SYS_inotify_add_watch = 317;
283pub const SYS_inotify_rm_watch = 318;
284pub const SYS_mbind = 319;
285pub const SYS_get_mempolicy = 320;
286pub const SYS_set_mempolicy = 321;
287pub const SYS_openat = 322;
288pub const SYS_mkdirat = 323;
289pub const SYS_mknodat = 324;
290pub const SYS_fchownat = 325;
291pub const SYS_futimesat = 326;
292pub const SYS_fstatat64 = 327;
293pub const SYS_unlinkat = 328;
294pub const SYS_renameat = 329;
295pub const SYS_linkat = 330;
296pub const SYS_symlinkat = 331;
297pub const SYS_readlinkat = 332;
298pub const SYS_fchmodat = 333;
299pub const SYS_faccessat = 334;
300pub const SYS_pselect6 = 335;
301pub const SYS_ppoll = 336;
302pub const SYS_unshare = 337;
303pub const SYS_set_robust_list = 338;
304pub const SYS_get_robust_list = 339;
305pub const SYS_splice = 340;
306pub const SYS_sync_file_range2 = 341;
307pub const SYS_arm_sync_file_range = 341;
308pub const SYS_tee = 342;
309pub const SYS_vmsplice = 343;
310pub const SYS_move_pages = 344;
311pub const SYS_getcpu = 345;
312pub const SYS_epoll_pwait = 346;
313pub const SYS_kexec_load = 347;
314pub const SYS_utimensat = 348;
315pub const SYS_signalfd = 349;
316pub const SYS_timerfd_create = 350;
317pub const SYS_eventfd = 351;
318pub const SYS_fallocate = 352;
319pub const SYS_timerfd_settime = 353;
320pub const SYS_timerfd_gettime = 354;
321pub const SYS_signalfd4 = 355;
322pub const SYS_eventfd2 = 356;
323pub const SYS_epoll_create1 = 357;
324pub const SYS_dup3 = 358;
325pub const SYS_pipe2 = 359;
326pub const SYS_inotify_init1 = 360;
327pub const SYS_preadv = 361;
328pub const SYS_pwritev = 362;
329pub const SYS_rt_tgsigqueueinfo = 363;
330pub const SYS_perf_event_open = 364;
331pub const SYS_recvmmsg = 365;
332pub const SYS_accept4 = 366;
333pub const SYS_fanotify_init = 367;
334pub const SYS_fanotify_mark = 368;
335pub const SYS_prlimit64 = 369;
336pub const SYS_name_to_handle_at = 370;
337pub const SYS_open_by_handle_at = 371;
338pub const SYS_clock_adjtime = 372;
339pub const SYS_syncfs = 373;
340pub const SYS_sendmmsg = 374;
341pub const SYS_setns = 375;
342pub const SYS_process_vm_readv = 376;
343pub const SYS_process_vm_writev = 377;
344pub const SYS_kcmp = 378;
345pub const SYS_finit_module = 379;
346pub const SYS_sched_setattr = 380;
347pub const SYS_sched_getattr = 381;
348pub const SYS_renameat2 = 382;
349pub const SYS_seccomp = 383;
350pub const SYS_getrandom = 384;
351pub const SYS_memfd_create = 385;
352pub const SYS_bpf = 386;
353pub const SYS_execveat = 387;
354pub const SYS_userfaultfd = 388;
355pub const SYS_membarrier = 389;
356pub const SYS_mlock2 = 390;
357pub const SYS_copy_file_range = 391;
358pub const SYS_preadv2 = 392;
359pub const SYS_pwritev2 = 393;
360pub const SYS_pkey_mprotect = 394;
361pub const SYS_pkey_alloc = 395;
362pub const SYS_pkey_free = 396;
363pub const SYS_statx = 397;
364pub const SYS_rseq = 398;
365pub const SYS_io_pgetevents = 399;
366pub const SYS_migrate_pages = 400;
367pub const SYS_kexec_file_load = 401;
368pub const SYS_clock_gettime64 = 403;
369pub const SYS_clock_settime64 = 404;
370pub const SYS_clock_adjtime64 = 405;
371pub const SYS_clock_getres_time64 = 406;
372pub const SYS_clock_nanosleep_time64 = 407;
373pub const SYS_timer_gettime64 = 408;
374pub const SYS_timer_settime64 = 409;
375pub const SYS_timerfd_gettime64 = 410;
376pub const SYS_timerfd_settime64 = 411;
377pub const SYS_utimensat_time64 = 412;
378pub const SYS_pselect6_time64 = 413;
379pub const SYS_ppoll_time64 = 414;
380pub const SYS_io_pgetevents_time64 = 416;
381pub const SYS_recvmmsg_time64 = 417;
382pub const SYS_mq_timedsend_time64 = 418;
383pub const SYS_mq_timedreceive_time64 = 419;
384pub const SYS_semtimedop_time64 = 420;
385pub const SYS_rt_sigtimedwait_time64 = 421;
386pub const SYS_futex_time64 = 422;
387pub const SYS_sched_rr_get_interval_time64 = 423;
388pub const SYS_pidfd_send_signal = 424;
389pub const SYS_io_uring_setup = 425;
390pub const SYS_io_uring_enter = 426;
391pub const SYS_io_uring_register = 427;
392
393pub const SYS_breakpoint = 0x0f0001;
394pub const SYS_cacheflush = 0x0f0002;
395pub const SYS_usr26 = 0x0f0003;
396pub const SYS_usr32 = 0x0f0004;
397pub const SYS_set_tls = 0x0f0005;
398pub const SYS_get_tls = 0x0f0006;
399
400pub const MMAP2_UNIT = 4096;
401
402pub const O_CREAT = 0o100;
403pub const O_EXCL = 0o200;
404pub const O_NOCTTY = 0o400;
405pub const O_TRUNC = 0o1000;
406pub const O_APPEND = 0o2000;
407pub const O_NONBLOCK = 0o4000;
408pub const O_DSYNC = 0o10000;
409pub const O_SYNC = 0o4010000;
410pub const O_RSYNC = 0o4010000;
411pub const O_DIRECTORY = 0o40000;
412pub const O_NOFOLLOW = 0o100000;
413pub const O_CLOEXEC = 0o2000000;
414
415pub const O_ASYNC = 0o20000;
416pub const O_DIRECT = 0o200000;
417pub const O_LARGEFILE = 0o400000;
418pub const O_NOATIME = 0o1000000;
419pub const O_PATH = 0o10000000;
420pub const O_TMPFILE = 0o20040000;
421pub const O_NDELAY = O_NONBLOCK;
422
423pub const F_DUPFD = 0;
424pub const F_GETFD = 1;
425pub const F_SETFD = 2;
426pub const F_GETFL = 3;
427pub const F_SETFL = 4;
428
429pub const F_SETOWN = 8;
430pub const F_GETOWN = 9;
431pub const F_SETSIG = 10;
432pub const F_GETSIG = 11;
433
434pub const F_GETLK = 12;
435pub const F_SETLK = 13;
436pub const F_SETLKW = 14;
437
438pub const F_SETOWN_EX = 15;
439pub const F_GETOWN_EX = 16;
440
441pub const F_GETOWNER_UIDS = 17;
442
443/// stack-like segment
444pub const MAP_GROWSDOWN = 0x0100;
445
446/// ETXTBSY
447pub const MAP_DENYWRITE = 0x0800;
448
449/// mark it as an executable
450pub const MAP_EXECUTABLE = 0x1000;
451
452/// pages are locked
453pub const MAP_LOCKED = 0x2000;
454
455/// don't check for reservations
456pub const MAP_NORESERVE = 0x4000;
457
458/// populate (prefault) pagetables
459pub const MAP_POPULATE = 0x8000;
460
461/// do not block on IO
462pub const MAP_NONBLOCK = 0x10000;
463
464/// give out an address that is best suited for process/thread stacks
465pub const MAP_STACK = 0x20000;
466
467/// create a huge page mapping
468pub const MAP_HUGETLB = 0x40000;
469
470/// perform synchronous page faults for the mapping
471pub const MAP_SYNC = 0x80000;
472
473pub const VDSO_USEFUL = true;
474pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
475pub const VDSO_CGT_VER = "LINUX_2.6";
476
477pub const HWCAP_SWP = 1 << 0;
478pub const HWCAP_HALF = 1 << 1;
479pub const HWCAP_THUMB = 1 << 2;
480pub const HWCAP_26BIT = 1 << 3;
481pub const HWCAP_FAST_MULT = 1 << 4;
482pub const HWCAP_FPA = 1 << 5;
483pub const HWCAP_VFP = 1 << 6;
484pub const HWCAP_EDSP = 1 << 7;
485pub const HWCAP_JAVA = 1 << 8;
486pub const HWCAP_IWMMXT = 1 << 9;
487pub const HWCAP_CRUNCH = 1 << 10;
488pub const HWCAP_THUMBEE = 1 << 11;
489pub const HWCAP_NEON = 1 << 12;
490pub const HWCAP_VFPv3 = 1 << 13;
491pub const HWCAP_VFPv3D16 = 1 << 14;
492pub const HWCAP_TLS = 1 << 15;
493pub const HWCAP_VFPv4 = 1 << 16;
494pub const HWCAP_IDIVA = 1 << 17;
495pub const HWCAP_IDIVT = 1 << 18;
496pub const HWCAP_VFPD32 = 1 << 19;
497pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT;
498pub const HWCAP_LPAE = 1 << 20;
499pub const HWCAP_EVTSTRM = 1 << 21;
500
501pub const msghdr = extern struct {
502 msg_name: ?*sockaddr,
503 msg_namelen: socklen_t,
504 msg_iov: [*]iovec,
505 msg_iovlen: i32,
506 msg_control: ?*c_void,
507 msg_controllen: socklen_t,
508 msg_flags: i32,
509};
510
511pub const msghdr_const = extern struct {
512 msg_name: ?*const sockaddr,
513 msg_namelen: socklen_t,
514 msg_iov: [*]iovec_const,
515 msg_iovlen: i32,
516 msg_control: ?*c_void,
517 msg_controllen: socklen_t,
518 msg_flags: i32,
519};
520
521/// Renamed to Stat to not conflict with the stat function.
522/// atime, mtime, and ctime have functions to return `timespec`,
523/// because although this is a POSIX API, the layout and names of
524/// the structs are inconsistent across operating systems, and
525/// in C, macros are used to hide the differences. Here we use
526/// methods to accomplish this.
527pub const Stat = extern struct {
528 dev: u64,
529 __dev_padding: u32,
530 __ino_truncated: u32,
531 mode: u32,
532 nlink: u32,
533 uid: u32,
534 gid: u32,
535 rdev: u64,
536 __rdev_padding: u32,
537 size: i64,
538 blksize: i32,
539 blocks: u64,
540 atim: timespec,
541 mtim: timespec,
542 ctim: timespec,
543 ino: u64,
544
545 pub fn atime(self: Stat) timespec {
546 return self.atim;
547 }
548
549 pub fn mtime(self: Stat) timespec {
550 return self.mtim;
551 }
552
553 pub fn ctime(self: Stat) timespec {
554 return self.ctim;
555 }
556};
557
558pub const timespec = extern struct {
559 tv_sec: i32,
560 tv_nsec: i32,
561};
562
563pub const timeval = extern struct {
564 tv_sec: i32,
565 tv_usec: i32,
566};
567
568pub const timezone = extern struct {
569 tz_minuteswest: i32,
570 tz_dsttime: i32,
571};
std/os/linux.zig+132-25
......@@ -17,6 +17,7 @@ pub const is_the_target = builtin.os == .linux;
1717pub usingnamespace switch (builtin.arch) {
1818 .x86_64 => @import("linux/x86_64.zig"),
1919 .aarch64 => @import("linux/arm64.zig"),
20 .arm => @import("linux/arm-eabi.zig"),
2021 else => struct {},
2122};
2223pub usingnamespace @import("bits.zig");
......@@ -189,7 +190,11 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
189190}
190191
191192pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
192 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
193 if (@hasDecl(@This(), "SYS_mmap2")) {
194 return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, @divTrunc(offset, MMAP2_UNIT)));
195 } else {
196 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
197 }
193198}
194199
195200pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {
......@@ -205,11 +210,26 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
205210}
206211
207212pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
208 return syscall4(SYS_preadv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);
213 return syscall5(
214 SYS_preadv,
215 @bitCast(usize, isize(fd)),
216 @ptrToInt(iov),
217 count,
218 @truncate(usize, offset),
219 @truncate(usize, offset >> 32),
220 );
209221}
210222
211223pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
212 return syscall5(SYS_preadv2, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset, flags);
224 return syscall6(
225 SYS_preadv2,
226 @bitCast(usize, isize(fd)),
227 @ptrToInt(iov),
228 count,
229 @truncate(usize, offset),
230 @truncate(usize, offset >> 32),
231 flags
232 );
213233}
214234
215235pub 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 {
221241}
222242
223243pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
224 return syscall4(SYS_pwritev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);
244 return syscall5(
245 SYS_pwritev,
246 @bitCast(usize, isize(fd)),
247 @ptrToInt(iov),
248 count,
249 @truncate(usize, offset),
250 @truncate(usize, offset >> 32),
251 );
225252}
226253
227254pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
228 return syscall5(SYS_pwritev2, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset, flags);
255 return syscall6(
256 SYS_pwritev2,
257 @bitCast(usize, isize(fd)),
258 @ptrToInt(iov),
259 count,
260 @truncate(usize, offset),
261 @truncate(usize, offset >> 32),
262 flags
263 );
229264}
230265
231266// TODO https://github.com/ziglang/zig/issues/265
......@@ -481,67 +516,123 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
481516}
482517
483518pub fn setuid(uid: u32) usize {
484 return syscall1(SYS_setuid, uid);
519 if (@hasDecl(@This(), "SYS_setuid32")) {
520 return syscall1(SYS_setuid32, uid);
521 } else {
522 return syscall1(SYS_setuid, uid);
523 }
485524}
486525
487526pub fn setgid(gid: u32) usize {
488 return syscall1(SYS_setgid, gid);
527 if (@hasDecl(@This(), "SYS_setgid32")) {
528 return syscall1(SYS_setgid32, gid);
529 } else {
530 return syscall1(SYS_setgid, gid);
531 }
489532}
490533
491534pub fn setreuid(ruid: u32, euid: u32) usize {
492 return syscall2(SYS_setreuid, ruid, euid);
535 if (@hasDecl(@This(), "SYS_setreuid32")) {
536 return syscall2(SYS_setreuid32, ruid, euid);
537 } else {
538 return syscall2(SYS_setreuid, ruid, euid);
539 }
493540}
494541
495542pub fn setregid(rgid: u32, egid: u32) usize {
496 return syscall2(SYS_setregid, rgid, egid);
543 if (@hasDecl(@This(), "SYS_setregid32")) {
544 return syscall2(SYS_setregid32, rgid, egid);
545 } else {
546 return syscall2(SYS_setregid, rgid, egid);
547 }
497548}
498549
499550pub fn getuid() u32 {
500 return u32(syscall0(SYS_getuid));
551 if (@hasDecl(@This(), "SYS_getuid32")) {
552 return u32(syscall0(SYS_getuid32));
553 } else {
554 return u32(syscall0(SYS_getuid));
555 }
501556}
502557
503558pub fn getgid() u32 {
504 return u32(syscall0(SYS_getgid));
559 if (@hasDecl(@This(), "SYS_getgid32")) {
560 return u32(syscall0(SYS_getgid32));
561 } else {
562 return u32(syscall0(SYS_getgid));
563 }
505564}
506565
507566pub fn geteuid() u32 {
508 return u32(syscall0(SYS_geteuid));
567 if (@hasDecl(@This(), "SYS_geteuid32")) {
568 return u32(syscall0(SYS_geteuid32));
569 } else {
570 return u32(syscall0(SYS_geteuid));
571 }
509572}
510573
511574pub fn getegid() u32 {
512 return u32(syscall0(SYS_getegid));
575 if (@hasDecl(@This(), "SYS_getegid32")) {
576 return u32(syscall0(SYS_getegid32));
577 } else {
578 return u32(syscall0(SYS_getegid));
579 }
513580}
514581
515582pub fn seteuid(euid: u32) usize {
516 return syscall1(SYS_seteuid, euid);
583 return setreuid(std.math.maxInt(u32), euid);
517584}
518585
519586pub fn setegid(egid: u32) usize {
520 return syscall1(SYS_setegid, egid);
587 return setregid(std.math.maxInt(u32), egid);
521588}
522589
523590pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize {
524 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
591 if (@hasDecl(@This(), "SYS_getresuid32")) {
592 return syscall3(SYS_getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
593 } else {
594 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
595 }
525596}
526597
527598pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize {
528 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
599 if (@hasDecl(@This(), "SYS_getresgid32")) {
600 return syscall3(SYS_getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
601 } else {
602 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
603 }
529604}
530605
531606pub fn setresuid(ruid: u32, euid: u32, suid: u32) usize {
532 return syscall3(SYS_setresuid, ruid, euid, suid);
607 if (@hasDecl(@This(), "SYS_setresuid32")) {
608 return syscall3(SYS_setresuid32, ruid, euid, suid);
609 } else {
610 return syscall3(SYS_setresuid, ruid, euid, suid);
611 }
533612}
534613
535614pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {
536 return syscall3(SYS_setresgid, rgid, egid, sgid);
615 if (@hasDecl(@This(), "SYS_setresgid32")) {
616 return syscall3(SYS_setresgid32, rgid, egid, sgid);
617 } else {
618 return syscall3(SYS_setresgid, rgid, egid, sgid);
619 }
537620}
538621
539622pub fn getgroups(size: usize, list: *u32) usize {
540 return syscall2(SYS_getgroups, size, @ptrToInt(list));
623 if (@hasDecl(@This(), "SYS_getgroups32")) {
624 return syscall2(SYS_getgroups32, size, @ptrToInt(list));
625 } else {
626 return syscall2(SYS_getgroups, size, @ptrToInt(list));
627 }
541628}
542629
543630pub fn setgroups(size: usize, list: *const u32) usize {
544 return syscall2(SYS_setgroups, size, @ptrToInt(list));
631 if (@hasDecl(@This(), "SYS_setgroups32")) {
632 return syscall2(SYS_setgroups32, size, @ptrToInt(list));
633 } else {
634 return syscall2(SYS_setgroups, size, @ptrToInt(list));
635 }
545636}
546637
547638pub fn getpid() i32 {
......@@ -708,22 +799,38 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags:
708799}
709800
710801pub fn fstat(fd: i32, stat_buf: *Stat) usize {
711 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
802 if (@hasDecl(@This(), "SYS_fstat64")) {
803 return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
804 } else {
805 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
806 }
712807}
713808
714809// TODO https://github.com/ziglang/zig/issues/265
715810pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
716 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
811 if (@hasDecl(@This(), "SYS_stat64")) {
812 return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
813 } else {
814 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
815 }
717816}
718817
719818// TODO https://github.com/ziglang/zig/issues/265
720819pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
721 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
820 if (@hasDecl(@This(), "SYS_lstat64")) {
821 return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
822 } else {
823 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
824 }
722825}
723826
724827// TODO https://github.com/ziglang/zig/issues/265
725828pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
726 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
829 if (@hasDecl(@This(), "SYS_fstatat64")) {
830 return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
831 } else {
832 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
833 }
727834}
728835
729836// TODO https://github.com/ziglang/zig/issues/265
std/os/linux/arm-eabi.zig created+96
......@@ -0,0 +1,96 @@
1pub fn syscall0(number: usize) usize {
2 return asm volatile ("svc #0"
3 : [ret] "={r0}" (-> usize)
4 : [number] "{r7}" (number)
5 : "memory"
6 );
7}
8
9pub fn syscall1(number: usize, arg1: usize) usize {
10 return asm volatile ("svc #0"
11 : [ret] "={r0}" (-> usize)
12 : [number] "{r7}" (number),
13 [arg1] "{r0}" (arg1)
14 : "memory"
15 );
16}
17
18pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
19 return asm volatile ("svc #0"
20 : [ret] "={r0}" (-> usize)
21 : [number] "{r7}" (number),
22 [arg1] "{r0}" (arg1),
23 [arg2] "{r1}" (arg2)
24 : "memory"
25 );
26}
27
28pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
29 return asm volatile ("svc #0"
30 : [ret] "={r0}" (-> usize)
31 : [number] "{r7}" (number),
32 [arg1] "{r0}" (arg1),
33 [arg2] "{r1}" (arg2),
34 [arg3] "{r2}" (arg3)
35 : "memory"
36 );
37}
38
39pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
40 return asm volatile ("svc #0"
41 : [ret] "={r0}" (-> usize)
42 : [number] "{r7}" (number),
43 [arg1] "{r0}" (arg1),
44 [arg2] "{r1}" (arg2),
45 [arg3] "{r2}" (arg3),
46 [arg4] "{r3}" (arg4)
47 : "memory"
48 );
49}
50
51pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
52 return asm volatile ("svc #0"
53 : [ret] "={r0}" (-> usize)
54 : [number] "{r7}" (number),
55 [arg1] "{r0}" (arg1),
56 [arg2] "{r1}" (arg2),
57 [arg3] "{r2}" (arg3),
58 [arg4] "{r3}" (arg4),
59 [arg5] "{r4}" (arg5)
60 : "memory"
61 );
62}
63
64pub fn syscall6(
65 number: usize,
66 arg1: usize,
67 arg2: usize,
68 arg3: usize,
69 arg4: usize,
70 arg5: usize,
71 arg6: usize,
72) usize {
73 return asm volatile ("svc #0"
74 : [ret] "={r0}" (-> usize)
75 : [number] "{r7}" (number),
76 [arg1] "{r0}" (arg1),
77 [arg2] "{r1}" (arg2),
78 [arg3] "{r2}" (arg3),
79 [arg4] "{r3}" (arg4),
80 [arg5] "{r4}" (arg5),
81 [arg6] "{r5}" (arg6)
82 : "memory"
83 );
84}
85
86/// This matches the libc clone function.
87pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
88
89// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
90// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.
91// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.
92pub extern fn getThreadPointer() usize {
93 return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"
94 : [ret] "=r" (-> usize)
95 );
96}
\ No newline at end of file
std/os/linux/arm64.zig+7
......@@ -2,6 +2,7 @@ pub fn syscall0(number: usize) usize {
22 return asm volatile ("svc #0"
33 : [ret] "={x0}" (-> usize)
44 : [number] "{x8}" (number)
5 : "memory", "cc"
56 );
67}
78
......@@ -10,6 +11,7 @@ pub fn syscall1(number: usize, arg1: usize) usize {
1011 : [ret] "={x0}" (-> usize)
1112 : [number] "{x8}" (number),
1213 [arg1] "{x0}" (arg1)
14 : "memory", "cc"
1315 );
1416}
1517
......@@ -19,6 +21,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
1921 : [number] "{x8}" (number),
2022 [arg1] "{x0}" (arg1),
2123 [arg2] "{x1}" (arg2)
24 : "memory", "cc"
2225 );
2326}
2427
......@@ -29,6 +32,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
2932 [arg1] "{x0}" (arg1),
3033 [arg2] "{x1}" (arg2),
3134 [arg3] "{x2}" (arg3)
35 : "memory", "cc"
3236 );
3337}
3438
......@@ -40,6 +44,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
4044 [arg2] "{x1}" (arg2),
4145 [arg3] "{x2}" (arg3),
4246 [arg4] "{x3}" (arg4)
47 : "memory", "cc"
4348 );
4449}
4550
......@@ -52,6 +57,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5257 [arg3] "{x2}" (arg3),
5358 [arg4] "{x3}" (arg4),
5459 [arg5] "{x4}" (arg5)
60 : "memory", "cc"
5561 );
5662}
5763
......@@ -73,6 +79,7 @@ pub fn syscall6(
7379 [arg4] "{x3}" (arg4),
7480 [arg5] "{x4}" (arg5),
7581 [arg6] "{x5}" (arg6)
82 : "memory", "cc"
7683 );
7784}
7885
std/os/linux/tls.zig+13
......@@ -118,6 +118,9 @@ pub fn setThreadPointer(addr: usize) void {
118118 : [addr] "r" (addr)
119119 );
120120 },
121 .arm => |arm| {
122 _ = std.os.linux.syscall1(std.os.linux.SYS_set_tls, addr);
123 },
121124 else => @compileError("Unsupported architecture"),
122125 }
123126}
......@@ -130,6 +133,7 @@ pub fn initTLS() void {
130133 var at_phent: usize = undefined;
131134 var at_phnum: usize = undefined;
132135 var at_phdr: usize = undefined;
136 var at_hwcap: usize = undefined;
133137
134138 var i: usize = 0;
135139 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
......@@ -137,6 +141,7 @@ pub fn initTLS() void {
137141 elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,
138142 elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,
139143 elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,
144 elf.AT_HWCAP => at_phdr = auxv[i].a_un.a_val,
140145 else => continue,
141146 }
142147 }
......@@ -156,6 +161,14 @@ pub fn initTLS() void {
156161 }
157162
158163 if (tls_phdr) |phdr| {
164 // If the cpu is arm-based, check if it supports the TLS register
165 if (builtin.arch == builtin.Arch.arm and hwcap & std.os.linux.HWCAP_TLS == 0) {
166 // If the CPU does not support TLS via a coprocessor register,
167 // a kernel helper function can be used instead on certain linux kernels.
168 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.
169 @panic("TODO: Implement ARM fallback TLS functionality");
170 }
171
159172 // Offsets into the allocated TLS area
160173 var tcb_offset: usize = undefined;
161174 var dtv_offset: usize = undefined;
std/special/c.zig+31
......@@ -25,6 +25,8 @@ comptime {
2525 @export("strncmp", strncmp, .Strong);
2626 @export("strerror", strerror, .Strong);
2727 @export("strlen", strlen, .Strong);
28 } else if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) {
29 @export("__aeabi_read_tp", std.os.linux.getThreadPointer, .Strong);
2830 }
2931}
3032
......@@ -238,6 +240,35 @@ nakedcc fn clone() void {
238240 \\ mov x8,#93 // SYS_exit
239241 \\ svc #0
240242 );
243 } else if (builtin.arch == builtin.Arch.arm) {
244 asm volatile (
245 \\ stmfd sp!,{r4,r5,r6,r7}
246 \\ mov r7,#120
247 \\ mov r6,r3
248 \\ mov r5,r0
249 \\ mov r0,r2
250 \\ and r1,r1,#-16
251 \\ ldr r2,[sp,#16]
252 \\ ldr r3,[sp,#20]
253 \\ ldr r4,[sp,#24]
254 \\ svc 0
255 \\ tst r0,r0
256 \\ beq 1f
257 \\ ldmfd sp!,{r4,r5,r6,r7}
258 \\ bx lr
259 \\
260 \\1: mov r0,r6
261 \\ tst r5,#1
262 \\ bne 1f
263 \\ mov lr,pc
264 \\ mov pc,r5
265 \\2: mov r7,#1
266 \\ svc 0
267 \\
268 \\1: mov lr,pc
269 \\ bx r5
270 \\ b 2b
271 );
241272 } else {
242273 @compileError("Implement clone() for this arch.");
243274 }
std/special/start.zig+1-1
......@@ -44,7 +44,7 @@ nakedcc fn _start() noreturn {
4444 : [argc] "={esp}" (-> [*]usize)
4545 );
4646 },
47 .aarch64, .aarch64_be => {
47 .aarch64, .aarch64_be, .arm => {
4848 argc_ptr = asm ("mov %[argc], sp"
4949 : [argc] "=r" (-> [*]usize)
5050 );