Skip to content

Commit

Permalink
[feat] OpenBSD pledge
Browse files Browse the repository at this point in the history
  • Loading branch information
afify committed Nov 28, 2020
1 parent 69bfc1a commit ce379ec
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ azan
- standalone nasm
- unix portable syscalls
- tested on Linux, OpenBSD, FreeBSD and NetBSD
- OpenBSD pledge.
- binary size ≈ 7 kb
- instructions ≈ 250-400
- branches ≈ 6-20
Expand Down
5 changes: 5 additions & 0 deletions azan.s
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ section .rodata
usage_len: equ $ - usage_msg
version_msg: db "azan-", VERSION, 10, 0
version_len: equ $ - version_msg
pledge_msg: db "pledge", 10, 0
promises: db "stdio", 0

section .data
res_msg: db "X XX:XX", 10, 0
Expand Down Expand Up @@ -84,6 +86,7 @@ check_argv:
DIE version_msg, version_len

get_timestamp:
OPENBSD_PLEDGE
mov rax, SYS_gettimeofday ;sys_gettimeofday(
mov rdi, tmp0 ;struct timeval *tv,
mov rsi, rsi ;struct timezone* tz
Expand Down Expand Up @@ -456,6 +459,8 @@ print_all_12:
PRINT_HM
EEXIT EXIT_SUCCESS

die_pledge:
DIE pledge_msg, 8
; result_hour ;r8
; result_min ;r9
; duhr_ts: ;xmm0
Expand Down
11 changes: 11 additions & 0 deletions macros.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ section .note.openbsd.ident note
%endif
%endmacro

%macro OPENBSD_PLEDGE 0
%ifdef OpenBSD
mov rax, SYS_pledge ;pledge(
mov rdi, promises ;const char *promises
xor rsi, rsi ;const char *execpromises
syscall
cmp rax, 0
jl die_pledge
%endif
%endmacro

%macro EEXIT 1
mov rax, SYS_exit
mov rdi, %1
Expand Down
1 change: 1 addition & 0 deletions syscalls.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
%define SYS_exit 1
%define SYS_write 4
%define SYS_gettimeofday 67
%define SYS_pledge 108
%elifdef FreeBSD
%define SYS_exit 1
%define SYS_write 4
Expand Down

0 comments on commit ce379ec

Please sign in to comment.