Commit Graph

73 Commits

Author SHA1 Message Date
Yawning Angel 672fc9fc4d core/mem: Add zero_explicit
This call is intended to provide the ability to securely scrub memory
without compiler interference, in a similar manner to explicit_bzero,
memset_s, SecureZeroMemory.

The approach taken is a volatile memset followed by a seqentially
consistent memory fence, to prevent the call from being optimized away
by DSE, and from being reordered.  An identical approach is currently
being used by the zeroize Rust crate, and is effective in practice.

LLVM IR output:
```
; Function Attrs: nounwind
define internal i8* @mem.zero_explicit(i8* %0, i64 %1) #0 {
decls:
  call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 %1, i1 true)
  fence seq_cst
  ret i8* %0
}
```
2021-10-31 22:57:13 +00:00
gingerBill aaaddd03a6 Improve internal procedures 2021-10-25 01:28:06 +01:00
Jeroen van Rijn 1931e3147d Remove assert from mem.ptr_to_bytes. Fixes #1206 2021-10-05 14:18:48 +02:00
gingerBill bfc92d0aaf Make runtime.memset use int for the length from uint 2021-09-23 23:43:29 +01:00
gingerBill ab85571ae6 Minor improvements to mem.odin 2021-09-11 16:33:05 +01:00
gingerBill b712c84afb Fix typo 2021-09-10 16:37:43 +01:00
gingerBill 9980f81062 Add other constants to c and libc 2021-09-10 16:14:39 +01:00
gingerBill 12af657369 Unify memset usage across platforms and core:c/libc 2021-09-10 15:59:14 +01:00
gingerBill 99df0f1b12 libc changes: unify c and libc types; Add [^]T where appropriate 2021-09-10 15:41:51 +01:00
gingerBill ca33cb990b Strip semicolons in core which were missing 2021-09-08 13:12:38 +01:00
gingerBill 3754af62d6 Correct "contextless" stuff in mem 2021-09-08 11:43:00 +01:00
gingerBill a9f4273514 Make many mem procedures "contextless" 2021-09-08 11:18:05 +01:00
gingerBill 720884e0f1 Strip even more semicolons if followed by a } or ) on the same line 2021-08-31 23:47:57 +01:00
gingerBill 251da264ed Remove unneeded semicolons from the core library 2021-08-31 22:21:13 +01:00
gingerBill 81623861c0 Correct mem.clone_slice 2021-08-23 14:33:54 +01:00
gingerBill d5bad374d9 Remove deprecated procedure slice_ptr_to_bytes 2021-08-22 12:55:57 +01:00
gingerBill 445ed9be2b Use multi-pointers when appropriate 2021-08-22 12:54:04 +01:00
gingerBill 2f5edebefa Rename mem.reinterpret to mem.reinterpret_copy 2021-08-20 10:19:30 +01:00
gingerBill b5cdb331b0 Add mem.reinterpret 2021-08-20 10:18:34 +01:00
Jeroen van Rijn 03862d1f48 Mark mem.slice_ptr_to_bytes as deprecated.
Use byte_slice instead.

We can't make it an alias *and* mark it as deprecated, regrettably:

