Commit Graph

66 Commits

Author SHA1 Message Date
gingerBill 7642e0a0e0 Require @(init) and @(fini) to be proc "contextless" () 2025-08-08 12:10:01 +01:00
Christiano Haesbaert c51df72f1a Make sure we don't leak os.args. Fixes #1633.
os.args is never freed, while this is an insignificant leak, it is a bit
annoying as it makes valgrind complain:

==234270== Memcheck, a memory error detector
==234270== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==234270== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==234270== Command: ./wc /tmp/mulumulu
==234270==
       1       8      58 /tmp/mulumulu
==234270==
==234270== HEAP SUMMARY:
==234270==     in use at exit: 47 bytes in 1 blocks
==234270==   total heap usage: 5 allocs, 4 frees, 4,195,875 bytes allocated
==234270==
==234270== 47 bytes in 1 blocks are possibly lost in loss record 1 of 1
==234270==    at 0x484BC13: calloc (vg_replace_malloc.c:1675)
==234270==    by 0x402E49: runtime._heap_alloc-769 (in /d/learn-odin/wc/wc)
==234270==    by 0x40A8D7: runtime.heap_alloc (in /d/learn-odin/wc/wc)
==234270==    by 0x436E9D: runtime.heap_allocator_proc.aligned_alloc-0 (in /d/learn-odin/wc/wc)
==234270==    by 0x4022DC: runtime.heap_allocator_proc (in /d/learn-odin/wc/wc)
==234270==    by 0x4165E0: runtime.make_aligned-22560 (in /d/learn-odin/wc/wc)
==234270==    by 0x41F6D0: runtime.make_slice-22340 (in /d/learn-odin/wc/wc)
==234270==    by 0x40156B: os._alloc_command_line_arguments-4679 (in /d/learn-odin/wc/wc)
==234270==    by 0x4011AF: __$startup_runtime (in /d/learn-odin/wc/wc)
==234270==    by 0x406F17: main (in /d/learn-odin/wc/wc)
==234270==
==234270== LEAK SUMMARY:
==234270==    definitely lost: 0 bytes in 0 blocks
==234270==    indirectly lost: 0 bytes in 0 blocks
==234270==      possibly lost: 47 bytes in 1 blocks
==234270==    still reachable: 0 bytes in 0 blocks
==234270==         suppressed: 0 bytes in 0 blocks
==234270==
==234270== For lists of detected and suppressed errors, rerun with: -s
==234270== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

With the fix the leak is gone, tested on linux only.

