Commit Graph

47 Commits

Author SHA1 Message Date
Joris Vink ecbc373433 revert some labbing in kore_realloc() 2023-03-01 16:41:33 +01:00
Joris Vink 3e944e106b Change kore_realloc() behaviour a bit.
If kore_realloc() decides that a new block must be allocated it will
explicitly call the new kore_free_zero() function to erase the
contents of the old block once the move is done.
2023-03-01 16:29:06 +01:00
Joris Vink a421e7a9cd Add memory protection with KORE_MEM_GUARD.
When KORE_MEM_GUARD is set in the environment when Kore is started
it will enable a few memory protection techniques for all kore pools:

1) The metadata is placed away from the actual user pointer returned.

2) Each entry in a pool is placed in such a way that it is followed
   immediately by a guard page which has PROT_NONE. Accessing a guard
   page will cause an immediate crash.

3) Each entry is marked with PROT_NONE until it is allocated. Once it
   is returned to a pool it becomes PROT_NONE again, protecting against
   use after frees.

This commit also removes the magic goo from the mem facitilies such
as kore_malloc and friends and moves these as canaries into the kore
pool facilities instead.

Note that using this will increase memory pressure and decrease performance.

It is recommended to enable this during development to catch bugs.
2023-01-05 22:47:29 +01:00
Joris Vink 0d305ecf5a fix format specifier, previous commit touched a bit too much. 2022-03-15 13:47:35 +01:00
Joris Vink 5021eeb597 use correct format specifier for size_t 2022-03-15 13:39:01 +01:00
Joris Vink 045beb8622 add kore_mem_zero().
use it in places explicit_bzero() used to be called.

The kore_mem_zero() is a best effort to try and let the compiler
not optimize the code away. Highly platform dependent.
2022-02-18 11:13:01 +01:00
Joris Vink 833ca646e7 i forgot, it's 2022. 2022-01-31 22:02:06 +01:00
Joris Vink cef5ac4003 bump copyright year. 2021-01-11 23:46:08 +01:00
Joris Vink 9d0aef0079 bump copyright 2020-02-10 14:47:33 +01:00
Joris Vink ffb9fd2fc5 Align kore memory functions on 16-byte boundaries. 2019-10-15 21:33:43 +02:00
Joris Vink eb9b7f7b14 explicitly include sys/types.h
some smaller libc variants do not include this from sys/param.h.
2019-03-06 09:29:46 +01:00
Joris Vink bf1e8e5ffb bump copyright to 2019 2019-02-22 16:57:28 +01:00
Joris Vink 086e2e3d5e len is a size_t, not ssize_t 2018-07-18 16:09:05 +02:00
Joris Vink 548348f553 2018 2018-01-20 22:51:06 +01:00
Joris Vink 40c93e66a2 Add memory tagging.
This allows modules that have global pointers to upon reload repopulate
those with the addresses of when they were first created.

Meaning it now is easier to write modules that can be reloaded if those
modules kept global state one way or the other.

This should only be used at module init/reload time and is very simple:

if ((ptr = kore_mem_lookup(MY_ID_VALUE)) == NULL) {
	ptr = kore_malloc_tagged(length, MY_ID_VALUE);
	/* initialize for the first time. */
}

If we were in a reload the kore_mem_lookup() will return the original address
returned by the initial kore_malloc_tagged() call for MY_ID_VALUE.
2017-08-30 11:47:26 +02:00
Joris Vink 27da1dd741 fix semantics for kore_calloc().
We were not returning zeroed out memory from kore_calloc() which goes
against what calloc() does. Skip performance for now and simply just
memset() the returned pointer from kore_malloc().

This should be sufficient enough for now.
2017-02-27 19:50:06 -08:00
Joris Vink 80698ee40a add kore_mem_cleanup() to cleanup pools at exit. 2017-02-06 11:42:23 +01:00
Joris Vink e47806c669 allow memory allocators to deal with 0 bytes.
we just increase the lenght requested to 8 bytes if we get a 0 byte request.

additionally when kore_realloc() is called check if we actually have
to do the work, if not just return the original pointer.
2017-01-25 22:07:08 +01:00
Joris Vink db4f6cf01f align pointers from kore_malloc() properly. 2016-07-28 14:52:15 +02:00
Joris Vink 4ad50caa29 Large changes to the memory subsystem in kore.
- Change pools to use mmap() for allocating regions.
- Change kore_malloc() to use pools for commonly sized objects.
  (split into multiple of 2 buckets, starting at 8 bytes up to 8192).
- Rename kore_mem_free() to kore_free().

The preallocated pools will hold up to 128K of elements per block size.

