ACTION_SET_FILE_SIZE: also return the right size if it doesn't need to change.
[AROS.git] / rom / exec / addresource.c
blobb9d38b25aecc8f78ab0dba47c7033963f42407c1
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Add a resource to the public list of resources.
6 Lang: english
7 */
9 #include <aros/kernel.h>
10 #include <exec/execbase.h>
11 #include <exec/rawfmt.h>
12 #include <proto/exec.h>
13 #include <proto/kernel.h>
15 #include <string.h>
17 #include "exec_debug.h"
18 #include "exec_intern.h"
20 /* Kludge for old kernels */
21 #ifndef KrnStatMemory
22 #define KrnStatMemory(...)
23 #endif
25 /*****************************************************************************
27 NAME */
29 AROS_LH1(void, AddResource,
31 /* SYNOPSIS */
32 AROS_LHA(APTR, resource, A1),
34 /* LOCATION */
35 struct ExecBase *, SysBase, 81, Exec)
37 /* FUNCTION
38 Adds a given resource to the system's resource list.
40 INPUTS
41 resource - Pointer to a ready for use resource.
43 RESULT
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 RemResource(), OpenResource()
54 INTERNALS
56 ******************************************************************************/
58 AROS_LIBFUNC_INIT
59 ASSERT_VALID_PTR(resource);
61 /* Just in case the user forgot them */
62 ((struct Node *)resource)->ln_Type=NT_RESOURCE;
64 /* Arbitrate for the resource list */
65 Forbid();
67 /* And add the resource */
68 Enqueue(&SysBase->ResourceList,(struct Node *)resource);
70 /* All done. */
71 Permit();
74 * A tricky part.
75 * kernel.resource is the first one to get initialized. After that
76 * some more things can wake up (hostlib.resource for example).
77 * They might want to use AllocMem() and even AllocPooled().
78 * Here we switch off boot mode of the memory manager. Currently we
79 * only set up page size for pool manager. When memory protection
80 * is implemented, more things will be done here.
81 * This allows to use exec pools even in kernel.resource itself.
82 * To do this its startup code needs to be changed to call AddResource()
83 * itself. Right after this exec's pool manager will be up and running.
85 if (!strcmp(((struct Node *)resource)->ln_Name, "kernel.resource"))
87 KernelBase = resource;
88 DINIT("Post-kernel init");
90 /* If there's no MMU support, PageSize will stay zero */
91 KrnStatMemory(0, KMS_PageSize, &PrivExecBase(SysBase)->PageSize, TAG_DONE);
92 DINIT("Memory page size: %lu", PrivExecBase(SysBase)->PageSize);
95 * On MMU-less hardware kernel.resource will report zero page size.
96 * In this case we use MEMCHUNK_TOTAL as allocation granularity.
97 * This is because our Allocate() relies on the fact that all chunks
98 * are at least MemChunk-aligned, otherwise we end up in
99 * "Corrupt memory list" alert.
101 if (!PrivExecBase(SysBase)->PageSize)
102 PrivExecBase(SysBase)->PageSize = MEMCHUNK_TOTAL;
104 /* We print the notice here because kprintf() works only after KernelBase is set up */
105 if (PrivExecBase(SysBase)->IntFlags & EXECF_MungWall)
106 RawDoFmt("[exec] Mungwall enabled\n", NULL, (VOID_FUNC)RAWFMTFUNC_SERIAL, NULL);
109 AROS_LIBFUNC_EXIT
110 } /* AddResource */