While here, also make _alloc_command_line_arguments() private.
2025-01-11 21:55:09 +01:00
Jeroen van Rijn 8581240ece Make O_RDONLY default for os.open on all platforms.
And also moved Windows file procs to `os_windows.odin`, in line with all the other platforms who didn't have a dedicated `file_<platform>.odin`
2024-11-28 15:57:48 +01:00
Karl Zylinski 19f0127e55 Moved all packages in core, base, vendor, tests and examples to use new #+ file tag syntax. 2024-09-14 18:27:49 +02:00
Feoramund 1ced76cdd1 Fix broken cases of Seek usage in _file_stream_proc
Handles `EINVAL`, among other fixes.
2024-08-28 19:53:20 +02:00
gingerBill c078b2dd1b Add @(require_results) 2024-08-04 15:24:26 +01:00
gingerBill e8d26c5797 Move errors to where appropriate 2024-08-04 13:41:34 +01:00
gingerBill 3d992e2704 Improve _error_string for Linux 2024-08-04 13:25:35 +01:00
gingerBill 0c5b645dde Correct EOF value 2024-08-04 13:20:33 +01:00
gingerBill 97c499dbb4 Begin mapping os.Error in the rest of the codebase 2024-08-04 11:58:04 +01:00
gingerBill 160048eaee Errno -> Error 2024-08-04 11:46:42 +01:00
gingerBill def2e2e271 Try to map to General_Error where possible 2024-08-04 11:44:45 +01:00
gingerBill 29b6eebcd5 Clean up error handling 2024-08-04 11:21:09 +01:00
gingerBill 9f9abb8fb3 Use union #shared_nil for os.Error 2024-08-04 11:05:30 +01:00
gingerBill e60951a902 Begin converting os.Errno to be a nil-able type as a transition period 2024-08-04 10:51:08 +01:00
gingerBill e296d6fb90 Fix loads of indentation issues with mixing spaces and tabs 2024-06-29 19:50:51 +01:00
gingerBill 038086d1d9 Alias heap calls from base:runtime is core:os 2024-01-28 22:47:55 +00:00
gingerBill 3e7e779abf Replace core:* to base:* where appropriate 2024-01-28 22:18:51 +00:00
gingerBill 986cba584e Add runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD where appropriate 2023-02-10 16:23:33 +00:00
Colin Davidson 3935957979 remove unused c import 2023-01-06 13:53:32 -08:00
Colin Davidson a36640bcfc more windows fixes 2023-01-06 13:51:25 -08:00
Colin Davidson 171d5b4012 more windows kerfuffle 2023-01-06 13:45:21 -08:00
Colin Davidson 6ff2db47b4 shuffle to private/public wrapper 2023-01-06 13:33:47 -08:00
Colin Davidson b455ccd261 fix more things? 2023-01-05 01:37:50 -08:00
Colin Davidson 944396128b add get core count 2023-01-05 01:06:55 -08:00
gingerBill 7f601c9535 Add Allocator_Mode.Alloc_Non_Zerored 2022-09-22 12:12:57 +01:00
gingerBill 17eebf338c Fix #1606 (Call runtime._cleanup_runtime_contextless() for os.exit) 2022-03-09 15:05:51 +00:00
gingerBill 251da264ed Remove unneeded semicolons from the core library 2021-08-31 22:21:13 +01:00
Jeroen van Rijn bb86b0f526 os: Add Windows 11 detection. 2021-08-21 14:08:22 +02:00
gingerBill 359ae29d98 Minor fixes 2021-03-18 13:25:41 +00:00
gingerBill b727b6438b Minimize unneeded casts 2021-03-03 14:31:17 +00:00
gingerBill efdee0dafb Remove bit_field type from Odin (keyword and dead runtime code still exists) 2021-02-19 11:31:14 +00:00
zhibog 4c4112fbc7 Fixed getting windows version. The former function is no longer working on Windows 10. Also fixed the struct to use correct win32 names 2020-10-24 00:14:01 +02: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 840af6825a Update packages os, path, and filepath 2020-09-26 16:02:03 +01:00
gingerBill 8cc5cd1494 Add package path/filepath; Add os.stat for windows (TODO: unix) 2020-09-25 20:20:53 +01:00
gingerBill fc4fdd588e Remove usage of do in core library 2020-09-23 17:17:14 +01:00
Tetralux 3820f27c7c Fix os.get_current_directory() allocator
This procedure accidentally used the temporary allocator for the
returned string.
Use context.allocator, and the allocator parameter idiom instead.
2020-08-26 11:37:44 +00:00
gingerBill 65b9dbe13f Clean-up OS constants; Clean-up procs_wasm32.odin 2020-07-09 17:21:40 +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 0ea64182f1 Begin work on windows 386 2020-06-29 17:35:33 +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 6bd05ef5d7 Begin migration from sys/win32 to sys/windows 2020-06-26 19:11:34 +01:00
gingerBill 240fc65d4d Add multi_logger.odin; Fix os_windows.odin 2020-06-19 11:49:08 +01:00
vassvik 6985d72fda Make os.get_current_directory no longer strip the zero at the end of the resulting string, as it no longer should occur. 2020-06-13 15:20:39 +02:00
gingerBill 93955a0fd8 Remove context.std* parameters; Fix unary boolean not 2020-03-19 15:03:02 +00:00
Tetralux 66d1656367 Add os.get_current_directory / os.set_current_directory 2020-01-20 14:28:31 +00:00
gingerBill 85e31e1b69 Fix os.open 2019-12-23 18:10:09 +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 f4f6e9ad49 Fix -debug crash on windows caused by missing debug info for files. 2019-09-25 21:07:56 +01:00