Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.1 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: atom.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This file contains the common code to implement atom tables.
  7. *
  8. \***************************************************************************/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. #pragma alloc_text(INIT, UserRtlCreateAtomTable)
  12. PVOID UserAtomTableHandle;
  13. NTSTATUS
  14. UserRtlCreateAtomTable(
  15. IN ULONG NumberOfBuckets
  16. )
  17. {
  18. NTSTATUS Status;
  19. if (UserAtomTableHandle == NULL) {
  20. Status = RtlCreateAtomTable( NumberOfBuckets, &UserAtomTableHandle );
  21. } else {
  22. RIPMSG0(RIP_VERBOSE, "UserRtlCreateAtomTable: table alread exists");
  23. Status = STATUS_SUCCESS;
  24. }
  25. return Status;
  26. }
  27. ATOM UserAddAtom(
  28. LPCWSTR ccxlpAtom, BOOL bPin)
  29. {
  30. NTSTATUS Status;
  31. ATOM atom;
  32. UserAssert(IS_PTR(ccxlpAtom) || (ccxlpAtom == NULL));
  33. /*
  34. * Rtl routines protect accesses to strings with their
  35. * own try/except blocks.
  36. */
  37. atom = 0;
  38. Status = RtlAddAtomToAtomTable( UserAtomTableHandle,
  39. (PWSTR)ccxlpAtom,
  40. &atom
  41. );
  42. if (!NT_SUCCESS(Status)) {
  43. RIPNTERR0(Status, RIP_VERBOSE, "UserAddAtom: add failed");
  44. }
  45. if (atom && bPin)
  46. RtlPinAtomInAtomTable(UserAtomTableHandle,atom);
  47. return atom;
  48. }
  49. ATOM UserFindAtom(
  50. LPCWSTR ccxlpAtom)
  51. {
  52. NTSTATUS Status;
  53. ATOM atom;
  54. /*
  55. * Rtl routines protect accesses to strings with their
  56. * own try/except blocks.
  57. */
  58. atom = 0;
  59. Status = RtlLookupAtomInAtomTable( UserAtomTableHandle,
  60. (PWSTR)ccxlpAtom,
  61. &atom
  62. );
  63. if (!NT_SUCCESS(Status)) {
  64. RIPNTERR0(Status, RIP_VERBOSE, "UserFindAtom: lookup failed");
  65. }
  66. return atom;
  67. }
  68. ATOM UserDeleteAtom(
  69. ATOM atom)
  70. {
  71. NTSTATUS Status;
  72. if ((atom >= gatomFirstPinned) && (atom <= gatomLastPinned))
  73. return 0; // if pinned, just return
  74. Status = RtlDeleteAtomFromAtomTable( UserAtomTableHandle, atom );
  75. if (NT_SUCCESS(Status)) {
  76. return 0;
  77. } else {
  78. RIPNTERR0(Status, RIP_VERBOSE, "UserDeleteAtom: delete failed");
  79. return atom;
  80. }
  81. }
  82. UINT UserGetAtomName(
  83. ATOM atom,
  84. LPWSTR ccxlpch,
  85. int cchMax)
  86. {
  87. NTSTATUS Status;
  88. ULONG AtomNameLength;
  89. AtomNameLength = cchMax * sizeof(WCHAR);
  90. Status = RtlQueryAtomInAtomTable( UserAtomTableHandle,
  91. atom,
  92. NULL,
  93. NULL,
  94. ccxlpch,
  95. &AtomNameLength
  96. );
  97. if (!NT_SUCCESS(Status)) {
  98. RIPNTERR0(Status, RIP_VERBOSE, "UserGetAtomName: query failed");
  99. return 0;
  100. } else {
  101. return AtomNameLength / sizeof(WCHAR);
  102. }
  103. }