The branch, v3-6-test has been updated via fb6004d lib/util: add tests for anonymous_shared_allocate/free() via 278f07c lib/util: add anonymous_shared_free() via d57a0ff lib/util: s/allocate_anonymous_shared/anonymous_shared_allocate/ via 54efccf lib/util: fix rounding to page size in allocate_anonymous_shared() from 4d2ff96 s3-param: Fixed code block in max_open_files().
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test - Log ----------------------------------------------------------------- commit fb6004d01ff4a3342e3cde174391edb8ea4e34ca Author: Stefan Metzmacher <me...@samba.org> Date: Tue Jan 18 17:00:26 2011 +0100 lib/util: add tests for anonymous_shared_allocate/free() metze Autobuild-User: Stefan Metzmacher <me...@samba.org> Autobuild-Date: Thu Jan 20 06:25:03 CET 2011 on sn-devel-104 (cherry picked from commit c9e6bf047dc92a75d31b686d4e759743fc7386f8) Signed-off-by: Stefan Metzmacher <me...@samba.org> commit 278f07c89f7e8c15a6e57cd7a51eeead3ea221a0 Author: Stefan Metzmacher <me...@samba.org> Date: Tue Oct 26 22:45:19 2010 +0200 lib/util: add anonymous_shared_free() metze (cherry picked from commit cc59f347ee6ca5d48ba2790a8f5d843b76c470a7) Signed-off-by: Stefan Metzmacher <me...@samba.org> commit d57a0ff11adec9d358c6e7586f08903425e40216 Author: Stefan Metzmacher <me...@samba.org> Date: Tue Oct 26 22:41:46 2010 +0200 lib/util: s/allocate_anonymous_shared/anonymous_shared_allocate/ metze (cherry picked from commit 34ea9096366fe475891a0aee7b3bbc74bfe07032) Signed-off-by: Stefan Metzmacher <me...@samba.org> commit 54efccf2ee028e1a111895124b507e853408e8f4 Author: Stefan Metzmacher <me...@samba.org> Date: Wed Jan 19 17:55:13 2011 +0100 lib/util: fix rounding to page size in allocate_anonymous_shared() metze (cherry picked from commit 9e00d2a9a47d03b41e88407eb89395b870a104a5) ----------------------------------------------------------------------- Summary of changes: lib/util/tests/anonymous_shared.c | 70 +++++++++++++++++++++++++++++++++++ lib/util/util.c | 47 ++++++++++++++++++++++- lib/util/util.h | 3 +- source3/smbd/signing.c | 2 +- source4/torture/local/local.c | 1 + source4/torture/local/wscript_build | 17 ++++++++- 6 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 lib/util/tests/anonymous_shared.c Changeset truncated at 500 lines: diff --git a/lib/util/tests/anonymous_shared.c b/lib/util/tests/anonymous_shared.c new file mode 100644 index 0000000..512a53f --- /dev/null +++ b/lib/util/tests/anonymous_shared.c @@ -0,0 +1,70 @@ +/* + Unix SMB/CIFS implementation. + + anonymous_shared testing + + Copyright (C) Stefan Metzmacher 2011 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "torture/torture.h" +#include "torture/local/proto.h" + +static bool test_anonymous_shared_simple(struct torture_context *tctx) +{ + void *ptr; + size_t len; + + torture_comment(tctx, "anonymous_shared_free(NULL)\n"); + anonymous_shared_free(NULL); + + len = 500; + torture_comment(tctx, "anonymous_shared_allocate(%llu)\n", + (unsigned long long)len); + ptr = anonymous_shared_allocate(len); + torture_assert(tctx, ptr, "valid pointer"); + memset(ptr, 0xfe, len); + torture_comment(tctx, "anonymous_shared_free(ptr)\n"); + anonymous_shared_free(ptr); + + len = 50000; + torture_comment(tctx, "anonymous_shared_allocate(%llu)\n", + (unsigned long long)len); + ptr = anonymous_shared_allocate(len); + torture_assert(tctx, ptr, "valid pointer"); + memset(ptr, 0xfe, len); + torture_comment(tctx, "anonymous_shared_free(ptr)\n"); + anonymous_shared_free(ptr); + + memset(&len, 0xFF, sizeof(len)); + torture_comment(tctx, "anonymous_shared_allocate(%llu)\n", + (unsigned long long)len); + ptr = anonymous_shared_allocate(len); + torture_assert(tctx, ptr == NULL, "null pointer"); + + return true; +} + +/* local.anonymous_shared test suite creation */ +struct torture_suite *torture_local_util_anonymous_shared(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "anonymous_shared"); + + torture_suite_add_simple_test(suite, "simple", + test_anonymous_shared_simple); + + return suite; +} diff --git a/lib/util/util.c b/lib/util/util.c index 42beed4..35ad49b 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -936,14 +936,36 @@ bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx, return next_token_internal_talloc(ctx, ptr, pp_buff, sep, false); } +struct anonymous_shared_header { + union { + size_t length; + uint8_t pad[16]; + } u; +}; + /* Map a shared memory buffer of at least nelem counters. */ -void *allocate_anonymous_shared(size_t bufsz) +void *anonymous_shared_allocate(size_t orig_bufsz) { + void *ptr; void *buf; size_t pagesz = getpagesize(); + size_t pagecnt; + size_t bufsz = orig_bufsz; + struct anonymous_shared_header *hdr; + + bufsz += sizeof(*hdr); + /* round up to full pages */ + pagecnt = bufsz / pagesz; if (bufsz % pagesz) { - bufsz = (bufsz + pagesz) % pagesz; /* round up to pagesz */ + pagecnt += 1; + } + bufsz = pagesz * pagecnt; + + if (orig_bufsz >= bufsz) { + /* integer wrap */ + errno = ENOMEM; + return NULL; } #ifdef MAP_ANON @@ -959,8 +981,27 @@ void *allocate_anonymous_shared(size_t bufsz) return NULL; } - return buf; + hdr = (struct anonymous_shared_header *)buf; + hdr->u.length = bufsz; + + ptr = (void *)(&hdr[1]); + + return ptr; +} + +void anonymous_shared_free(void *ptr) +{ + struct anonymous_shared_header *hdr; + + if (ptr == NULL) { + return; + } + + hdr = (struct anonymous_shared_header *)ptr; + + hdr--; + munmap(hdr, hdr->u.length); } #ifdef DEVELOPER diff --git a/lib/util/util.h b/lib/util/util.h index 0073aa9..c730010 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -857,7 +857,8 @@ bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid, /** * Allocate anonymous shared memory of the given size */ -void *allocate_anonymous_shared(size_t bufsz); +void *anonymous_shared_allocate(size_t bufsz); +void anonymous_shared_free(void *ptr); /* run a command as a child process, with a timeout. diff --git a/source3/smbd/signing.c b/source3/smbd/signing.c index ad7fa87..65fe457 100644 --- a/source3/smbd/signing.c +++ b/source3/smbd/signing.c @@ -175,7 +175,7 @@ bool srv_init_signing(struct smbd_server_connection *conn) } s->shm_size = 4096; s->shm_pointer = - (uint8_t *)allocate_anonymous_shared(s->shm_size); + (uint8_t *)anonymous_shared_allocate(s->shm_size); if (s->shm_pointer == NULL) { talloc_free(s); return false; diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c index d044c8f..a8147da 100644 --- a/source4/torture/local/local.c +++ b/source4/torture/local/local.c @@ -40,6 +40,7 @@ torture_local_util_time, torture_local_util_data_blob, torture_local_util_asn1, + torture_local_util_anonymous_shared, torture_local_idtree, torture_local_dlinklist, torture_local_genrand, diff --git a/source4/torture/local/wscript_build b/source4/torture/local/wscript_build index dff75bf..19d74c7 100644 --- a/source4/torture/local/wscript_build +++ b/source4/torture/local/wscript_build @@ -1,6 +1,21 @@ #!/usr/bin/env python -TORTURE_LOCAL_SOURCE = '../../../lib/util/charset/tests/iconv.c ../../../lib/talloc/testsuite.c ../../lib/messaging/tests/messaging.c ../../lib/messaging/tests/irpc.c ../../librpc/tests/binding_string.c ../../../lib/util/tests/idtree.c ../../../lib/util/tests/dlinklist.c ../../lib/socket/testsuite.c ../../libcli/resolve/testsuite.c ../../../lib/util/tests/strlist.c ../../../lib/util/tests/parmlist.c ../../../lib/util/tests/str.c ../../../lib/util/tests/time.c ../../../lib/util/tests/asn1_tests.c ../../../lib/util/tests/data_blob.c ../../../lib/util/tests/file.c ../../../lib/util/tests/genrand.c ../../../lib/compression/testsuite.c ../../../lib/util/charset/tests/charset.c ../../libcli/security/tests/sddl.c ../../../lib/tdr/testsuite.c ../../../lib/tevent/testsuite.c ../../param/tests/share.c ../../param/tests/loadparm.c ../../auth/credentials/tests/simple.c local.c dbspeed.c torture.c ../ldb/ldb.c ../../dsdb/common/tests/dsdb_dn.c ../../dsdb/schema/tests/schema_syntax.c' +TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c + ../../../lib/talloc/testsuite.c ../../lib/messaging/tests/messaging.c + ../../lib/messaging/tests/irpc.c ../../librpc/tests/binding_string.c + ../../../lib/util/tests/idtree.c ../../../lib/util/tests/dlinklist.c + ../../lib/socket/testsuite.c ../../libcli/resolve/testsuite.c + ../../../lib/util/tests/strlist.c ../../../lib/util/tests/parmlist.c + ../../../lib/util/tests/str.c ../../../lib/util/tests/time.c + ../../../lib/util/tests/asn1_tests.c ../../../lib/util/tests/data_blob.c + ../../../lib/util/tests/file.c ../../../lib/util/tests/genrand.c + ../../../lib/compression/testsuite.c ../../../lib/util/charset/tests/charset.c + ../../libcli/security/tests/sddl.c ../../../lib/tdr/testsuite.c + ../../../lib/tevent/testsuite.c ../../param/tests/share.c + ../../param/tests/loadparm.c ../../auth/credentials/tests/simple.c local.c + dbspeed.c torture.c ../ldb/ldb.c ../../dsdb/common/tests/dsdb_dn.c + ../../dsdb/schema/tests/schema_syntax.c + ../../../lib/util/tests/anonymous_shared.c''' TORTURE_LOCAL_DEPS = 'RPC_NDR_ECHO TDR LIBCLI_SMB MESSAGING iconv POPT_CREDENTIALS TORTURE_AUTH TORTURE_UTIL TORTURE_NDR TORTURE_LIBCRYPTO share torture_registry PROVISION ldb samdb replace-test' -- Samba Shared Repository