```odin
byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
    return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
}
@(deprecated="use byte_slice")
slice_ptr_to_bytes :: byte_slice;

"mem.odin(145:1) Constant alias declarations cannot have attributes"
```
2021-05-06 13:23:17 +02:00
gingerBill e9b1d4f633 Fix #906 2021-04-20 10:34:41 +01:00
gingerBill f98c4d6837 Improve the Allocator interface to support returning Allocator_Error to allow for safer calls
Virtually all code (except for user-written custom allocators) should work as normal. Extra features will need to be added to make the current procedures support the `Allocator_Error` return value (akin to #optional_ok)
2021-04-19 12:31:31 +01:00
gingerBill b727b6438b Minimize unneeded casts 2021-03-03 14:31:17 +00:00
gingerBill aa93305015 Replace usage of inline proc with #force_inline proc in the core library 2021-02-23 16:14:47 +00:00
gingerBill 519dcc2b76 Add os.read_at and for Windows; fix mem.clone_slice; fix current directory locking code 2020-09-29 11:11:28 +01:00
gingerBill fc4fdd588e Remove usage of do in core library 2020-09-23 17:17:14 +01:00
gingerBill 4930a9c1a4 Add mem.clone_slice 2020-09-15 11:51:38 +01:00
gingerBill 3385fcecb0 Fix typo 2020-08-04 14:31:14 +01:00
gingerBill 92363da58e Add -show-system-calls; Update runtime for windows_386; Fix some minor bugs 2020-06-30 10:09:58 +01:00
gingerBill 8478b887a5 Add mem.check_zero and mem.check_zero_ptr 2020-06-29 16:17:40 +01:00
gingerBill 86448ee044 Add raw_data to replace cases in which &x[0] was used 2020-06-29 15:58:24 +01:00
gingerBill be76c860a5 mem.simple_equal 2020-06-12 14:52:31 +01:00
gingerBill 474d79dcf1 Add mem.simple_compare_values 2020-06-10 16:37:22 +01:00
gingerBill 8b066b2456 Fix runtime.memset issue 2020-05-14 17:56:24 +01:00
gingerBill e0a242e9a1 Enforce explicit context definition for procedure calls 2020-05-14 13:44:28 +01:00
gingerBill 117ade0700 Fix errors in package win32 2020-04-30 17:48:35 +01:00
gingerBill 97f7a558fa #optional_ok tag for procedures 2020-04-19 21:45:04 +01:00
gingerBill baf5b9edc3 Add runtime.bswap_* required for -llvm-api 2020-04-11 19:26:16 +01:00
gingerBill c6c6c56ba9 Fix mem.set for LLVM C API 2020-03-08 18:44:45 +00:00
gingerBill c74d8405ec Merge branch 'master' into llvm-integration 2020-03-08 10:13:19 +00:00
Tetralux 0190f90979 Fix mem.align_backward when pointer is already aligned 2020-02-28 12:22:30 +00:00
gingerBill e197af766d Merge branch 'master' into llvm-integration 2020-02-23 10:39:57 +00:00
gingerBill 2180f4a475 Basic work on obj generation 2020-02-23 10:04:25 +00:00
Tetralux 1f0c1943da Fix #552.
- Fix comparisons involving one or more empty string.
- Fix comparisons against two strings of different lengths.
2020-02-12 11:25:12 +00:00
gingerBill 13107628f8 Make mem.set use llvm.memset.p0i8.iXX 2019-12-31 14:09:51 +00:00
gingerBill ab52f8d795 Move definition of mem.Allocator and log.Logger to package runtime, to reduce import cycle magic 2019-12-31 12:15:19 +00:00
Tetralux 99121d6ff2 Implement core:thread and core:sync on Unix using pthreads
Also do some cleanup and refactoring of the thread, sync and time APIs.

- remove 'semaphore_release' because 'post' and 'wait' is easier to understand

- change 'semaphore_wait' to '*_wait_for' to match Condition

- pthreads can be given a stack, but doing so requires the user to set up the guard
  pages manually. BE WARNED. The alignment requirements of the stack are also
  platform-dependant; it may need to be page size aligned on some systems.
  Unclear which systems, however. See 'os.get_page_size', and 'mem.make_aligned'.
  HOWEVER: I was unable to get custom stacks with guard pages working reliably,
  so while you can do it, the API does not support it.

- add 'os.get_page_size', 'mem.make_aligned', and 'mem.new_aligned'.

- removed thread return values because windows and linux are not consistent; windows returns 'i32'
  and pthreads return 'void*'; besides which, if you really wanted to communicate how the
  thread exited, you probably wouldn't do it with the thread's exit code.

- fixed 'thread.is_done' on Windows; it didn't report true immediately after calling 'thread.join'.

- moved time related stuff out of 'core:os' to 'core:time'.

- add 'mem.align_backward'

- fixed default allocator alignment
  The heap on Windows, and calloc on Linux, both have no facility to request alignment.
  It's a bit of hack, but the heap_allocator now overallocates; `size + alignment` bytes,
  and aligns things to at least 2.
  It does both of these things to ensure that there is at least two bytes before the payload,
  which it uses to store how much padding it needed to insert in order to fulfil the alignment
  requested.

- make conditions more sane by matching the Windows behaviour.
  The fact that they were signalled now lingers until a thread tries to wait,
  causing them to just pass by uninterrupted, without sleeping or locking the
  underlying mutex, as it would otherwise need to do.
  This means that a thread no longer has to be waiting in order to be signalled, which
  avoids timing bugs that causes deadlocks that are hard to debug and fix.
  See the comment on the `sync.Condition.flag` field.

- add thread priority: `thread.create(worker_proc, .High)`
2019-12-01 00:46:23 +00:00
gingerBill 40546fbde2 Use runtime.mem_copy in package me 2019-11-03 19:59:41 +00:00
gingerBill 927d6814f2 slice_data_cast 2019-07-09 11:09:46 +01:00
gingerBill 79b585ada8 Add minor additions to mem, sync, and sys/win32 2019-02-21 21:45:33 +00:00