In case a larger object is to be allocated kore_malloc() will use
malloc() instead.
2016-07-12 13:54:14 +02:00
Joris Vink 27acc51241 Improve kore_strlcpy().
Make it return the original length of the input string so the caller
can check for truncation. Also guard against len being 0 as this would
not do anything with the destination string (not even NUL terminate it).
2016-07-04 11:41:37 +02:00
Joris Vink 318647945f more consistency in fatal messages. 2016-02-13 15:45:33 +01:00
Stig Telfer 2ac6e7d41d Merge branch 'master' into oneswig 2016-01-24 13:46:38 +00:00
Joris Vink c4b1206ae3 Bump copyright to 2016. 2016-01-04 12:58:51 +01:00
Stig Telfer ac45e8cd62 Revert incorrect parameter validation 2015-12-29 21:29:35 +00:00
Stig Telfer 0c51d9da53 Add resource management as part of the kore shutdown process. 2015-12-29 19:39:39 +00:00
Joris Vink 769c78a6e8 Introduce NOHTTP=1 build option.
This basically turns off the HTTP layer for Kore. It does not
compile in anything for HTTP.

This allows Kore to be used as a network application platform as well.
Added an example for this called nohttp.

Other changes that sneaked in while hacking on this:
* Use calloc(), kill pendantic malloc option.
* Killed off SPDY/3.1 support completely, will be superseded by http2

Note that comes with massive changes to a lot of the core API
functions provided by Kore, these might break your application.
2015-11-27 16:22:50 +01:00
Joris Vink af865abede Bump copyright to 2015 2015-04-07 13:08:26 +02:00
Joris Vink 693a07250f bump copyright years 2014-10-14 16:18:23 +02:00
Joris Vink 1c83af511d Make kore_mem_free() behave like free() and don't do anything if NULL is passed in. 2014-09-25 22:20:47 +02:00
Joris Vink fbfabf6f04 Add missing stdint.h header 2014-07-22 09:53:44 +02:00
Joris Vink f3fe543358 Add integer overflow checks to kore_calloc 2014-04-23 14:26:28 +02:00
Joris Vink 2bdc9210a0 Wrap with KORE_PEDANTIC_MALLOC 2014-04-22 13:05:16 +02:00
Joris Vink d98d56fb20 Add KORE_PENDANTIC_MALLOC option.
This option tells Kore to zero out memory when allocated, freed or
when get/put from the pools.
2014-04-22 12:46:23 +02:00
Joris Vink d2618db525 Kill __packed__ attributes on some data structs 2014-04-18 17:41:56 +02:00
Joris Vink 20f02ced23 remove meminuse and list of allocated memory blocks, we don't need it. 2013-07-25 23:41:00 +02:00
Joris Vink 60ce2ce858 In kore_realloc() copy a minimum of old or new length bytes. 2013-07-22 22:44:42 +02:00
Joris Vink 341172f844 Do not 0 out everything we allocate, and instead fix the behaviour of the code in the appropriate places. 2013-07-16 09:56:36 +02:00
Joris Vink 29fa49ba83 Add fixed size memory pools and use them throughout Kore. 2013-07-15 11:06:36 +02:00
Joris Vink cebd1c2c2b Reduce footprint of meminfo and shuffle some stuff around 2013-07-13 22:19:50 +02:00
Joris Vink 51c8188f7a remove cast for malloc + add missing stdlib.h 2013-07-13 21:47:04 +02:00
Joris Vink 9c7aaf179f Remove unneeded malloc result casting, annoying habbit of mine but serves no purpose. 2013-07-13 21:08:55 +02:00
Joris Vink c1723f2db5 Clean up header includes, based on a diff from Ewan Higgs via github.
And while we're messing in it, make sure bsd.c compiles again.
2013-07-06 20:55:22 +02:00
Joris Vink a1342c93d5 remove memid from meminfo 2013-06-27 12:27:17 +02:00
Joris Vink f18a6388fd fix kore_realloc() to actually behave properly 2013-06-27 09:20:48 +02:00
Joris Vink 4b2420097b - Better spread load between all worker processes.
- Introduce own memory management system on top of malloc to keep track
  of all our allocations and free's. Later we should introduce a pooling
  mechanism for fixed size allocations (http_request comes to mind).
- Introduce ssl_cipher in configuration.

Memory usage is kind of high right now, but it seems its OpenSSL
doing it rather then Kore.
2013-06-27 08:46:18 +02:00
Joris Vink b4a0330a96 - Better spread load between all worker processes.
- Introduce own memory management system on top of malloc to keep track
  of all our allocations and free's. Later we should introduce a pooling
  mechanism for fixed size allocations (http_request comes to mind).
- Introduce ssl_cipher in configuration.

Memory usage is kind of high right now, but it seems its OpenSSL
doing it rather then Kore.
2013-06-27 08:43:07 +02:00